Skip to content

Commit

Permalink
Added container prefix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Oct 25, 2023
1 parent 322aafd commit 18c07c0
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 23 deletions.
8 changes: 6 additions & 2 deletions src/pytest_celery/vendors/memcached/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}/"

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L34 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L38 was not covered by tests

@property
def hostname(self) -> str:
Expand All @@ -60,3 +60,7 @@ def image(cls) -> str:
@classmethod
def ports(cls) -> dict:
return MEMCACHED_PORTS

@classmethod

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L64 was not covered by tests
def prefix(cls) -> str:
return MEMCACHED_PREFIX
8 changes: 6 additions & 2 deletions src/pytest_celery/vendors/rabbitmq/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Check warning on line 33 in src/pytest_celery/vendors/rabbitmq/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/rabbitmq/container.py#L33

Added line #L33 was not covered by tests

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

Check warning on line 37 in src/pytest_celery/vendors/rabbitmq/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/rabbitmq/container.py#L37

Added line #L37 was not covered by tests

@property
def hostname(self) -> str:
Expand Down Expand Up @@ -64,6 +64,10 @@ def image(cls) -> str:
def ports(cls) -> dict:
return RABBITMQ_PORTS

@classmethod

Check warning on line 67 in src/pytest_celery/vendors/rabbitmq/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/rabbitmq/container.py#L67

Added line #L67 was not covered by tests
def prefix(cls) -> str:
return RABBITMQ_PREFIX

@property
def ready_prompt(self) -> Optional[str]:
return "Server startup complete"
8 changes: 6 additions & 2 deletions src/pytest_celery/vendors/redis/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Check warning on line 33 in src/pytest_celery/vendors/redis/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/redis/container.py#L33

Added line #L33 was not covered by tests

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

Check warning on line 37 in src/pytest_celery/vendors/redis/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/redis/container.py#L37

Added line #L37 was not covered by tests

@property
def hostname(self) -> str:
Expand Down Expand Up @@ -64,6 +64,10 @@ def image(cls) -> str:
def ports(cls) -> dict:
return REDIS_PORTS

@classmethod

Check warning on line 67 in src/pytest_celery/vendors/redis/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/redis/container.py#L67

Added line #L67 was not covered by tests
def prefix(cls) -> str:
return REDIS_PREFIX

@property
def ready_prompt(self) -> Optional[str]:
return "Ready to accept connections"
9 changes: 4 additions & 5 deletions tests/integration/vendors/test_memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,14 +20,14 @@ 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)])
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"]
9 changes: 4 additions & 5 deletions tests/integration/vendors/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,14 +22,14 @@ 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)])
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"]
13 changes: 6 additions & 7 deletions tests/integration/vendors/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,23 +22,23 @@ 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)])
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)])
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"]
4 changes: 4 additions & 0 deletions tests/unit/vendors/test_memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/vendors/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/vendors/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 18c07c0

Please sign in to comment.