Skip to content

Commit

Permalink
Hotfix: Allow overriding node celery config with kwargs (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus authored Mar 17, 2024
1 parent ed67255 commit fb092cc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/pytest_celery/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,21 @@ def ready(self) -> bool:

def config(self, *args: tuple, **kwargs: dict) -> dict:
"""Compile the configurations required for Celery from this node."""
return self.container.celeryconfig
config = self.container.celeryconfig

if not args and not kwargs:
return config

for key, value in kwargs.items():
config[key] = value

if key == "vhost":
vhost = str(value)
config["url"] = f"{config['url'][:-1].rstrip('/')}/{vhost}"
config["host_url"] = f"{config['host_url'][:-1].rstrip('/')}/{vhost}"
config[key] = vhost

return config

def logs(self) -> str:
"""Get the logs of the underlying container."""
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/api/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def test_ready(self, node: CeleryTestNode):
def test_config(self, node: CeleryTestNode):
assert node.config()

def test_config_kwarg_vhost(self, node: CeleryTestNode):
vhost = "/test_vhost"
config = node.config()
assert "vhost" not in config
assert config["url"].endswith(vhost) is False
assert config["host_url"].endswith(vhost) is False
config = node.config(vhost=vhost[1:])
assert config["vhost"] == vhost[1:]
assert config["url"].endswith(vhost)
assert config["host_url"].endswith(vhost)

def test_logs(self, node: CeleryTestNode):
assert node.logs()

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def mocked_container(spec: type) -> Mock:
mocked_container = Mock(spec=spec)
mocked_container.id = "mocked_test_container_id"
mocked_container.celeryconfig = {
"url": "mocked_url",
"host_url": "mocked_host_url",
"url": "mocked_url/",
"host_url": "mocked_host_url/",
}
return mocked_container

Expand Down

0 comments on commit fb092cc

Please sign in to comment.