示例#1
0
 def test_unflatten_container_factory(self):
     def container_factory(parent_key, item_key):
         if item_key.isdigit():
             return []
         return {}
     data = [('foo.0', 'bar')]
     self.assertEqual(api.unflatten(data), {'foo': {'0': 'bar'}})
     self.assertEqual(api.unflatten(data, container_factory=container_factory), {'foo': ['bar']})
示例#2
0
 def test_unflatten_container_factory_with_random_order(self):
     container_factory = lambda parent, item: []
     self.assertEqual(
         api.unflatten([("foo.0", 42), ("foo.1", 23)], container_factory=container_factory), {"foo": [42, 23]}
     )
     self.assertEqual(
         api.unflatten([("foo.1", 23), ("foo.0", 42)], container_factory=container_factory), {"foo": [42, 23]}
     )
示例#3
0
    def test_unflatten_container_factory(self):
        def container_factory(parent_key, item_key):
            if item_key.isdigit():
                return []
            return {}

        data = [("foo.0", "bar")]
        self.assertTrue(api.unflatten(data) == {"foo": {"0": "bar"}})
        self.assertTrue(api.unflatten(data, container_factory=container_factory) == {"foo": ["bar"]})
示例#4
0
    def test_unflatten_container_factory(self):
        def container_factory(parent_key, item_key):
            if item_key.isdigit():
                return []
            return {}

        data = [('foo.0', 'bar')]
        self.assertEqual(api.unflatten(data), {'foo': {'0': 'bar'}})
        self.assertEqual(
            api.unflatten(data, container_factory=container_factory),
            {'foo': ['bar']})
示例#5
0
 def test_unflatten(self):
     for (result, test) in [({}, []), ({
             '0': 'foo'
     }, [('0', 'foo')]), ({
             'foo': 'bar'
     }, [('foo', 'bar')]),
                            ({
                                'foo': {
                                    'bar': {
                                        '0': 10,
                                        '1': 11,
                                        '2': 12,
                                        '3': {
                                            'wibble': {
                                                '0': 'm',
                                                '1': 'a',
                                                '2': 't',
                                                '3': 't'
                                            }
                                        }
                                    }
                                }
                            }, [('foo.bar.0', 10), ('foo.bar.1', 11),
                                ('foo.bar.2', 12),
                                ('foo.bar.3.wibble.0', 'm'),
                                ('foo.bar.3.wibble.1', 'a'),
                                ('foo.bar.3.wibble.2', 't'),
                                ('foo.bar.3.wibble.3', 't')])]:
         self.assertEqual(api.unflatten(test), result)
示例#6
0
 def test_unflatten(self):
     for (result, test) in [
         ({}, []),
         ({'0': 'foo'}, [('0', 'foo')]),
         ({'foo': 'bar'}, [('foo', 'bar')]),
         ({'foo': {'bar': {'0': 10, '1': 11, '2': 12, '3': {'wibble': {'0': 'm', '1': 'a', '2': 't', '3': 't'}}}}},
          [('foo.bar.0', 10), ('foo.bar.1', 11), ('foo.bar.2', 12), ('foo.bar.3.wibble.0', 'm'), ('foo.bar.3.wibble.1', 'a'), ('foo.bar.3.wibble.2', 't'), ('foo.bar.3.wibble.3', 't')])]:
         self.assertEqual(api.unflatten(test), result)
示例#7
0
    def get_post(self):
        def container_factory(parent_key, item_key):
            if item_key.isdigit():
                return []
            return {}

        return unflatten(self.POST.dict_of_lists().iteritems(),
                         container_factory=container_factory)
示例#8
0
 def test_unflatten(self):
     for (result, test) in [
         ({}, []),
         ({"0": "foo"}, [("0", "foo")]),
         ({"foo": "bar"}, [("foo", "bar")]),
         (
             {
                 "foo": {
                     "bar": {"0": 10, "1": 11, "2": 12, "3": {"wibble": {"0": "m", "1": "a", "2": "t", "3": "t"}}}
                 }
             },
             [
                 ("foo.bar.0", 10),
                 ("foo.bar.1", 11),
                 ("foo.bar.2", 12),
                 ("foo.bar.3.wibble.0", "m"),
                 ("foo.bar.3.wibble.1", "a"),
                 ("foo.bar.3.wibble.2", "t"),
                 ("foo.bar.3.wibble.3", "t"),
             ],
         ),
     ]:
         self.assertTrue(api.unflatten(test) == result)
示例#9
0
 def get_post(self):
     def container_factory(parent_key, item_key):
         if item_key.isdigit():
             return []
         return {}
     return unflatten(self.POST.dict_of_lists().iteritems(), container_factory=container_factory)