Ejemplo n.º 1
0
    def test_with_auth_with_two_args_replaces_whole_auth_string_with_username_and_password(self):
        # Replaces username-only auth string
        url = URLObject('https://[email protected]/')
        assert url.with_auth('zack', '1234') == 'https://*****:*****@github.com/'

        # Replaces username and password.
        url = URLObject('https://*****:*****@github.com/')
        assert url.with_auth('zack', '1234') == 'https://*****:*****@github.com/'
Ejemplo n.º 2
0
 def test_without_auth_removes_entire_auth_string(self):
     # No username or password => no-op.
     url = URLObject('https://github.com/')
     assert url.without_auth() == 'https://github.com/'
     # Username-only.
     url = URLObject('https://[email protected]/')
     assert url.without_auth() == 'https://github.com/'
     # Username and password.
     url = URLObject('https://*****:*****@github.com/')
     assert url.without_auth() == 'https://github.com/'
Ejemplo n.º 3
0
 def test_set_query_params_with_multiple_values_adds_or_replaces_the_same_parameter_multiple_times(self):
     assert (self.url.set_query_params({'spam': ['bar', 'baz']}) ==
             'https://github.com/fish2000/urlstring?spam=bar&spam=baz#foo')
     assert (self.url.set_query_params({'foo': ['bar', 'baz']}) ==
             'https://github.com/fish2000/urlstring?spam=eggs&foo=bar&foo=baz#foo')
     # Ensure it removes all appearances of an existing name before adding
     # the new ones.
     url = URLObject('https://github.com/fish2000/urlstring?foo=bar&foo=baz#foo')
     assert (url.set_query_params({'foo': ['spam', 'ham']}) ==
             'https://github.com/fish2000/urlstring?foo=spam&foo=ham#foo')
Ejemplo n.º 4
0
 def test_query_multi_dict_returns_a_multi_dict_of_query_params(self):
     url = URLObject('https://example.com/?spam=eggs&spam=ham&foo=bar')
     assert url.query_multi_dict == {'spam': ['eggs', 'ham'],
                                     'foo': ['bar']}
Ejemplo n.º 5
0
 def setUp(self):
     self.url = URLObject("https://github.com/fish2000/urlstring?spam=eggs#foo")
Ejemplo n.º 6
0
 def test_calling_unicode_on_a_urlstring_returns_a_normal_string(self):
     url = URLObject(self.url_string)
     # Normally `type(x) is Y` is a bad idea, but it's exactly what we want.
     assert type(text_type(url)) is text_type
     assert text_type(url) == self.url_string
Ejemplo n.º 7
0
 def test_parent_jumps_up_one_level(self):
     url = URLObject('https://github.com/fish2000/urlstring')
     assert url.parent == 'https://github.com/fish2000/'
     assert url.parent.parent == 'https://github.com/'
Ejemplo n.º 8
0
 def test_urlstring_preserves_the_hash_of_the_original_string(self):
     assert hash(URLObject(self.url_string)) == hash(self.url_string)
Ejemplo n.º 9
0
 def test_without_username_removes_username(self):
     url = URLObject('https://[email protected]/')
     assert url.without_username() == 'https://github.com/'
Ejemplo n.º 10
0
 def test_with_username_replaces_username(self):
     url = URLObject('https://[email protected]/')
     assert url.with_username('alice') == 'https://[email protected]/'
Ejemplo n.º 11
0
 def test_with_hostname_replaces_hostname(self):
     url = URLObject('https://*****:*****@github.com/')
     assert (url.with_hostname('example.com') ==
             'https://*****:*****@example.com/')
Ejemplo n.º 12
0
 def test_auth_properties_return_None_with_no_username_or_password(self):
     url = URLObject('https://github.com/')
     assert url.username is None
     assert url.password is None
     assert url.auth == (None, None)
