File: test_1394.py

package info (click to toggle)
python-graphene 3.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 8,935; makefile: 214; sh: 18
file content (36 lines) | stat: -rw-r--r-- 947 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from ...types import ObjectType, Schema, String, NonNull


class Query(ObjectType):
    hello = String(input=NonNull(String))

    def resolve_hello(self, info, input):
        if input == "nothing":
            return None
        return f"Hello {input}!"


schema = Schema(query=Query)


def test_required_input_provided():
    """
    Test that a required argument works when provided.
    """
    input_value = "Potato"
    result = schema.execute('{ hello(input: "%s") }' % input_value)
    assert not result.errors
    assert result.data == {"hello": "Hello Potato!"}


def test_required_input_missing():
    """
    Test that a required argument raised an error if not provided.
    """
    result = schema.execute("{ hello }")
    assert result.errors
    assert len(result.errors) == 1
    assert (
        result.errors[0].message
        == "Field 'hello' argument 'input' of type 'String!' is required, but it was not provided."
    )