Add add_host implementation and testing to URIBuilder
This commit is contained in:
parent
5aab5ae8b4
commit
3936f8a7fd
|
@ -114,3 +114,23 @@ class URIBuilder(object):
|
|||
query=self.query,
|
||||
fragment=self.fragment,
|
||||
)
|
||||
|
||||
def add_host(self, host):
|
||||
"""Add hostname to the URI.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> URIBuilder().add_host('google.com')
|
||||
URIBuilder(scheme=None, userinfo=None, host='google.com',
|
||||
port=None, path=None, query=None, fragment=None)
|
||||
|
||||
"""
|
||||
return URIBuilder(
|
||||
scheme=self.scheme,
|
||||
userinfo=self.userinfo,
|
||||
host=normalizers.normalize_host(host),
|
||||
port=self.port,
|
||||
path=self.path,
|
||||
query=self.query,
|
||||
fragment=self.fragment,
|
||||
)
|
||||
|
|
|
@ -65,3 +65,15 @@ def test_add_credentials_requires_username():
|
|||
"""Verify one needs a username to add credentials."""
|
||||
with pytest.raises(ValueError):
|
||||
builder.URIBuilder().add_credentials(None, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('hostname', [
|
||||
'google.com',
|
||||
'GOOGLE.COM',
|
||||
'gOOgLe.COM',
|
||||
'goOgLE.com',
|
||||
])
|
||||
def test_add_host(hostname):
|
||||
"""Verify we normalize hostnames in add_host."""
|
||||
uribuilder = builder.URIBuilder().add_host(hostname)
|
||||
assert uribuilder.host == 'google.com'
|
||||
|
|
Loading…
Reference in New Issue