Skip to content

Commit

Permalink
Renamed "local_url" -> "host_url"
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Jan 21, 2024
1 parent f1ebae9 commit 82e3288
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/pytest_celery/api/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CeleryTestBackend(CeleryTestNode):
def default_config(cls) -> dict:
return {
"url": DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"],
"local_url": DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"],
"host_url": DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"],
}

def restart(self, reload_container: bool = True, force: bool = False) -> None:
Expand All @@ -26,7 +26,7 @@ def restart(self, reload_container: bool = True, force: bool = False) -> None:
super().restart(reload_container, force)
if self.app:
self.app.conf.update(
result_backend=self.config()["local_url"],
result_backend=self.config()["host_url"],
)


Expand All @@ -42,5 +42,5 @@ class CeleryBackendCluster(CeleryTestCluster):
def default_config(cls) -> dict:
return {
"urls": [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]],
"local_urls": [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]],
"host_urls": [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]],
}
2 changes: 1 addition & 1 deletion src/pytest_celery/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def config(self, *args: tuple, **kwargs: dict) -> dict:
config = [node.container.celeryconfig for node in self]
return {
"urls": [c["url"] for c in config],
"local_urls": [c["local_url"] for c in config],
"host_urls": [c["host_url"] for c in config],
}

def teardown(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_celery/api/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CeleryTestBroker(CeleryTestNode):
def default_config(cls) -> dict:
return {
"url": DEFAULT_WORKER_ENV["CELERY_BROKER_URL"],
"local_url": DEFAULT_WORKER_ENV["CELERY_BROKER_URL"],
"host_url": DEFAULT_WORKER_ENV["CELERY_BROKER_URL"],
}

def restart(self, reload_container: bool = True, force: bool = False) -> None:
Expand All @@ -26,7 +26,7 @@ def restart(self, reload_container: bool = True, force: bool = False) -> None:
super().restart(reload_container, force)
if self.app:
self.app.conf.update(
broker_url=self.config()["local_url"],
broker_url=self.config()["host_url"],
)


Expand All @@ -42,5 +42,5 @@ class CeleryBrokerCluster(CeleryTestCluster):
def default_config(cls) -> dict:
return {
"urls": [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]],
"local_urls": [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]],
"host_urls": [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]],
}
4 changes: 2 additions & 2 deletions src/pytest_celery/api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def config(cls, celery_worker_cluster_config: dict) -> dict:
celery_backend_cluster_config: dict = celery_worker_cluster_config.get("celery_backend_cluster_config", {})
config = {}
if celery_broker_cluster_config:
config["broker_url"] = ";".join(celery_broker_cluster_config["local_urls"])
config["broker_url"] = ";".join(celery_broker_cluster_config["host_urls"])
if celery_backend_cluster_config:
config["result_backend"] = ";".join(celery_backend_cluster_config["local_urls"])
config["result_backend"] = ";".join(celery_backend_cluster_config["host_urls"])
return config

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_celery/vendors/memcached/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class MemcachedContainer(CeleryTestContainer):
@property
def client(self) -> memcache.Client:
conf = self.celeryconfig
servers = [f"{conf['local_url'][:-1].split('://')[-1]}"]
servers = [f"{conf['host_url'][:-1].split('://')[-1]}"]

Check warning on line 16 in src/pytest_celery/vendors/memcached/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/memcached/container.py#L16

Added line #L16 was not covered by tests
client = memcache.Client(servers)
return client

@property
def celeryconfig(self) -> dict:
return {
"url": self.url,
"local_url": self.local_url,
"host_url": self.host_url,
"hostname": self.hostname,
"port": self.port,
}
Expand All @@ -31,7 +31,7 @@ def url(self) -> str:
return f"{self.prefix()}{self.hostname}/"

@property
def local_url(self) -> str:
def host_url(self) -> str:
return f"{self.prefix()}localhost:{self.port}/"

