-
Notifications
You must be signed in to change notification settings - Fork 292
feat: add build method back to multihosturl #730
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
Merged
davidhewitt
merged 26 commits into
pydantic:main
from
ollz272:add-build-method-to-multihosturl
Jul 11, 2023
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
55cd0c0
feat: add build method back to multihosturl
ollz272 0f42b46
fix: linting
ollz272 c6d9735
fix: remove return statement
ollz272 7d88c9b
fix: add clippy linting error fix
ollz272 c137132
fix: PR comments
ollz272 26c9f2b
fix: formatting
ollz272 e1ff7d3
fix: add build method to pyurl
ollz272 880768d
fix: formatting
ollz272 f29f657
chore: Merge branch 'main' of github.com:ollz272/pydantic-core into a…
ollz272 a38adfe
fix: return a class instance instead of a string
ollz272 d5a30a8
fix: formatting
ollz272 498b1b7
implement hosts argument for MultiHostUrl.build()
davidhewitt 6f60df7
fix: fix up some code, handle new errors etc
ollz272 b00b684
fix: slight refactor
ollz272 d3f3c2a
fix: wip
ollz272 e4f3c32
fix: final updates
ollz272 1497f9e
fix: remove unused imports
ollz272 1724821
fix: remove unused imports
ollz272 7aa36e0
fix: issues
ollz272 87bd446
fix: type hint
ollz272 8e24981
fix: PR changes
ollz272 5cf598f
fix: linting
ollz272 52dd633
fix: final fixes
ollz272 8727e51
chore: Merge branch 'main' of github.com:ollz272/pydantic-core into a…
ollz272 e2da63a
Update src/url.rs
davidhewitt a202960
Update src/url.rs
davidhewitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -1216,3 +1216,86 @@ def test_url_hash() -> None: | |
|
||
def test_url_deepcopy() -> None: | ||
assert deepcopy(Url('http://example.com')) == Url('http://example.com/') | ||
|
||
|
||
def test_multi_url_build() -> None: | ||
url = MultiHostUrl.build( | ||
scheme='postgresql', | ||
username='testuser', | ||
password='testpassword', | ||
host='127.0.0.1', | ||
port=5432, | ||
path='database', | ||
query='sslmode=require', | ||
fragment='test', | ||
) | ||
assert url == MultiHostUrl('postgresql://testuser:[email protected]:5432/database?sslmode=require#test') | ||
assert str(url) == 'postgresql://testuser:[email protected]:5432/database?sslmode=require#test' | ||
|
||
|
||
@pytest.mark.parametrize('field', ['host', 'password', 'username', 'port']) | ||
def test_multi_url_build_hosts_set_with_single_value(field) -> None: | ||
"""Hosts can't be provided with any single url values.""" | ||
hosts = [ | ||
{'host': '127.0.0.1', 'password': 'testpassword', 'username': 'testuser', 'port': 5432}, | ||
{'host': '127.0.0.1', 'password': 'testpassword', 'username': 'testuser', 'port': 5432}, | ||
] | ||
kwargs = dict(scheme='postgresql', hosts=hosts, path='database', query='sslmode=require', fragment='test') | ||
if field == 'port': | ||
kwargs[field] = 5432 | ||
else: | ||
kwargs[field] = 'test' | ||
with pytest.raises(ValueError): | ||
MultiHostUrl.build(**kwargs) | ||
|
||
|
||
def test_multi_url_build_hosts_empty_host() -> None: | ||
"""Hosts can't be provided with any single url values.""" | ||
hosts = [{}] | ||
with pytest.raises(ValueError): | ||
MultiHostUrl.build(scheme='postgresql', hosts=hosts, path='database', query='sslmode=require', fragment='test') | ||
|
||
|
||
def test_multi_url_build_hosts() -> None: | ||
"""Hosts can't be provided with any single url values.""" | ||
hosts = [ | ||
{'host': '127.0.0.1', 'password': 'testpassword', 'username': 'testuser', 'port': 5431}, | ||
{'host': '127.0.0.1', 'password': 'testpassword', 'username': 'testuser', 'port': 5433}, | ||
] | ||
kwargs = dict(scheme='postgresql', hosts=hosts, path='database', query='sslmode=require', fragment='test') | ||
url = MultiHostUrl.build(**kwargs) | ||
assert url == MultiHostUrl( | ||
'postgresql://testuser:[email protected]:5431,testuser:[email protected]:5433/database?sslmode=require#test' | ||
) | ||
assert ( | ||
str(url) | ||
== 'postgresql://testuser:[email protected]:5431,testuser:[email protected]:5433/database?sslmode=require#test' | ||
) | ||
|
||
|
||
def test_multi_url_build_neither_host_and_hosts_set() -> None: | ||
with pytest.raises(ValueError): | ||
MultiHostUrl.build( | ||
scheme='postgresql', | ||
username='testuser', | ||
password='testpassword', | ||
port=5432, | ||
path='database', | ||
query='sslmode=require', | ||
fragment='test', | ||
) | ||
|
||
|
||
def test_url_build() -> None: | ||
url = Url.build( | ||
scheme='postgresql', | ||
username='testuser', | ||
password='testpassword', | ||
host='127.0.0.1', | ||
port=5432, | ||
path='database', | ||
query='sslmode=require', | ||
fragment='test', | ||
) | ||
assert url == Url('postgresql://testuser:[email protected]:5432/database?sslmode=require#test') | ||
assert str(url) == 'postgresql://testuser:[email protected]:5432/database?sslmode=require#test' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.