Add add_host implementation and testing to URIBuilder

This commit is contained in:
Ian Cordasco 2017-03-12 19:49:55 -05:00
parent 5aab5ae8b4
commit 3936f8a7fd
No known key found for this signature in database
GPG Key ID: 656D3395E4A9791A
2 changed files with 32 additions and 0 deletions

View File

@ -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,
)

View File

@ -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'