예제 #1
0
 def it_flattens_nested_dicts_with_lists(self):
     data = {'top': {'list': ['a', 'b', 'c']}}
     assert to_nested_php_args(data) == {
         'top[list][0]': 'a',
         'top[list][1]': 'b',
         'top[list][2]': 'c',
     }
예제 #2
0
 def it_flattens_nested_dicts_with_lists(self):
     data = {'top': {'list': ['a', 'b', 'c']}}
     assert to_nested_php_args(data) == {
         'top[list][0]': 'a',
         'top[list][1]': 'b',
         'top[list][2]': 'c',
     }
예제 #3
0
 def test_lists(self):
     data = {'top': {'list': ['a', 'b', 'c']}}
     result = utils.to_nested_php_args(data)
     self.assertEqual(result, {
         'top[list][0]': 'a',
         'top[list][1]': 'b',
         'top[list][2]': 'c',
     })
예제 #4
0
 def test_accepts_list_of_tuples(self):
     data = [('top', {'list': ['a', 'b', 'c']})]
     result = utils.to_nested_php_args(data)
     self.assertEqual(result, [
         ('top[list][2]', 'c'),
         ('top[list][0]', 'a'),
         ('top[list][1]', 'b'),
     ])
예제 #5
0
 def _encode_data(data):
     """URL encode data."""
     data = data if data is not None else {}
     data = to_nested_php_args(data)
     files = dict([(key, value) for key, value in data.items() if isinstance(value, file_type)])
     for fname in files:
         del data[fname]
     return data, files or None, None
예제 #6
0
 def _encode_data(data):
     """URL encode data."""
     data = data if data is not None else {}
     data = to_nested_php_args(data)
     files = dict([(key, value) for key, value in data.items()
                   if isinstance(value, file_type)])
     for fname in files:
         del data[fname]
     return data, files or None, None
예제 #7
0
 def test_nested_dicts(self):
     data = {
         'dict': {
             'muffin': {
                 'taco': {
                     'puffin': 'value'
                 }
             }
         }
     }
     result = utils.to_nested_php_args(data)
     self.assertEqual(result, {'dict[muffin][taco][puffin]': 'value'})
예제 #8
0
 def it_flattens_multiple_levels_of_nested_dicts(self):
     data = {
         'dict': {
             'muffin': {
                 'taco': {
                     'puffin': 'value',
                 },
             },
         },
     }
     assert to_nested_php_args(data) == {
         'dict[muffin][taco][puffin]': 'value',
     }
예제 #9
0
 def it_flattens_multiple_levels_of_nested_dicts(self):
     data = {
         'dict': {
             'muffin': {
                 'taco': {
                     'puffin': 'value',
                 },
             },
         },
     }
     assert to_nested_php_args(data) == {
         'dict[muffin][taco][puffin]': 'value',
     }
예제 #10
0
 def _encode_data(self, data):
     """URL encode data."""
     data = data if data is not None else {}
     data = to_nested_php_args(data)
     return urlencode_unicode(data)
예제 #11
0
 def it_flattens_nested_dict(self):
     data = {'dict': {'key': 'value'}}
     assert to_nested_php_args(data) == {'dict[key]': 'value'}
예제 #12
0
 def it_raises_type_error_on_bad_data_types(self):
     x = object()
     with pytest.raises(TypeError) as e:
         to_nested_php_args(x)
     assert str(e.value) == "expected dict or list, got {0}".format(type(x))
예제 #13
0
 def it_flattens_nested_lists_of_tuples(self, data, result):
     assert sorted(to_nested_php_args(data)) == result
예제 #14
0
 def it_raises_type_error_on_bad_data_types(self):
     x = object()
     with pytest.raises(TypeError) as e:
         to_nested_php_args(x)
     assert str(e.value) == "expected dict or list, got {0}".format(type(x))
예제 #15
0
 def it_flattens_nested_dict(self):
     data = {'dict': {'key': 'value'}}
     assert to_nested_php_args(data) == {'dict[key]': 'value'}
예제 #16
0
 def it_flattens_nested_lists_of_tuples(self, data, result):
     assert sorted(to_nested_php_args(data)) == result
예제 #17
0
 def test_single_level_dict(self):
     data = {'dict': {'key': 'value'}}
     result = utils.to_nested_php_args(data)
     self.assertEqual(result, {'dict[key]': 'value'})