@property
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_celery/vendors/rabbitmq/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RabbitMQContainer(CeleryTestContainer):
@property
def client(self) -> Connection:
client = Connection(
self.celeryconfig["local_url"],
self.celeryconfig["host_url"],
port=self.celeryconfig["port"],
)
return client
Expand All @@ -22,7 +22,7 @@ def client(self) -> Connection:
def celeryconfig(self) -> dict:
return {
"url": self.url,
"local_url": self.local_url,
"host_url": self.host_url,
"hostname": self.hostname,
"port": self.port,
"vhost": self.vhost,
Expand All @@ -33,7 +33,7 @@ def url(self) -> str:
return f"{self.prefix()}{self.hostname}/{self.vhost}"

@property
def local_url(self) -> str:
def host_url(self) -> str:
return f"{self.prefix()}localhost:{self.port}/{self.vhost}"

@property
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_celery/vendors/redis/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RedisContainer(CeleryTestContainer):
@property
def client(self) -> Redis | None:
client = Redis.from_url(
self.celeryconfig["local_url"],
self.celeryconfig["host_url"],
decode_responses=True,
)
return client
Expand All @@ -22,7 +22,7 @@ def client(self) -> Redis | None:
def celeryconfig(self) -> dict:
return {
"url": self.url,
"local_url": self.local_url,
"host_url": self.host_url,
"hostname": self.hostname,
"port": self.port,
"vhost": self.vhost,
Expand All @@ -37,7 +37,7 @@ def url(self) -> str:
return f"{self.prefix()}{self.hostname}/{self.vhost}"

@property
def local_url(self) -> str:
def host_url(self) -> str:
return f"{self.prefix()}localhost:{self.port}/{self.vhost}"

@property
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/api/custom_setup/test_custom_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ def test_ready(self, celery_setup: CeleryTestSetup):

def test_worker_is_connected_to_backend(self, celery_setup: CeleryTestSetup):
backend_urls = [
backend.container.celeryconfig["local_url"].replace("cache+", "")
for backend in celery_setup.backend_cluster
backend.container.celeryconfig["host_url"].replace("cache+", "") for backend in celery_setup.backend_cluster
]
worker: CeleryTestWorker
for worker in celery_setup.worker_cluster:
app: Celery = worker.app
assert app.backend.as_uri() in backend_urls

def test_worker_is_connected_to_broker(self, celery_setup: CeleryTestSetup):
broker_urls = [broker.container.celeryconfig["local_url"] for broker in celery_setup.broker_cluster]
broker_urls = [broker.container.celeryconfig["host_url"] for broker in celery_setup.broker_cluster]
worker: CeleryTestWorker
for worker in celery_setup.worker_cluster:
app: Celery = worker.app
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def test_app(self, cluster: CeleryBackendCluster):
assert backend.app is None

def test_config(self, cluster: CeleryBackendCluster):
expected_keys = {"urls", "local_urls"}
expected_keys = {"urls", "host_urls"}
assert set(cluster.config().keys()) == expected_keys
2 changes: 1 addition & 1 deletion tests/integration/api/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def test_app(self, cluster: CeleryBrokerCluster):
assert broker.app is None

def test_config(self, cluster: CeleryBrokerCluster):
expected_keys = {"urls", "local_urls"}
expected_keys = {"urls", "host_urls"}
assert set(cluster.config().keys()) == expected_keys
5 changes: 2 additions & 3 deletions tests/integration/api/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ def test_ready(self, celery_setup: CeleryTestSetup, confirmation: dict):

def test_worker_is_connected_to_backend(self, celery_setup: CeleryTestSetup):
backend_urls = [
backend.container.celeryconfig["local_url"].replace("cache+", "")
for backend in celery_setup.backend_cluster
backend.container.celeryconfig["host_url"].replace("cache+", "") for backend in celery_setup.backend_cluster
]
worker: CeleryTestWorker
for worker in celery_setup.worker_cluster:
app: Celery = worker.app
assert app.backend.as_uri() in backend_urls

def test_worker_is_connected_to_broker(self, celery_setup: CeleryTestSetup):
broker_urls = [broker.container.celeryconfig["local_url"] for broker in celery_setup.broker_cluster]
broker_urls = [broker.container.celeryconfig["host_url"] for broker in celery_setup.broker_cluster]
worker: CeleryTestWorker
for worker in celery_setup.worker_cluster:
app: Celery = worker.app
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/vendors/test_memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ def test_client(self, container: MemcachedContainer):
assert container.client.delete("ready")

def test_celeryconfig(self, container: MemcachedContainer):
expected_keys = {"url", "local_url", "hostname", "port"}
expected_keys = {"url", "host_url", "hostname", "port"}
config = container.celeryconfig
assert set(config.keys()) == expected_keys
assert container.prefix() in config["url"]
assert container.prefix() in config["local_url"]
assert container.prefix() in config["host_url"]


@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_MEMCACHED_BACKEND)])
class test_memcached_test_backend:
def test_config(self, backend: MemcachedTestBackend):
expected_keys = {"url", "local_url", "hostname", "port"}
expected_keys = {"url", "host_url", "hostname", "port"}
assert set(backend.config().keys()) == expected_keys
assert backend.container.prefix() in backend.config()["url"]
assert backend.container.prefix() in backend.config()["local_url"]
assert backend.container.prefix() in backend.config()["host_url"]
8 changes: 4 additions & 4 deletions tests/integration/vendors/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ def test_client(self, container: RabbitMQContainer):
c.release()