Ejemplo n.º 13
0
 def test_auth_properties_can_parse_username(self):
     url = URLObject('https://[email protected]/')
     assert url.username == 'zack'
     assert url.password is None
     assert url.auth == ('zack', None)
Ejemplo n.º 14
0
 def test_auth_properties_can_parse_username_and_password(self):
     url = URLObject('https://*****:*****@github.com/')
     assert url.username == 'zack'
     assert url.password == '12345'
     assert url.auth == ('zack', '12345')
Ejemplo n.º 15
0
 def test_fragment_is_decoded_correctly(self):
     url = URLObject('https://example.com/#frag%20ment')
     assert url.fragment == 'frag ment'
Ejemplo n.º 16
0
 def test_urlstring_preserves_equality_with_the_original_string(self):
     assert URLObject(self.url_string) == self.url_string
Ejemplo n.º 17
0
 def test_with_password_adds_password(self):
     url = URLObject('https://[email protected]/')
     assert url.with_password('1234') == 'https://*****:*****@github.com/'
Ejemplo n.º 18
0
 def test_with_password_raises_ValueError_when_there_is_no_username(self):
     url = URLObject('https://github.com/')
     assert_raises(ValueError, lambda: url.with_password('1234'))
Ejemplo n.º 19
0
 def test_with_port_replaces_port_number(self):
     url = URLObject('https://github.com:59/')
     assert url.with_port(67) == 'https://github.com:67/'
Ejemplo n.º 20
0
 def test_with_password_replaces_password(self):
     url = URLObject('https://*****:*****@github.com/')
     assert url.with_password('5678') == 'https://*****:*****@github.com/'
Ejemplo n.º 21
0
 def test_without_port_removes_port_number(self):
     url = URLObject('https://github.com:59/')
     assert url.without_port() == 'https://github.com/'
Ejemplo n.º 22
0
 def test_without_password_removes_password(self):
     url = URLObject('https://*****:*****@github.com/')
     assert url.without_password() == 'https://[email protected]/'
Ejemplo n.º 23
0
 def test_add_path_adds_a_partial_path(self):
     url = URLObject('https://github.com/fish2000/urlstring')
     assert (url.add_path('tree') ==
             'https://github.com/fish2000/urlstring/tree')
     assert (url.add_path('tree/master') ==
             'https://github.com/fish2000/urlstring/tree/master')
Ejemplo n.º 24
0
 def test_with_auth_with_one_arg_adds_username(self):
     url = URLObject('https://github.com/')
     assert url.with_auth('zack') == 'https://[email protected]/'
Ejemplo n.º 25
0
 def test_is_leaf(self):
     assert URLObject('https://github.com/fish2000/urlstring').is_leaf
     assert not URLObject('https://github.com/fish2000/').is_leaf
Ejemplo n.º 26
0
 def test_with_auth_with_one_arg_replaces_whole_auth_string_with_username(self):
     url = URLObject('https://*****:*****@github.com/')
     assert url.with_auth('zack') == 'https://[email protected]/'
Ejemplo n.º 27
0
 def test_del_query_params_removes_multiple_query_parameters(self):
     url = URLObject('https://github.com/fish2000/urlstring?foo=bar&baz=spam#foo')
     assert (url.del_query_params(['foo', 'baz']) ==
             'https://github.com/fish2000/urlstring#foo')
Ejemplo n.º 28
0
 def test_with_auth_with_two_args_adds_username_and_password(self):
     url = URLObject('https://github.com/')
     assert url.with_auth('zack', '1234') == 'https://*****:*****@github.com/'
Ejemplo n.º 29
0
 def test_hostname_returns_hostname(self):
     assert self.url.hostname == 'github.com'
     url = URLObject("https://*****:*****@github.com:443")
     assert url.hostname == 'github.com'
Ejemplo n.º 30
0
 def test_default_port_returns_given_port_when_one_is_specified(self):
     assert URLObject("https://github.com:412").default_port == 412