Skip to content

Commit

Permalink
Refactored Unit & Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Oct 23, 2023
1 parent 1a76769 commit 423f32e
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 129 deletions.
9 changes: 4 additions & 5 deletions tests/integration/api/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

@pytest.mark.parametrize("node", [lazy_fixture(CELERY_BACKEND)])
class test_celey_test_backend:
def test_ready(self, node: CeleryTestBackend):
assert node.ready()

def test_app(self, node: CeleryTestBackend):
assert node.app is None


@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BACKEND_CLUSTER)])
class test_celery_backend_cluster:
def test_ready(self, cluster: CeleryBackendCluster):
assert cluster.ready()
def test_app(self, cluster: CeleryBackendCluster):
node: CeleryTestBackend
for node in cluster:
assert node.app is None
9 changes: 4 additions & 5 deletions tests/integration/api/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

@pytest.mark.parametrize("node", [lazy_fixture(CELERY_BROKER)])
class test_celery_test_broker:
def test_ready(self, node: CeleryTestBroker):
assert node.ready()

def test_app(self, node: CeleryTestBroker):
assert node.app is None


@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BROKER_CLUSTER)])
class test_celery_broker_cluster:
def test_ready(self, cluster: CeleryBrokerCluster):
assert cluster.ready()
def test_app(self, cluster: CeleryBrokerCluster):
node: CeleryTestBroker
for node in cluster:
assert node.app is None
6 changes: 0 additions & 6 deletions tests/integration/api/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

@pytest.mark.parametrize("node", [lazy_fixture(CELERY_WORKER)])
class test_celey_test_worker:
def test_ready(self, node: CeleryTestWorker):
assert node.ready()

def test_app(self, node: CeleryTestWorker, celery_setup_app: Celery):
assert node.app is celery_setup_app

Expand All @@ -32,9 +29,6 @@ def test_assert_log_exists(self, node: CeleryTestWorker):

@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_WORKER_CLUSTER)])
class test_celery_worker_cluster:
def test_ready(self, cluster: CeleryWorkerCluster):
assert cluster.ready()

def test_app(self, cluster: CeleryWorkerCluster, celery_setup_app: Celery):
node: CeleryTestWorker
for node in cluster:
Expand Down
13 changes: 7 additions & 6 deletions tests/integration/vendors/test_memcached.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest
from pytest_lazyfixture import lazy_fixture

from pytest_celery import CELERY_MEMCACHED_BACKEND
# from pytest_celery import CELERY_MEMCACHED_BACKEND
from pytest_celery import MemcachedContainer
from pytest_celery import MemcachedTestBackend

# from pytest_celery import MemcachedTestBackend
from tests.defaults import ALL_MEMCACHED_FIXTURES


Expand All @@ -17,7 +18,7 @@ def test_client(self, container: MemcachedContainer):
assert container.client.delete("ready")


@pytest.mark.parametrize("node", [lazy_fixture(CELERY_MEMCACHED_BACKEND)])
class test_memcached_test_backend:
def test_ready(self, node: MemcachedTestBackend):
assert node.ready()
# @pytest.mark.parametrize("node", [lazy_fixture(CELERY_MEMCACHED_BACKEND)])
# class test_memcached_test_backend:
# def test_placeholder(self, node: MemcachedTestBackend):
# node = node
13 changes: 7 additions & 6 deletions tests/integration/vendors/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from kombu import Connection
from pytest_lazyfixture import lazy_fixture

from pytest_celery import CELERY_RABBITMQ_BROKER
# from pytest_celery import CELERY_RABBITMQ_BROKER
from pytest_celery import RabbitMQContainer
from pytest_celery import RabbitMQTestBroker

# from pytest_celery import RabbitMQTestBroker
from tests.defaults import ALL_RABBITMQ_FIXTURES


Expand All @@ -19,7 +20,7 @@ def test_client(self, container: RabbitMQContainer):
c.release()


@pytest.mark.parametrize("node", [lazy_fixture(CELERY_RABBITMQ_BROKER)])
class test_rabbitmq_test_broker:
def test_ready(self, node: RabbitMQTestBroker):
assert node.ready()
# @pytest.mark.parametrize("node", [lazy_fixture(CELERY_RABBITMQ_BROKER)])
# class test_rabbitmq_test_broker:
# def test_placeholder(self, node: RabbitMQTestBroker):
# node = node
25 changes: 13 additions & 12 deletions tests/integration/vendors/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
from pytest_lazyfixture import lazy_fixture

