Ejemplo n.º 1
0
 def test_iter(self):
     items = (
         Field('foo'),
         Field('bar'),
     )
     assert tuple(SelectionSet(*items)) == items
     assert len(SelectionSet(*items)) == 2
Ejemplo n.º 2
0
 def test_nested(self):
     assert _.foo[_.bar.bing[_.blabla]] == SelectionSet(
         Field('foo',
               selection_set=SelectionSet(
                   Field('bar'),
                   Field('bing',
                         selection_set=SelectionSet(
                             Field('blabla'), )))))
Ejemplo n.º 3
0
 def test_simple(self):
     assert _.foo.bar.blabla[_.foobar.bing] == SelectionSet(
         Field('foo'), Field('bar'),
         Field('blabla',
               selection_set=SelectionSet(
                   Field('foobar'),
                   Field('bing'),
               )))
Ejemplo n.º 4
0
 def test_simple(self):
     assert _.foo.bar.blabla[_.foobar.bing] == SelectionSet(
         Field("foo"),
         Field("bar"),
         Field(
             "blabla",
             selection_set=SelectionSet(Field("foobar"), Field("bing")),
         ),
     )
Ejemplo n.º 5
0
 def test_nested(self):
     assert _.foo[_.bar.bing[_.blabla]] == SelectionSet(
         Field(
             "foo",
             selection_set=SelectionSet(
                 Field("bar"),
                 Field("bing",
                       selection_set=SelectionSet(Field("blabla"))),
             ),
         ))
Ejemplo n.º 6
0
 def test_selection_set(self):
     field = Field(
         'bla',
         fdict({'q': 9}),
         selection_set=SelectionSet(
             Field('blabla'),
             Field('foobar', fdict({'qux': 'another string'})),
             Field('other', selection_set=SelectionSet(Field('baz'), )),
             InlineFragment(on=Dog,
                            selection_set=SelectionSet(
                                Field('name'), Field('bark_volume'),
                                Field('owner',
                                      selection_set=SelectionSet(
                                          Field('name'), )))),
         ))
     assert gql(field) == dedent('''
     bla(q: 9) {
       blabla
       foobar(qux: "another string")
       other {
         baz
       }
       ... on Dog {
         name
         bark_volume
         owner {
           name
         }
       }
     }
     ''').strip()
Ejemplo n.º 7
0
        def test_arguments(self):
            field = Field("foo", {"foo": 4, "blabla": "my string!"})

            # arguments are unordered, multiple valid options
            assert gql(field) in [
                'foo(foo: 4, blabla: "my string!")',
                'foo(blabla: "my string!", foo: 4)',
            ]
Ejemplo n.º 8
0
    def test_gql(self):
        op = quiz.Query(Dog, quiz.SelectionSet(Field('name')))
        assert quiz.gql(op) == dedent('''
        query {
          name
        }
        ''').strip()

        assert quiz.gql(op) == str(op)
Ejemplo n.º 9
0
    def test_gql(self):
        op = quiz.Query(Dog, quiz.SelectionSet(Field("name")))
        assert (quiz.gql(op) == dedent("""
        query {
          name
        }
        """).strip())

        assert quiz.gql(op) == str(op)
Ejemplo n.º 10
0
        def test_arguments(self):
            field = Field('foo', {
                'foo': 4,
                'blabla': 'my string!',
            })

            # arguments are unordered, multiple valid options
            assert gql(field) in [
                'foo(foo: 4, blabla: "my string!")',
                'foo(blabla: "my string!", foo: 4)',
            ]
Ejemplo n.º 11
0
 def test_combination(self):
     assert _.foo.bar[_.bing(param1=4.1).baz.foo_bar_bla(
         p2=None, r='')[_.height(unit='cm')].oof.qux()] == SelectionSet(
             Field('foo'),
             Field('bar',
                   selection_set=SelectionSet(
                       Field('bing', fdict({'param1': 4.1})),
                       Field('baz'),
                       Field(
                           'foo_bar_bla', fdict({
                               'p2': None,
                               'r': ''
                           }),
                           SelectionSet(
                               Field('height', fdict({'unit': 'cm'})), )),
                       Field('oof'),
                       Field('qux'),
                   )))
