Skip to content

Commit fb092cc

Browse files
authored
Hotfix: Allow overriding node celery config with kwargs (#249)
1 parent ed67255 commit fb092cc

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/pytest_celery/api/base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,21 @@ def ready(self) -> bool:
7474

7575
def config(self, *args: tuple, **kwargs: dict) -> dict:
7676
"""Compile the configurations required for Celery from this node."""
77-
return self.container.celeryconfig
77+
config = self.container.celeryconfig
78+
79+
if not args and not kwargs:
80+
return config
81+
82+
for key, value in kwargs.items():
83+
config[key] = value
84+
85+
if key == "vhost":
86+
vhost = str(value)
87+
config["url"] = f"{config['url'][:-1].rstrip('/')}/{vhost}"
88+
config["host_url"] = f"{config['host_url'][:-1].rstrip('/')}/{vhost}"
89+
config[key] = vhost
90+
91+
return config
7892

7993
def logs(self) -> str:
8094
"""Get the logs of the underlying container."""

tests/unit/api/test_base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ def test_ready(self, node: CeleryTestNode):
5656
def test_config(self, node: CeleryTestNode):
5757
assert node.config()
5858

59+
def test_config_kwarg_vhost(self, node: CeleryTestNode):
60+
vhost = "/test_vhost"
61+
config = node.config()
62+
assert "vhost" not in config
63+
assert config["url"].endswith(vhost) is False
64+
assert config["host_url"].endswith(vhost) is False
65+
config = node.config(vhost=vhost[1:])
66+
assert config["vhost"] == vhost[1:]
67+
assert config["url"].endswith(vhost)
68+
assert config["host_url"].endswith(vhost)
69+
5970
def test_logs(self, node: CeleryTestNode):
6071
assert node.logs()
6172

tests/unit/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def mocked_container(spec: type) -> Mock:
2020
mocked_container = Mock(spec=spec)
2121
mocked_container.id = "mocked_test_container_id"
2222
mocked_container.celeryconfig = {
23-
"url": "mocked_url",
24-
"host_url": "mocked_host_url",
23+
"url": "mocked_url/",
24+
"host_url": "mocked_host_url/",
2525
}
2626
return mocked_container
2727

0 commit comments

Comments
 (0)