-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: when / present in virtual host name and passing as uri (#1979)
* fix: when extra / present in virtual host name e.g name of vh is "/test" there is no problenm if passing vh separately, result url will "amqp://root:123@localhost:5672//test" but if pass vh in uri, result uri will "amqp://root:123@localhost:5672/test" cause lstrip("/") calling and slash missing in result url, so replace with count 1 is ok * add test for rabbit broker build_url * refactor building vh and add tests for this * Update test_url_builder.py * Update test_url_builder.py --------- Co-authored-by: Pastukhov Nikita <[email protected]>
- Loading branch information
Showing
5 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/faststream/rabbit/utils/build_virtual_host.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.rabbit.utils.build_virtual_host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Any, Dict | ||
|
||
import pytest | ||
from yarl import URL | ||
|
||
from faststream.rabbit.utils import build_url | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("url_kwargs", "expected_url"), | ||
[ | ||
pytest.param( | ||
{}, | ||
URL("amqp://guest:guest@localhost:5672/"), # pragma: allowlist secret | ||
id="blank params use defaults", | ||
), | ||
pytest.param( | ||
{"ssl": True}, | ||
URL("amqps://guest:guest@localhost:5672/"), # pragma: allowlist secret | ||
id="ssl affects protocol", | ||
), | ||
pytest.param( | ||
{"url": "fake", "virtualhost": "/", "host": "host"}, | ||
URL("amqp://guest:guest@host:5672/"), # pragma: allowlist secret | ||
id="kwargs overrides url", | ||
), | ||
pytest.param( | ||
{"virtualhost": "//test"}, # pragma: allowlist secret | ||
URL( | ||
"amqp://guest:guest@localhost:5672//test" # pragma: allowlist secret | ||
), | ||
id="exotic virtualhost", | ||
), | ||
], | ||
) | ||
def test_unpack_args(url_kwargs: Dict[str, Any], expected_url: URL) -> None: | ||
url = build_url(**url_kwargs) | ||
assert url == expected_url |