def test_celeryconfig(self, container: RabbitMQContainer):
expected_keys = {"url", "local_url", "hostname", "port", "vhost"}
expected_keys = {"url", "host_url", "hostname", "port", "vhost"}
config = container.celeryconfig
assert set(config.keys()) == expected_keys
assert container.prefix() in config["url"]
assert container.prefix() in config["local_url"]
assert container.prefix() in config["host_url"]


@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_RABBITMQ_BROKER)])
class test_rabbitmq_test_broker:
def test_config(self, broker: RabbitMQTestBroker):
expected_keys = {"url", "local_url", "hostname", "port", "vhost"}
expected_keys = {"url", "host_url", "hostname", "port", "vhost"}
assert set(broker.config().keys()) == expected_keys
assert broker.container.prefix() in broker.config()["url"]
assert broker.container.prefix() in broker.config()["local_url"]
assert broker.container.prefix() in broker.config()["host_url"]
12 changes: 6 additions & 6 deletions tests/integration/vendors/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ def test_client(self, container: RedisContainer):
assert container.client.delete("ready")

def test_celeryconfig(self, container: RedisContainer):
expected_keys = {"url", "local_url", "hostname", "port", "vhost"}
expected_keys = {"url", "host_url", "hostname", "port", "vhost"}
config = container.celeryconfig
assert set(config.keys()) == expected_keys
assert container.prefix() in config["url"]
assert container.prefix() in config["local_url"]
assert container.prefix() in config["host_url"]


@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_REDIS_BACKEND)])
class test_redis_test_backend:
def test_config(self, backend: RedisTestBackend):
expected_keys = {"url", "local_url", "hostname", "port", "vhost"}
expected_keys = {"url", "host_url", "hostname", "port", "vhost"}
assert set(backend.config().keys()) == expected_keys
assert backend.container.prefix() in backend.config()["url"]
assert backend.container.prefix() in backend.config()["local_url"]
assert backend.container.prefix() in backend.config()["host_url"]


@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_REDIS_BROKER)])
class test_redis_test_broker:
def test_config(self, broker: RedisTestBroker):
expected_keys = {"url", "local_url", "hostname", "port", "vhost"}
expected_keys = {"url", "host_url", "hostname", "port", "vhost"}
assert set(broker.config().keys()) == expected_keys
assert broker.container.prefix() in broker.config()["url"]
assert broker.container.prefix() in broker.config()["local_url"]
assert broker.container.prefix() in broker.config()["host_url"]
4 changes: 2 additions & 2 deletions tests/unit/api/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class test_celey_test_backend:
def test_default_config_format(self, backend: CeleryTestBackend):
assert backend.default_config()["url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]
assert backend.default_config()["local_url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]
assert backend.default_config()["host_url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]

def test_restart_no_app(self, backend: CeleryTestBackend):
assert backend.app is None
Expand All @@ -32,7 +32,7 @@ def test_restart_with_app(self, backend: CeleryTestBackend, celery_setup_app: Ce
class test_celery_backend_cluster:
def test_default_config_format(self, cluster: CeleryBackendCluster):
assert cluster.default_config()["urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]]
assert cluster.default_config()["local_urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]]
assert cluster.default_config()["host_urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]]

class test_disabling_cluster:
@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/api/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class test_celey_test_broker:
def test_default_config_format(self, broker: CeleryTestBroker):
assert broker.default_config()["url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]
assert broker.default_config()["local_url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]
assert broker.default_config()["host_url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]

def test_restart_no_app(self, broker: CeleryTestBroker):
assert broker.app is None
Expand All @@ -32,7 +32,7 @@ def test_restart_with_app(self, broker: CeleryTestBroker, celery_setup_app: Cele
class test_celery_broker_cluster:
def test_default_config_format(self, cluster: CeleryBrokerCluster):
assert cluster.default_config()["urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]]
assert cluster.default_config()["local_urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]]
assert cluster.default_config()["host_urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]]

class test_disabling_cluster:
@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mocked_container(spec: type) -> Mock:
mocked_container.id = "mocked_test_container_id"
mocked_container.celeryconfig = {
"url": "mocked_url",
"local_url": "mocked_local_url",
"host_url": "mocked_host_url",
}
return mocked_container

Expand Down

0 comments on commit 82e3288

Please sign in to comment.