from pytest_celery import CELERY_REDIS_BACKEND
from pytest_celery import CELERY_REDIS_BROKER
# from pytest_celery import CELERY_REDIS_BACKEND
# from pytest_celery import CELERY_REDIS_BROKER
from pytest_celery import RedisContainer
from pytest_celery import RedisTestBackend
from pytest_celery import RedisTestBroker

# from pytest_celery import RedisTestBackend
# from pytest_celery import RedisTestBroker
from tests.defaults import ALL_REDIS_FIXTURES


Expand All @@ -19,13 +20,13 @@ def test_client(self, container: RedisContainer):
assert container.client.delete("ready")


@pytest.mark.parametrize("node", [lazy_fixture(CELERY_REDIS_BACKEND)])
class test_redis_test_backend:
def test_ready(self, node: RedisTestBackend):
assert node.ready()
# @pytest.mark.parametrize("node", [lazy_fixture(CELERY_REDIS_BACKEND)])
# class test_redis_test_backend:
# def test_placeholder(self, node: RedisTestBackend):
# node = node


@pytest.mark.parametrize("node", [lazy_fixture(CELERY_REDIS_BROKER)])
class test_redis_test_broker:
def test_ready(self, node: RedisTestBroker):
assert node.ready()
# @pytest.mark.parametrize("node", [lazy_fixture(CELERY_REDIS_BROKER)])
# class test_redis_test_broker:
# def test_placeholder(self, node: RedisTestBroker):
# node = node
27 changes: 7 additions & 20 deletions tests/integration/vendors/test_worker.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import pytest
from celery import Celery
from pytest_lazyfixture import lazy_fixture

from pytest_celery import CELERY_SETUP_WORKER
from pytest_celery import CeleryTestWorker
# from pytest_celery import CELERY_SETUP_WORKER
# from pytest_celery import CeleryTestWorker
from pytest_celery import CeleryWorkerContainer
from tests.defaults import ALL_WORKERS_FIXTURES
from tests.integration.conftest import IntegrationWorkerContainer


@pytest.mark.parametrize("container", lazy_fixture(ALL_WORKERS_FIXTURES))
class test_celery_worker_container:
def test_client(self, container: CeleryWorkerContainer):
assert container.client
assert container.client == container, "Check tests/conftest.py/WorkerContainer.client"
assert container.client == container


@pytest.mark.parametrize("node", [lazy_fixture(CELERY_SETUP_WORKER)])
class test_base_test_worker:
def test_ready(self, node: CeleryTestWorker):
assert node.ready()

def test_app(self, node: CeleryTestWorker, celery_setup_app: Celery):
assert node.app is celery_setup_app

def test_wait_for_log(self, node: CeleryTestWorker):
log = f"{IntegrationWorkerContainer.worker_name()}@{node.hostname()} v{node.version}"
node.wait_for_log(log, "test_base_test_worker.test_wait_for_log")

def test_assert_log_exists(self, node: CeleryTestWorker):
log = f"{IntegrationWorkerContainer.worker_name()}@{node.hostname()} v{node.version}"
node.assert_log_exists(log, "test_base_test_worker.test_assert_log_exists")
# @pytest.mark.parametrize("node", [lazy_fixture(CELERY_SETUP_WORKER)])
# class test_base_test_worker:
# def test_placeholder(self, node: CeleryTestWorker):
# node = node
16 changes: 2 additions & 14 deletions tests/unit/api/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,20 @@


class test_celey_test_backend:
def test_ready(self, unit_tests_container: CeleryTestContainer):
node = CeleryTestBackend(unit_tests_container)
assert node.ready()

