コード例 #1
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 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()
コード例 #2
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_iter(self):
     items = (
         Field('foo'),
         Field('bar'),
     )
     assert tuple(SelectionSet(*items)) == items
     assert len(SelectionSet(*items)) == 2
コード例 #3
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_nested(self):
     assert _.foo[_.bar.bing[_.blabla]] == SelectionSet(
         Field('foo',
               selection_set=SelectionSet(
                   Field('bar'),
                   Field('bing',
                         selection_set=SelectionSet(
                             Field('blabla'), )))))
コード例 #4
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_simple(self):
     assert _.foo.bar.blabla[_.foobar.bing] == SelectionSet(
         Field('foo'), Field('bar'),
         Field('blabla',
               selection_set=SelectionSet(
                   Field('foobar'),
                   Field('bing'),
               )))
コード例 #5
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_simple(self):
     assert _.foo.bar.blabla[_.foobar.bing] == SelectionSet(
         Field("foo"),
         Field("bar"),
         Field(
             "blabla",
             selection_set=SelectionSet(Field("foobar"), Field("bing")),
         ),
     )
コード例 #6
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_nested(self):
     assert _.foo[_.bar.bing[_.blabla]] == SelectionSet(
         Field(
             "foo",
             selection_set=SelectionSet(
                 Field("bar"),
                 Field("bing",
                       selection_set=SelectionSet(Field("blabla"))),
             ),
         ))
コード例 #7
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 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'),
                   )))
コード例 #8
0
ファイル: test_build.py プロジェクト: white54503/quiz
 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"),
                 ),
             ),
         )
コード例 #9
0
ファイル: test_build.py プロジェクト: white54503/quiz
 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())
コード例 #10
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_simple(self):
     assert _.foo(bla=4, bar=None) == SelectionSet(
         Field('foo', {
             'bla': 4,
             'bar': None
         }), )
コード例 #11
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_iter(self):
     items = (Field("foo"), Field("bar"))
     assert tuple(SelectionSet(*items)) == items
     assert len(SelectionSet(*items)) == 2
コード例 #12
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_argument_named_self(self):
     assert _.foo(self=4, bla=3) == SelectionSet(
         Field("foo", fdict({
             "self": 4,
             "bla": 3
         })))
コード例 #13
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_alias(self):
     assert _("foo").bla(a=4) == SelectionSet(
         Field("bla", {"a": 4}, alias="foo"))
コード例 #14
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_simple(self):
     assert _.foo(bla=4, bar=None) == SelectionSet(
         Field("foo", {
             "bla": 4,
             "bar": None
         }))
コード例 #15
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_empty(self):
     assert _.foo() == SelectionSet(Field("foo"))
コード例 #16
0
ファイル: test_build.py プロジェクト: white54503/quiz
 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)
コード例 #17
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_argument_named_self(self):
     assert _.foo(self=4, bla=3) == SelectionSet(
         Field('foo', fdict({
             'self': 4,
             'bla': 3
         })))
コード例 #18
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_alias(self):
     assert _('foo').bla(a=4) == SelectionSet(
         Field('bla', {'a': 4}, alias='foo'))
コード例 #19
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_empty(self):
     assert _ == SelectionSet()
コード例 #20
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_getattr(self):
     assert _.foo_field.bla == SelectionSet(Field("foo_field"),
                                            Field("bla"))
コード例 #21
0
ファイル: test_build.py プロジェクト: white54503/quiz
 def test_hash(self):
     assert hash(SelectionSet()) == hash(SelectionSet())
     assert hash(_.foo.bar) == hash(_.foo.bar)
     assert hash(_.bar.foo) != hash(_.foo.bar)
コード例 #22
0
ファイル: test_build.py プロジェクト: rmarren1/quiz
 def test_getattr(self):
     assert _.foo_field.bla == SelectionSet(
         Field('foo_field'),
         Field('bla'),
     )