Skip to content

Commit

Permalink
Hotfix: Allow overriding node celery config with kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Mar 17, 2024
1 parent ed67255 commit dcc605f
Show file tree
Hide file tree
Showing 3 changed files with 27 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"] = config["url"][:-1] + f"{vhost}"
config["host_url"] = config["host_url"][:-1] + f"{vhost}"
config[key] = vhost

return config

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

def test_config_kwarg_vhost(self, node: CeleryTestNode):
config = node.config()
assert "vhost" not in config
assert config["url"].endswith("test_vhost") is False
assert config["host_url"].endswith("test_vhost") is False
config = node.config(vhost="test_vhost")
assert config["vhost"] == "test_vhost"
assert config["url"].endswith("test_vhost")
assert config["host_url"].endswith("test_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 dcc605f

Please sign in to comment.