Ejemplo n.º 12
0
 def test_selection_set(self):
     field = Field(
         "bla",
         fdict({"q": 9}),
         selection_set=SelectionSet(
             Field("blabla"),
             Field("foobar", fdict({"qux": "another string"})),
             Field("other", selection_set=SelectionSet(Field("baz"))),
             InlineFragment(
                 on=Dog,
                 selection_set=SelectionSet(
                     Field("name"),
                     Field("bark_volume"),
                     Field(
                         "owner",
                         selection_set=SelectionSet(Field("name")),
                     ),
                 ),
             ),
         ),
     )
     assert (gql(field) == dedent("""
     bla(q: 9) {
       blabla
       foobar(qux: "another string")
       other {
         baz
       }
       ... on Dog {
         name
         bark_volume
         owner {
           name
         }
       }
     }
     """).strip())
Ejemplo n.º 13
0
 def test_combination(self):
     assert _.foo.bar[_.bing(param1=4.1).baz.foo_bar_bla(
         p2=None, r="")[_.height(unit="cm")].oof.qux()] == SelectionSet(
             Field("foo"),
             Field(
                 "bar",
                 selection_set=SelectionSet(
                     Field("bing", fdict({"param1": 4.1})),
                     Field("baz"),
                     Field(
                         "foo_bar_bla",
                         fdict({
                             "p2": None,
                             "r": ""
                         }),
                         SelectionSet(Field("height", fdict({"unit":
                                                             "cm"}))),
                     ),
                     Field("oof"),
                     Field("qux"),
                 ),
             ),
         )
Ejemplo n.º 14
0
 def test_getattr(self):
     assert _.foo_field.bla == SelectionSet(Field("foo_field"),
                                            Field("bla"))
Ejemplo n.º 15
0
 def test_empty(self):
     assert gql(Field("foo")) == "foo"
Ejemplo n.º 16
0
 def test_simple(self):
     assert _.foo(bla=4, bar=None) == SelectionSet(
         Field('foo', {
             'bla': 4,
             'bar': None
         }), )
Ejemplo n.º 17
0
 def test_hash(self):
     assert hash(Field("foo",
                       fdict({"bar":
                              3}))) == hash(Field("foo", fdict({"bar": 3})))
     assert hash(Field("bla", fdict({"bla": 4}))) != hash(Field("bla"))
Ejemplo n.º 18
0
 def test_argument_named_self(self):
     assert _.foo(self=4, bla=3) == SelectionSet(
         Field("foo", fdict({
             "self": 4,
             "bla": 3
         })))
Ejemplo n.º 19
0
 def test_alias(self):
     assert _("foo").bla(a=4) == SelectionSet(
         Field("bla", {"a": 4}, alias="foo"))
Ejemplo n.º 20
0
 def test_simple(self):
     assert _.foo(bla=4, bar=None) == SelectionSet(
         Field("foo", {
             "bla": 4,
             "bar": None
         }))
Ejemplo n.º 21
0
 def test_empty(self):
     assert _.foo() == SelectionSet(Field("foo"))
Ejemplo n.º 22
0
 def test_argument_named_self(self):
     assert _.foo(self=4, bla=3) == SelectionSet(
         Field('foo', fdict({
             'self': 4,
             'bla': 3
         })))
Ejemplo n.º 23
0
 def test_defaults(self):
     f = Field("foo")
     assert f.kwargs == {}
     assert isinstance(f.kwargs, fdict)
     assert f.selection_set == SelectionSet()
     assert isinstance(f.selection_set, SelectionSet)
Ejemplo n.º 24
0
 def test_alias(self):
     assert _('foo').bla(a=4) == SelectionSet(
         Field('bla', {'a': 4}, alias='foo'))
Ejemplo n.º 25
0
 def test_hash(self):
     assert hash(Field('foo',
                       fdict({'bar':
                              3}))) == hash(Field('foo', fdict({'bar': 3})))
     assert hash(Field('bla', fdict({'bla': 4}))) != hash(Field('bla'))
Ejemplo n.º 26
0
 def test_alias(self):
     field = Field("foo", {"a": 4}, alias="my_alias")
     assert gql(field) == "my_alias: foo(a: 4)"
Ejemplo n.º 27
0
 def test_empty(self):
     assert gql(Field('foo')) == 'foo'
Ejemplo n.º 28
0
 def test_alias(self):
     field = Field('foo', {
         'a': 4,
     }, alias='my_alias')
     assert gql(field) == 'my_alias: foo(a: 4)'
Ejemplo n.º 29
0
 def test_iter(self):
     items = (Field("foo"), Field("bar"))
     assert tuple(SelectionSet(*items)) == items
     assert len(SelectionSet(*items)) == 2
Ejemplo n.º 30
0
 def test_getattr(self):
     assert _.foo_field.bla == SelectionSet(
         Field('foo_field'),
         Field('bla'),
     )