From 18c07c03e9891fbfa7d772c8e06cbc14ccfa3bde Mon Sep 17 00:00:00 2001 From: Tomer Nosrati Date: Thu, 26 Oct 2023 00:11:39 +0300 Subject: [PATCH] Added container prefix unit tests --- src/pytest_celery/vendors/memcached/container.py | 8 ++++++-- src/pytest_celery/vendors/rabbitmq/container.py | 8 ++++++-- src/pytest_celery/vendors/redis/container.py | 8 ++++++-- tests/integration/vendors/test_memcached.py | 9 ++++----- tests/integration/vendors/test_rabbitmq.py | 9 ++++----- tests/integration/vendors/test_redis.py | 13 ++++++------- tests/unit/vendors/test_memcached.py | 4 ++++ tests/unit/vendors/test_rabbitmq.py | 4 ++++ tests/unit/vendors/test_redis.py | 4 ++++ 9 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/pytest_celery/vendors/memcached/container.py b/src/pytest_celery/vendors/memcached/container.py index bdd46106..f10692f5 100644 --- a/src/pytest_celery/vendors/memcached/container.py +++ b/src/pytest_celery/vendors/memcached/container.py @@ -31,11 +31,11 @@ def celeryconfig(self) -> dict: @property def url(self) -> str: - return f"{MEMCACHED_PREFIX}{self.hostname}/" + return f"{self.prefix()}{self.hostname}/" @property def local_url(self) -> str: - return f"{MEMCACHED_PREFIX}localhost:{self.port}/" + return f"{self.prefix()}localhost:{self.port}/" @property def hostname(self) -> str: @@ -60,3 +60,7 @@ def image(cls) -> str: @classmethod def ports(cls) -> dict: return MEMCACHED_PORTS + + @classmethod + def prefix(cls) -> str: + return MEMCACHED_PREFIX diff --git a/src/pytest_celery/vendors/rabbitmq/container.py b/src/pytest_celery/vendors/rabbitmq/container.py index 3309b9fe..519550f6 100644 --- a/src/pytest_celery/vendors/rabbitmq/container.py +++ b/src/pytest_celery/vendors/rabbitmq/container.py @@ -30,11 +30,11 @@ def celeryconfig(self) -> dict: @property def url(self) -> str: - return f"{RABBITMQ_PREFIX}{self.hostname}/{self.vhost}" + return f"{self.prefix()}{self.hostname}/{self.vhost}" @property def local_url(self) -> str: - return f"{RABBITMQ_PREFIX}localhost:{self.port}/{self.vhost}" + return f"{self.prefix()}localhost:{self.port}/{self.vhost}" @property def hostname(self) -> str: @@ -64,6 +64,10 @@ def image(cls) -> str: def ports(cls) -> dict: return RABBITMQ_PORTS + @classmethod + def prefix(cls) -> str: + return RABBITMQ_PREFIX + @property def ready_prompt(self) -> Optional[str]: return "Server startup complete" diff --git a/src/pytest_celery/vendors/redis/container.py b/src/pytest_celery/vendors/redis/container.py index b9ede104..f43a9eb1 100644 --- a/src/pytest_celery/vendors/redis/container.py +++ b/src/pytest_celery/vendors/redis/container.py @@ -30,11 +30,11 @@ def celeryconfig(self) -> dict: @property def url(self) -> str: - return f"{REDIS_PREFIX}{self.hostname}/{self.vhost}" + return f"{self.prefix()}{self.hostname}/{self.vhost}" @property def local_url(self) -> str: - return f"{REDIS_PREFIX}localhost:{self.port}/{self.vhost}" + return f"{self.prefix()}localhost:{self.port}/{self.vhost}" @property def hostname(self) -> str: @@ -64,6 +64,10 @@ def image(cls) -> str: def ports(cls) -> dict: return REDIS_PORTS + @classmethod + def prefix(cls) -> str: + return REDIS_PREFIX + @property def ready_prompt(self) -> Optional[str]: return "Ready to accept connections" diff --git a/tests/integration/vendors/test_memcached.py b/tests/integration/vendors/test_memcached.py index 19fc8af8..0ec9ccda 100644 --- a/tests/integration/vendors/test_memcached.py +++ b/tests/integration/vendors/test_memcached.py @@ -2,7 +2,6 @@ from pytest_lazyfixture import lazy_fixture from pytest_celery import CELERY_MEMCACHED_BACKEND -from pytest_celery import MEMCACHED_PREFIX from pytest_celery import MemcachedContainer from pytest_celery import MemcachedTestBackend from tests.defaults import ALL_MEMCACHED_FIXTURES @@ -21,8 +20,8 @@ def test_celeryconfig(self, container: MemcachedContainer): expected_keys = {"url", "local_url", "hostname", "port"} config = container.celeryconfig assert set(config.keys()) == expected_keys - assert MEMCACHED_PREFIX in config["url"] - assert MEMCACHED_PREFIX in config["local_url"] + assert container.prefix() in config["url"] + assert container.prefix() in config["local_url"] @pytest.mark.parametrize("backend", [lazy_fixture(CELERY_MEMCACHED_BACKEND)]) @@ -30,5 +29,5 @@ class test_memcached_test_backend: def test_config(self, backend: MemcachedTestBackend): expected_keys = {"url", "local_url", "hostname", "port"} assert set(backend.config().keys()) == expected_keys - assert MEMCACHED_PREFIX in backend.config()["url"] - assert MEMCACHED_PREFIX in backend.config()["local_url"] + assert backend.container.prefix() in backend.config()["url"] + assert backend.container.prefix() in backend.config()["local_url"] diff --git a/tests/integration/vendors/test_rabbitmq.py b/tests/integration/vendors/test_rabbitmq.py index 9112833a..04dee23b 100644 --- a/tests/integration/vendors/test_rabbitmq.py +++ b/tests/integration/vendors/test_rabbitmq.py @@ -3,7 +3,6 @@ from pytest_lazyfixture import lazy_fixture from pytest_celery import CELERY_RABBITMQ_BROKER -from pytest_celery import RABBITMQ_PREFIX from pytest_celery import RabbitMQContainer from pytest_celery import RabbitMQTestBroker from tests.defaults import ALL_RABBITMQ_FIXTURES @@ -23,8 +22,8 @@ def test_celeryconfig(self, container: RabbitMQContainer): expected_keys = {"url", "local_url", "hostname", "port", "vhost"} config = container.celeryconfig assert set(config.keys()) == expected_keys - assert RABBITMQ_PREFIX in config["url"] - assert RABBITMQ_PREFIX in config["local_url"] + assert container.prefix() in config["url"] + assert container.prefix() in config["local_url"] @pytest.mark.parametrize("broker", [lazy_fixture(CELERY_RABBITMQ_BROKER)]) @@ -32,5 +31,5 @@ class test_rabbitmq_test_broker: def test_config(self, broker: RabbitMQTestBroker): expected_keys = {"url", "local_url", "hostname", "port", "vhost"} assert set(broker.config().keys()) == expected_keys - assert RABBITMQ_PREFIX in broker.config()["url"] - assert RABBITMQ_PREFIX in broker.config()["local_url"] + assert broker.container.prefix() in broker.config()["url"] + assert broker.container.prefix() in broker.config()["local_url"] diff --git a/tests/integration/vendors/test_redis.py b/tests/integration/vendors/test_redis.py index 8bfbb439..6066b98e 100644 --- a/tests/integration/vendors/test_redis.py +++ b/tests/integration/vendors/test_redis.py @@ -3,7 +3,6 @@ from pytest_celery import CELERY_REDIS_BACKEND from pytest_celery import CELERY_REDIS_BROKER -from pytest_celery import REDIS_PREFIX from pytest_celery import RedisContainer from pytest_celery import RedisTestBackend from pytest_celery import RedisTestBroker @@ -23,8 +22,8 @@ def test_celeryconfig(self, container: RedisContainer): expected_keys = {"url", "local_url", "hostname", "port", "vhost"} config = container.celeryconfig assert set(config.keys()) == expected_keys - assert REDIS_PREFIX in config["url"] - assert REDIS_PREFIX in config["local_url"] + assert container.prefix() in config["url"] + assert container.prefix() in config["local_url"] @pytest.mark.parametrize("backend", [lazy_fixture(CELERY_REDIS_BACKEND)]) @@ -32,8 +31,8 @@ class test_redis_test_backend: def test_config(self, backend: RedisTestBackend): expected_keys = {"url", "local_url", "hostname", "port", "vhost"} assert set(backend.config().keys()) == expected_keys - assert REDIS_PREFIX in backend.config()["url"] - assert REDIS_PREFIX in backend.config()["local_url"] + assert backend.container.prefix() in backend.config()["url"] + assert backend.container.prefix() in backend.config()["local_url"] @pytest.mark.parametrize("broker", [lazy_fixture(CELERY_REDIS_BROKER)]) @@ -41,5 +40,5 @@ class test_redis_test_broker: def test_config(self, broker: RedisTestBroker): expected_keys = {"url", "local_url", "hostname", "port", "vhost"} assert set(broker.config().keys()) == expected_keys - assert REDIS_PREFIX in broker.config()["url"] - assert REDIS_PREFIX in broker.config()["local_url"] + assert broker.container.prefix() in broker.config()["url"] + assert broker.container.prefix() in broker.config()["local_url"] diff --git a/tests/unit/vendors/test_memcached.py b/tests/unit/vendors/test_memcached.py index d012176b..e13a87be 100644 --- a/tests/unit/vendors/test_memcached.py +++ b/tests/unit/vendors/test_memcached.py @@ -5,6 +5,7 @@ from pytest_celery import MEMCACHED_ENV from pytest_celery import MEMCACHED_IMAGE from pytest_celery import MEMCACHED_PORTS +from pytest_celery import MEMCACHED_PREFIX from pytest_celery import MemcachedContainer from pytest_celery import MemcachedTestBackend @@ -22,6 +23,9 @@ def test_image(self): def test_ports(self): assert MemcachedContainer.ports() == MEMCACHED_PORTS + def test_prefix(self): + assert MemcachedContainer.prefix() == MEMCACHED_PREFIX + @pytest.mark.parametrize("backend", [lazy_fixture(CELERY_MEMCACHED_BACKEND)]) class test_memcached_backend_api: diff --git a/tests/unit/vendors/test_rabbitmq.py b/tests/unit/vendors/test_rabbitmq.py index 8a929310..b390c46d 100644 --- a/tests/unit/vendors/test_rabbitmq.py +++ b/tests/unit/vendors/test_rabbitmq.py @@ -5,6 +5,7 @@ from pytest_celery import RABBITMQ_ENV from pytest_celery import RABBITMQ_IMAGE from pytest_celery import RABBITMQ_PORTS +from pytest_celery import RABBITMQ_PREFIX from pytest_celery import RabbitMQContainer from pytest_celery import RabbitMQTestBroker @@ -23,6 +24,9 @@ def test_image(self): def test_ports(self): assert RabbitMQContainer.ports() == RABBITMQ_PORTS + def test_prefix(self): + assert RabbitMQContainer.prefix() == RABBITMQ_PREFIX + @pytest.mark.parametrize("broker", [lazy_fixture(CELERY_RABBITMQ_BROKER)]) class test_rabbitmq_broker_api: diff --git a/tests/unit/vendors/test_redis.py b/tests/unit/vendors/test_redis.py index 5619a58d..7bc5a6ff 100644 --- a/tests/unit/vendors/test_redis.py +++ b/tests/unit/vendors/test_redis.py @@ -6,6 +6,7 @@ from pytest_celery import REDIS_ENV from pytest_celery import REDIS_IMAGE from pytest_celery import REDIS_PORTS +from pytest_celery import REDIS_PREFIX from pytest_celery import RedisContainer from pytest_celery import RedisTestBackend from pytest_celery import RedisTestBroker @@ -24,6 +25,9 @@ def test_image(self): def test_ports(self): assert RedisContainer.ports() == REDIS_PORTS + def test_prefix(self): + assert RedisContainer.prefix() == REDIS_PREFIX + @pytest.mark.parametrize("backend", [lazy_fixture(CELERY_REDIS_BACKEND)]) class test_redis_backend_api: