Ejemplo n.º 1
0
def test_field():
    check_read(
        """
        [:foo :bar]
        """,
        Node([Field('foo'), Field('bar')]),
    )
Ejemplo n.º 2
0
def test_link():
    check_read(
        """
        [{:foo [:bar :baz]}]
        """,
        Node([Link('foo', Node([Field('bar'), Field('baz')]))]),
    )
Ejemplo n.º 3
0
def test_field_options():
    check_read(
        """
        [(:foo {:bar 1}) :baz]
        """,
        Node([Field('foo', options={'bar': 1}),
              Field('baz')]),
    )
Ejemplo n.º 4
0
def test_invalid_options():
    with pytest.raises(ParseError) as type_err:
        export(Node([Field('kott', options={'clauber': UNKNOWN})]))
    type_err.match('has unexpected type')

    with pytest.raises(ParseError) as item_type_err:
        export(Node([Field('puerco', options={'bayat': [1, UNKNOWN, 3]})]))
    item_type_err.match('has unexpected type')
Ejemplo n.º 5
0
def test_distinct_by_name_fields():
    query = Node([
        Field('a'),
        Field('b', options={'x': 1}, alias='a'),
        Field('a'),
    ])
    assert merge([query]) == Node([
        Field('a'),
        Field('b', options={'x': 1}, alias='a'),
    ])
Ejemplo n.º 6
0
def test_distinct_by_options_fields():
    query = Node([
        Field('a'),
        Field('a', options={'x': 1}),
        Field('a'),
    ])
    assert merge([query]) == Node([
        Field('a'),
        Field('a', options={'x': 1}),
    ])
Ejemplo n.º 7
0
def test_link_alias():
    check_read(
        '{ a: b { c d } }',
        Node([
            Link('b', Node([
                Field('c'),
                Field('d'),
            ]), alias='a'),
        ]),
    )
Ejemplo n.º 8
0
def test_query_list():

    @define(Record[{'clacks': Any, 'panicle': Any}])
    def foo():
        pass

    check_query(
        each(S.x, S.comped, [foo(S.weigh), foo(S.x)]),
        Node([Link('comped', Node([Field('clacks'), Field('panicle')])),
              Link('weigh', Node([Field('clacks'), Field('panicle')]))]),
    )
Ejemplo n.º 9
0
def test_skip_field(skip):
    check_read(
        """
        query Page($cond: Boolean!) {
          foo
          bar @skip(if: $cond)
        }
        """,
        Node([Field('foo')] + ([] if skip else [Field('bar')])),
        {'cond': skip},
    )
Ejemplo n.º 10
0
def test_include_field(include):
    check_read(
        """
        query Page($cond: Boolean!) {
          foo
          bar @include(if: $cond)
        }
        """,
        Node([Field('foo')] + ([Field('bar')] if include else [])),
        {'cond': include},
    )
Ejemplo n.º 11
0
def test_include_inline_fragment(include):
    check_read(
        """
        query Page($cond: Boolean!) {
          foo
          ... on Thing @include(if: $cond) {
            bar
          }
        }
        """,
        Node([Field('foo')] + ([Field('bar')] if include else [])),
        {'cond': include},
    )
Ejemplo n.º 12
0
 def testTupleWithNestedLinkToMany(self):
     self.assertRequires(
         baz(S.y),
         Edge([Link('y',
                    Edge([Field('e'),
                          Link('xs', Edge([Field('b')]))]))]),
     )
     self.assertRequires(
         each(S.item, S.ys, baz(S.item)),
         Edge([Link('ys',
                    Edge([Field('e'),
                          Link('xs', Edge([Field('b')]))]))]),
     )
Ejemplo n.º 13
0
def test_skip_inline_fragment(skip):
    check_read(
        """
        query Page($cond: Boolean!) {
          foo
          ... on Thing @skip(if: $cond) {
            bar
          }
        }
        """,
        Node([Field('foo')] + ([] if skip else [Field('bar')])),
        {'cond': skip},
    )
Ejemplo n.º 14
0
def test_skip_fragment_spread(skip):
    check_read(
        """
        query Page($cond: Boolean!) {
          foo
          ...Fragment @skip(if: $cond)
        }
        fragment Fragment on Thing {
          bar
        }
        """,
        Node([Field('foo')] + ([] if skip else [Field('bar')])),
        {'cond': skip},
    )
Ejemplo n.º 15
0
def test_include_fragment_spread(include):
    check_read(
        """
        query Page($cond: Boolean!) {
          foo
          ...Fragment @include(if: $cond)
        }
        fragment Fragment on Thing {
          bar
        }
        """,
        Node([Field('foo')] + ([Field('bar')] if include else [])),
        {'cond': include},
    )
Ejemplo n.º 16
0
def test_link_options():
    check_read(
        """
        [{(:foo {:bar 1}) [:baz]}]
        """,
        Node([Link('foo', Node([Field('baz')]), options={'bar': 1})]),
    )
Ejemplo n.º 17
0
def test_ref_root_node_field():
    malatya_ref = NamedRef(None, 'malatya', ROOT_TYPES['malatya'])
    check_req(malatya_ref, Node([Link('malatya', Node([]))]))

    bartok_ref = NamedRef(malatya_ref, 'bartok',
                          ROOT_TYPES['malatya'].__field_types__['bartok'])
    check_req(bartok_ref, Node([Link('malatya', Node([Field('bartok')]))]))
Ejemplo n.º 18
0
def test_options():
    check_export(
        Node([Field('foo', options={'bar': [1, {
            'baz': 2
        }, 3]})]),
        '{\n  foo(bar: [1, {baz: 2}, 3])\n}\n',
    )
Ejemplo n.º 19
0
def test_node():
    node = query_pb2.Node()
    node.items.add().field.name = 'aimer'

    query = Node([Field('aimer')])

    assert export(query) == node
Ejemplo n.º 20
0
def test_link():
    node = t.Node()
    link_item = node.items.add()
    link_item.link.name = 'swaying'
    field_item = link_item.link.node.items.add()
    field_item.field.name = 'pelew'
    check_read(node, Node([Link('swaying', Node([Field('pelew')]))]))
Ejemplo n.º 21
0
def test_node_field_options():
    node = t.Node()
    item = node.items.add()
    item.field.name = 'sprayed'
    item.field.options['treason'] = 123
    item.field.options['prizren'] = 'stager'
    check_read(node, Node([Field('sprayed', {'treason': 123,
                                             'prizren': 'stager'})]))
Ejemplo n.º 22
0
 def test(self):
     with reqs_eq_patcher():
         self.assertEqual(
             read("""
             { hello }
             """),
             Edge([Field('hello')]),
         )
Ejemplo n.º 23
0
    def testEdgeField(self):
        x_ref = NamedRef(None, 'x', Env.x)
        self.assertReq(x_ref,
                       Edge([Link('x', Edge([]))]))

        a_ref = NamedRef(x_ref, 'a', Env.x.fields['a'])
        self.assertReq(a_ref,
                       Edge([Link('x', Edge([Field('a')]))]))
Ejemplo n.º 24
0
def test_query_tuple_with_simple_args():

    @define(Record[{'clacks': Any, 'panicle': Any}],
            Any,
            Record[{'oloroso': Any, 'gashes': Any}],
            Any)
    def foo():
        pass

    check_query(
        foo(S.weigh, 1, S.weigh.apatite, 2),
        Node([Link('weigh',
                   Node([Field('clacks'),
                         Field('panicle'),
                         Link('apatite',
                              Node([Field('oloroso'),
                                    Field('gashes')]))]))]),
    )
Ejemplo n.º 25
0
def test_complex_field_args():
    check_read(
        '{ saale(lammie: "nursy") { slighty } }',
        Node([
            Link('saale',
                 Node([Field('slighty')]),
                 options={'lammie': 'nursy'})
        ]),
    )
Ejemplo n.º 26
0
def test():
    query = build([
        Q.tyan,
        Q.turlock[Q.gange],
        Q.tiber(ramsons='defaces')[Q.decifer(botches='auxerre'),
                                   Q.exocet(brogues='hygiea'), ],
    ])
    with reqs_eq_patcher():
        assert query == Node([
            Field('tyan'),
            Link('turlock', Node([Field('gange')])),
            Link(
                'tiber',
                Node([
                    Field('decifer', options={'botches': 'auxerre'}),
                    Field('exocet', options={'brogues': 'hygiea'}),
                ]), {'ramsons': 'defaces'}),
        ])
Ejemplo n.º 27
0
def test_ref_link_many_node_field():
    comped_ref = NamedRef(None, 'comped', ROOT_TYPES['comped'])
    check_req(comped_ref, Node([Link('comped', Node([]))]))

    patens_ref = Ref(comped_ref, TYPES['patens'])
    check_req(patens_ref, Node([Link('comped', Node([]))]))

    clacks_ref = NamedRef(patens_ref, 'clacks',
                          TYPES['patens'].__field_types__['clacks'])
    check_req(clacks_ref, Node([Link('comped', Node([Field('clacks')]))]))
Ejemplo n.º 28
0
def test_ref_link_one_node_field():
    weigh_ref = NamedRef(None, 'weigh', ROOT_TYPES['weigh'])
    check_req(weigh_ref, Node([Link('weigh', Node([]))]))

    patens_ref = Ref(weigh_ref, TYPES['patens'])
    check_req(patens_ref, Node([Link('weigh', Node([]))]))

    clacks_ref = NamedRef(patens_ref, 'clacks',
                          TYPES['patens'].__field_types__['clacks'])
    check_req(clacks_ref, Node([Link('weigh', Node([Field('clacks')]))]))
Ejemplo n.º 29
0
def test_field_options():
    node = query_pb2.Node()
    field = node.items.add().field
    field.name = 'cody'
    field.options['kink'] = 1234
    field.options['cithara'] = 'slasher'

    query = Node([Field('cody', options={'kink': 1234, 'cithara': 'slasher'})])

    assert export(query) == node
Ejemplo n.º 30
0
def test_link_options():
    node = t.Node()
    link_item = node.items.add()
    link_item.link.name = 'dubiety'
    link_item.link.options['squat'] = 234
    link_item.link.options['liquid'] = 'ravages'
    field_item = link_item.link.node.items.add()
    field_item.field.name = 'gits'
    check_read(node, Node([Link('dubiety', Node([Field('gits')]),
                                {'squat': 234, 'liquid': 'ravages'})]))