Esempio n. 1
0
 def test_multiple_nested_wildcards_with_list_values(self):
     # foo[].bar[].baz
     parsed = ast.Projection(
         ast.Flatten(
             ast.Projection(ast.Flatten(ast.Field('foo')),
                            ast.Field('bar'))), ast.Field('baz'))
     data = {
         "foo": [
             {
                 "bar": [{
                     "baz": [1]
                 }, {
                     "baz": [2]
                 }]
             },
             {
                 "bar": [{
                     "baz": [3]
                 }, {
                     "baz": [4]
                 }]
             },
         ]
     }
     self.assertEqual(parsed.search(data), [[1], [2], [3], [4]])
Esempio n. 2
0
 def test_multiple_nested_wildcards(self):
     # foo[].bar[].baz
     parsed = ast.Projection(
         ast.Flatten(
             ast.Projection(ast.Flatten(ast.Field('foo')),
                            ast.Field('bar'))), ast.Field('baz'))
     data = {
         "foo": [
             {
                 "bar": [{
                     "baz": 1
                 }, {
                     "baz": 2
                 }]
             },
             {
                 "bar": [{
                     "baz": 3
                 }, {
                     "baz": 4
                 }]
             },
         ]
     }
     self.assertEqual(parsed.search(data), [1, 2, 3, 4])
Esempio n. 3
0
 def test_flattened_multiselect_with_none(self):
     # foo[].[bar,baz]
     field_bar = ast.Field('bar')
     field_baz = ast.Field('baz')
     multiselect = ast.MultiFieldList([field_bar, field_baz])
     projection = ast.Projection(ast.Flatten(ast.Field('foo')), multiselect)
     self.assertEqual(
         projection.search({'bar': [{
             'bar': 1,
             'baz': 2,
             'qux': 3
         }]}), None)
Esempio n. 4
0
 def test_nested_filter_projection(self):
     data = {
         "reservations": [{
             "instances": [{
                 "foo": 1,
                 "bar": 2
             }, {
                 "foo": 1,
                 "bar": 3
             }, {
                 "foo": 1,
                 "bar": 2
             }, {
                 "foo": 2,
                 "bar": 1
             }]
         }]
     }
     projection = ast.Projection(
         ast.Flatten(ast.Field('reservations')),
         ast.FilterProjection(
             ast.Field('instances'), ast.Identity(),
             ast.OPEquals(ast.Field('bar'), ast.Literal(1))))
     self.assertEqual(projection.search(data), [[{'bar': 1, 'foo': 2}]])
Esempio n. 5
0
 def test_flattened_wildcard(self):
     # foo[].bar
     parsed = ast.Projection(ast.Flatten(ast.Field('foo')),
                             ast.Field('bar'))
     data = {'foo': [{'bar': 1}, {'bar': 2}, {'bar': 3}]}
     self.assertEqual(parsed.search(data), [1, 2, 3])
Esempio n. 6
0
 def _token_led_flatten(self, left):
     left = ast.Flatten(left)
     right = self._parse_projection_rhs(
         self.BINDING_POWER['flatten'])
     return ast.Projection(left, right)
Esempio n. 7
0
 def _token_nud_flatten(self, token):
     left = ast.Flatten(ast.Identity())
     right = self._parse_projection_rhs(
         self.BINDING_POWER['flatten'])
     return ast.Projection(left, right)