Ejemplo n.º 1
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.º 2
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.º 3
0
    def test_query(self):
        query = quiz.Query(DogQuery, _.dog[_.name.bark_volume])
        client = MockClient(
            snug.Response(
                200,
                json.dumps({
                    'data': {
                        'dog': {
                            'name': 'Fred',
                            'bark_volume': 8,
                        }
                    }
                }).encode()))
        result = quiz.execute(query, url='https://my.url/api', client=client)
        assert result == DogQuery(dog=Dog(
            name='Fred',
            bark_volume=8,
        ))

        request = client.request
        assert request.url == 'https://my.url/api'
        assert request.method == 'POST'
        assert json.loads(request.content.decode()) == {
            'query': quiz.gql(query)
        }
        assert request.headers == {'Content-Type': 'application/json'}
Ejemplo n.º 4
0
    def test_query(self):
        query = quiz.Query(DogQuery, _.dog[_.name.bark_volume])
        response = snug.Response(
            200,
            json.dumps({
                "data": {
                    "dog": {
                        "name": "Fred",
                        "bark_volume": 8
                    }
                }
            }).encode(),
        )
        client = MockClient(response)
        result = quiz.execute(query, url="https://my.url/api", client=client)
        assert result == DogQuery(dog=Dog(name="Fred", bark_volume=8))
        request = client.request

        assert result.__metadata__ == quiz.QueryMetadata(response=response,
                                                         request=request)
        assert request.url == "https://my.url/api"
        assert request.method == "POST"
        assert json.loads(request.content.decode()) == {
            "query": quiz.gql(query)
        }
        assert request.headers == {"Content-Type": "application/json"}
Ejemplo n.º 5
0
    def test_non_string(self, event_loop):
        query = quiz.Query(DogQuery, _.dog[_.name.bark_volume])
        client = MockAsyncClient(
            snug.Response(
                200,
                json.dumps({
                    "data": {
                        "dog": {
                            "name": "Fred",
                            "bark_volume": 8
                        }
                    }
                }).encode(),
            ))

        future = quiz.execute_async(query,
                                    url="https://my.url/api",
                                    client=client)
        result = event_loop.run_until_complete(future)
        assert result == DogQuery(dog=Dog(name="Fred", bark_volume=8))

        request = client.request
        assert request.url == "https://my.url/api"
        assert request.method == "POST"
        assert json.loads(request.content.decode()) == {
            "query": quiz.gql(query)
        }
        assert request.headers == {"Content-Type": "application/json"}
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_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.º 9
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.º 10
0
 def test_repr(self):
     instance = _.foo.bar(bla=3)
     rep = repr(instance)
     assert "SelectionSet" in rep
     assert gql(instance) in rep
Ejemplo n.º 11
0
 def test_alias(self):
     field = Field("foo", {"a": 4}, alias="my_alias")
     assert gql(field) == "my_alias: foo(a: 4)"
Ejemplo n.º 12
0
 def test_empty(self):
     assert gql(Field("foo")) == "foo"
Ejemplo n.º 13
0
 def test_gql(self):
     raw = quiz.Raw("my raw graphql")
     assert gql(raw) == "my raw graphql"
Ejemplo n.º 14
0
 def test_empty(self):
     assert gql(Field('foo')) == 'foo'
Ejemplo n.º 15
0
 def test_str(self):
     instance = _.foo.bar(bla=5)
     assert str(instance) == gql(instance)
Ejemplo n.º 16
0
 def test_gql(self):
     raw = quiz.Raw('my raw graphql')
     assert gql(raw) == 'my raw graphql'
Ejemplo n.º 17
0
 def test_alias(self):
     field = Field('foo', {
         'a': 4,
     }, alias='my_alias')
     assert gql(field) == 'my_alias: foo(a: 4)'