diff --git a/src/pytest_celery/api/base.py b/src/pytest_celery/api/base.py index bfed5e03..2e551239 100644 --- a/src/pytest_celery/api/base.py +++ b/src/pytest_celery/api/base.py @@ -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.""" diff --git a/tests/unit/api/test_base.py b/tests/unit/api/test_base.py index cceacc3f..c2481f75 100644 --- a/tests/unit/api/test_base.py +++ b/tests/unit/api/test_base.py @@ -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() diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index bfbde243..0325aa1c 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -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