def test_default_config_format(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node = CeleryTestBackend(unit_tests_container)
expected_format = {"url", "local_url"}
assert set(node.default_config().keys()) == expected_format


class test_celery_backend_cluster:
def test_ready(
self,
unit_tests_container: CeleryTestContainer,
local_test_container: CeleryTestContainer,
):
node1 = CeleryTestBackend(unit_tests_container)
node2 = CeleryTestBackend(local_test_container)
cluster = CeleryBackendCluster(node1, node2)
assert cluster.ready()

def test_default_config_format(
self,
unit_tests_container: CeleryTestContainer,
local_test_container: CeleryTestContainer,
):
# TODO: Use mock instead of real container
node1 = CeleryTestBackend(unit_tests_container)
node2 = CeleryTestBackend(local_test_container)
cluster = CeleryBackendCluster(node1, node2)
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/api/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,46 @@

class test_celery_test_node:
def test_ready(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node = CeleryTestNode(unit_tests_container)
assert node.ready()

def test_app(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
expected_app = Celery()
node = CeleryTestNode(unit_tests_container, expected_app)
assert node.app is expected_app

def test_default_config_format(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node = CeleryTestNode(unit_tests_container)
assert node.default_config() == dict()

def test_eq_opertor(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
node2 = CeleryTestNode(unit_tests_container)
assert node1 == node2
assert node1 is not node2

def test_wait_for_log(self, unit_tests_container: CeleryTestContainer, celery_setup_app: Celery):
# TODO: Use mock instead of real container
node = CeleryTestNode(unit_tests_container, celery_setup_app)
node.wait_for_log("", "test_celey_test_worker.test_wait_for_log")

def test_assert_log_exists(self, unit_tests_container: CeleryTestContainer, celery_setup_app: Celery):
# TODO: Use mock instead of real container
node = CeleryTestNode(unit_tests_container, celery_setup_app)
node.assert_log_exists("", "test_celey_test_worker.test_assert_log_exists")


class test_celery_test_cluster:
def test_ready(
self,
unit_tests_container: CeleryTestContainer,
local_test_container: CeleryTestContainer,
):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
node2 = CeleryTestNode(local_test_container)
cluster = CeleryTestCluster(node1, node2)
Expand All @@ -42,29 +57,34 @@ def test_default_config_format(
unit_tests_container: CeleryTestContainer,
local_test_container: CeleryTestContainer,
):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
node2 = CeleryTestNode(local_test_container)
cluster = CeleryTestCluster(node1, node2)
assert cluster.default_config() == dict()

def test_set_nodes(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
node2 = CeleryTestNode(unit_tests_container)
cluster = CeleryTestCluster(node1)
cluster._set_nodes(node2)
assert cluster[0] == node2

def test_iter(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
cluster = CeleryTestCluster(node1)
assert list(cluster) == [node1]

def test_len(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
cluster = CeleryTestCluster(node1)
assert len(cluster) == 1

def test_getitem(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node1 = CeleryTestNode(unit_tests_container)
cluster = CeleryTestCluster(node1)
assert cluster[0] == node1
16 changes: 2 additions & 14 deletions tests/unit/api/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,20 @@


class test_celery_test_broker:
def test_ready(self, unit_tests_container: CeleryTestContainer):
node = CeleryTestBroker(unit_tests_container)
assert node.ready()

def test_default_config_format(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
node = CeleryTestBroker(unit_tests_container)
expected_format = {"url", "local_url"}
assert set(node.default_config().keys()) == expected_format


class test_celery_broker_cluster:
def test_ready(
self,
unit_tests_container: CeleryTestContainer,
local_test_container: CeleryTestContainer,
):
node1 = CeleryTestBroker(unit_tests_container)
node2 = CeleryTestBroker(local_test_container)
cluster = CeleryBrokerCluster(node1, node2)
assert cluster.ready()

def test_default_config_format(
self,
unit_tests_container: CeleryTestContainer,
local_test_container: CeleryTestContainer,
):
# TODO: Use mock instead of real container
node1 = CeleryTestBroker(unit_tests_container)
node2 = CeleryTestBroker(local_test_container)
cluster = CeleryBrokerCluster(node1, node2)
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/api/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

class test_celery_test_container:
def test_client(self, unit_tests_container: CeleryTestContainer):
# TODO: Use mock instead of real container
# TODO: Check raises NotImplementedError and remove the client overload from the unit tests container
assert unit_tests_container.client == unit_tests_container
Loading

0 comments on commit 423f32e

Please sign in to comment.