def test_with_auth_with_two_args_replaces_whole_auth_string_with_username_and_password(self): # Replaces username-only auth string assert (Netloc('*****@*****.**').with_auth('zack', '1234') == 'zack:[email protected]') # Replaces username and password. assert (Netloc('alice:[email protected]').with_auth('zack', '1234') == 'zack:[email protected]')
def test_without_auth_removes_entire_auth_string(self): # No username or password => no-op. netloc = Netloc('github.com') assert netloc.without_auth() == 'github.com' # Username-only. netloc = Netloc('*****@*****.**') assert netloc.without_auth() == 'github.com' # Username and password. netloc = Netloc('alice:[email protected]') assert netloc.without_auth() == 'github.com'
def test_with_auth_with_two_args_adds_username_and_password(self): assert (Netloc('github.com').with_auth('zack', '1234') == 'zack:[email protected]')
def test_with_auth_with_one_arg_replaces_whole_auth_string_with_username(self): assert (Netloc('alice:[email protected]').with_auth('zack') == '*****@*****.**')
def test_auth(self): assert Netloc('github.com').auth == (None, None) assert Netloc('*****@*****.**').auth == ('zack', None) assert Netloc('zack:[email protected]').auth == ('zack', '1234')
def test_with_auth_with_one_arg_adds_username(self): assert (Netloc('github.com').with_auth('zack') == '*****@*****.**')
def test_with_port_replaces_port(self): assert Netloc('github.com:443').with_port(80) == 'github.com:80'
def test_with_hostname_replaces_hostname(self): assert (Netloc('zack:[email protected]:443').with_hostname('example.com') == 'zack:[email protected]:443')
def test_preserves_equality_of_the_original_string(self): netloc = 'zack:[email protected]:443' assert Netloc(netloc) == netloc
def test_password(self): assert Netloc('github.com').password is None assert Netloc('*****@*****.**').password is None assert Netloc('zack:[email protected]').password == '1234'
def test_without_username_removes_username(self): assert Netloc('github.com').without_username() == 'github.com' assert Netloc('*****@*****.**').without_username() == 'github.com' # Removing the username will also remove the password. assert Netloc('zack:[email protected]:443').without_username() == 'github.com:443'
def test_with_username_replaces_username(self): assert (Netloc('*****@*****.**').with_username('alice') == '*****@*****.**') assert (Netloc('zack:[email protected]').with_username('alice') == 'alice:[email protected]')
def test_with_username_adds_username(self): assert Netloc('github.com').with_username('zack') == '*****@*****.**'
def test_username(self): assert Netloc('github.com').username is None assert Netloc('*****@*****.**').username == 'zack' assert Netloc('zack:[email protected]').username == 'zack'
def test_preserves_hash_of_the_original_string(self): netloc = 'zack:[email protected]:443' assert hash(Netloc(netloc)) == hash(netloc)
def test_without_port_removes_port(self): assert Netloc('github.com:443').without_port() == 'github.com'
def test_with_password_adds_password(self): assert (Netloc('*****@*****.**').with_password('1234') == 'zack:[email protected]')
def test_with_password_replaces_password(self): assert (Netloc('zack:[email protected]:443').with_password('5678') == 'zack:[email protected]:443')
def test_hostname(self): assert Netloc('zack:[email protected]:443').hostname == 'github.com'
def test_with_password_on_a_netloc_with_no_username_raises_ValueError(self): assert_raises(ValueError, lambda: Netloc('github.com').with_password('1234'))
def test_port(self): assert Netloc('github.com:443').port == 443 assert Netloc('github.com').port is None
def test_with_port_adds_port(self): assert Netloc('github.com').with_port(443) == 'github.com:443'