Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Allow overriding node celery config with kwargs #249

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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