def test_set_params_with_multiple_values_sets_the_same_name_multiple_times(self): s = QueryString('foo=spam') assert (s.set_params({'foo': ['bar', 'baz']}) == 'foo=bar&foo=baz') s2 = QueryString('foo=bar&foo=baz') assert (s2.set_params({'foo': ['spam', 'ham']}) == 'foo=spam&foo=ham')
def test_add_params_accepts_the_same_args_as_dict(self): s = QueryString('') added = s.add_params({'abc': '123'}, foo='bar', xyz='456') assert added.dict == {'abc': '123', 'foo': 'bar', 'xyz': '456'} added2 = s.add_params([('abc', '123')], foo='bar', xyz='456') assert added2.dict == {'abc': '123', 'foo': 'bar', 'xyz': '456'} # It also has to fail in the same way as `dict`. If you pass more than # one positional argument it should raise a TypeError. self.assertRaises(TypeError, s.add_params, {'abc': '123'}, {'foo': 'bar'})
def test_add_param_encodes_utf8(self): s = QueryString('abc=123') assert s.add_param('foo', u('\ufffd')) == 'abc=123&foo=%EF%BF%BD'
def test_add_param_can_add_anonymous_parameters(self): s = QueryString('abc=123') assert s.add_param('', '456') == 'abc=123&=456'
def test_add_param_can_add_empty_valued_parameters(self): s = QueryString('abc=123') assert s.add_param('def', '') == 'abc=123&def='
def test_add_param_can_add_valueless_parameters(self): s = QueryString('abc=123') assert s.add_param('def', None) == 'abc=123&def'
def test_add_param_encodes_and_adds_the_given_parameter_to_the_QueryString(self): s = QueryString('') assert s.add_param('abc', '123') == 'abc=123' assert (s.add_param('abc', '123') .add_param('def', '456') == 'abc=123&def=456')
def test_del_params_accepts_an_iterable_and_removes_all_listed_parameters(self): s = QueryString('abc=123&def=456&xyz=789') assert s.del_params(('abc', 'xyz')) == 'def=456'
def test_set_param_replaces_existing_parameter_names(self): s = QueryString('abc=123&abc=456') assert s.set_param('abc', '789') == 'abc=789'
def test_set_params_accepts_the_same_args_as_dict(self): s = QueryString('') added = s.set_params({'abc': '123'}, abc='456') assert added.dict == {'abc': '456'} added2 = s.set_params([('abc', '123')], abc='456') assert added2.dict == {'abc': '456'}
def test_set_params_is_equivalent_to_calling_set_param_multiple_times(self): s = QueryString('') assert (s.set_params([('abc', '123'), ('def', '456')]) == s.set_param('abc', '123').set_param('def', '456'))
def test_add_params_with_multiple_values_adds_the_same_parameter_multiple_times(self): s = QueryString('') assert (s.add_params({'foo': ['bar', 'baz']}) == s.add_param('foo', 'bar').add_param('foo', 'baz'))
def test_del_param_can_remove_anonymous_parameters(self): s = QueryString('abc=123&=456&def=789') assert s.del_param('') == 'abc=123&def=789'
def test_del_param_can_remove_valueless_parameters(self): valueless = QueryString('abc=123&def&abc=456') empty_valued = QueryString('abc=123&def=&abc=456') assert valueless.del_param('def') == 'abc=123&abc=456' assert empty_valued.del_param('def') == 'abc=123&abc=456'
def test_del_param_removes_all_instances_of_the_parameter_from_the_QueryString(self): s = QueryString('abc=123&def=456&abc=789') assert s.del_param('abc') == 'def=456' assert s.del_param('def') == 'abc=123&abc=789'
def test_add_param_accepts_int(self): s = QueryString('') assert s.add_param('abc', 123) == 'abc=123'
def test_add_param_allows_the_same_parameter_name_to_be_added_twice(self): s = QueryString('abc=123') assert s.add_param('abc', '456') == 'abc=123&abc=456'
def test_add_param_encodes_special_characters(self): s = QueryString('abc=123') assert s.add_param('d e f', '4+5#6') == 'abc=123&d+e+f=4%2B5%236'