Пример #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'})