Debian Codegraph @

t/smoke/workers/dev.py

raw
1 import os
2 from typing import Any, Type
3
4 import pytest
5 from pytest_celery import CeleryWorkerContainer, defaults
6 from pytest_docker_tools import build, container, fxtr
7
8 import celery
9
10
11 class SmokeWorkerContainer(CeleryWorkerContainer):
12 """Defines the configurations for the smoke tests worker container.
13
14 This worker will install Celery from the current source code.
15 """
16
17 @property
18 def client(self) -> Any:
19 return self
20
21 @classmethod
22 def version(cls) -> str:
23 return celery.__version__
24
25 @classmethod
26 def log_level(cls) -> str:
27 return "INFO"
28
29 @classmethod
30 def worker_name(cls) -> str:
31 return "smoke_tests_worker"
32
33 @classmethod
34 def worker_queue(cls) -> str:
35 return "smoke_tests_queue"
36
37
38 # Build the image from the current source code
39 celery_dev_worker_image = build(
40 path=".",
41 dockerfile="t/smoke/workers/docker/dev",
42 tag="t/smoke/worker:dev",
43 buildargs=SmokeWorkerContainer.buildargs(),
44 )
45
46
47 # Define container settings
48 default_worker_container = container(
49 image="{celery_dev_worker_image.id}",
50 ports=fxtr("default_worker_ports"),
51 environment=fxtr("default_worker_env"),
52 network="{default_pytest_celery_network.name}",
53 volumes={
54 # Volume: Worker /app
55 "{default_worker_volume.name}": defaults.DEFAULT_WORKER_VOLUME,
56 # Mount: Celery source
57 os.path.abspath(os.getcwd()): {
58 "bind": "/celery",
59 "mode": "rw",
60 },
61 },
62 wrapper_class=SmokeWorkerContainer,
63 timeout=defaults.DEFAULT_WORKER_CONTAINER_TIMEOUT,
64 command=fxtr("default_worker_command"),
65 )
66
67
68 @pytest.fixture
69 def default_worker_container_cls() -> Type[CeleryWorkerContainer]:
70 """Replace the default pytest-celery worker container with the smoke tests worker container.
71
72 This will allow the default fixtures of pytest-celery to use the custom worker
73 configuration using the vendor class.
74 """
75 return SmokeWorkerContainer
76
77
78 @pytest.fixture(scope="session")
79 def default_worker_container_session_cls() -> Type[CeleryWorkerContainer]:
80 """Replace the default pytest-celery worker container with the smoke tests worker container.
81
82 This will allow the default fixtures of pytest-celery to use the custom worker
83 configuration using the vendor class.
84 """
85 return SmokeWorkerContainer