-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor building vh and add tests for this
- Loading branch information
Showing
5 changed files
with
82 additions
and
32 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,54 @@ | ||
from typing import Any, Dict | ||
|
||
import pytest | ||
from yarl import URL | ||
|
||
from faststream.rabbit.utils import build_url | ||
|
||
|
||
class TestUrlBuilder: | ||
def test_arg_priority_over_url(self, settings): | ||
url = build_url( | ||
url=settings.url, | ||
host="host", | ||
port=5673, | ||
login="test", | ||
password="test", # pragma: allowlist secret | ||
virtualhost="test", | ||
) | ||
assert url == URL("amqp://test:test@host:5673/test") | ||
|
||
def test_ssl_overwrites_protocol(self, settings): | ||
url = build_url(url=settings.url, ssl=True) | ||
assert url == URL("amqps://guest:guest@localhost:5672/") | ||
|
||
@pytest.mark.parametrize( | ||
("passed_url", "expected_url"), | ||
[ | ||
pytest.param( | ||
"amqp://guest:guest@localhost:5672//", # pragma: allowlist secret | ||
URL("amqp://guest:guest@localhost:5672//"), | ||
), | ||
pytest.param( | ||
"amqp://guest:guest@localhost:5672//test", # pragma: allowlist secret | ||
URL("amqp://guest:guest@localhost:5672//test"), | ||
), | ||
], | ||
) | ||
def test_exotic_virtualhost_variants(self, passed_url: str, expected_url: URL): | ||
url = build_url(passed_url) | ||
assert url == expected_url | ||
|
||
@pytest.mark.parametrize( | ||
("url_kwargs", "expected_url"), | ||
[ | ||
pytest.param({}, URL("amqp://guest:guest@localhost:5672/")), | ||
pytest.param( | ||
{"url": "fake", "virtualhost": "/", "host": "host"}, | ||
URL("amqp://guest:guest@host:5672/"), | ||
), | ||
], | ||
) | ||
def test_unpack_args(self, url_kwargs: Dict[str, Any], expected_url: URL) -> None: | ||
url = build_url(**url_kwargs) | ||
assert url == expected_url |