File: test_1419.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 (53 lines) | stat: -rw-r--r-- 1,585 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pytest

from ...types.base64 import Base64
from ...types.datetime import Date, DateTime
from ...types.decimal import Decimal
from ...types.generic import GenericScalar
from ...types.json import JSONString
from ...types.objecttype import ObjectType
from ...types.scalars import ID, BigInt, Boolean, Float, Int, String
from ...types.schema import Schema
from ...types.uuid import UUID


@pytest.mark.parametrize(
    "input_type,input_value",
    [
        (Date, '"2022-02-02"'),
        (GenericScalar, '"foo"'),
        (Int, "1"),
        (BigInt, "12345678901234567890"),
        (Float, "1.1"),
        (String, '"foo"'),
        (Boolean, "true"),
        (ID, "1"),
        (DateTime, '"2022-02-02T11:11:11"'),
        (UUID, '"cbebbc62-758e-4f75-a890-bc73b5017d81"'),
        (Decimal, '"1.1"'),
        (JSONString, '"{\\"key\\":\\"foo\\",\\"value\\":\\"bar\\"}"'),
        (Base64, '"Q2hlbG8gd29ycmxkCg=="'),
    ],
)
def test_parse_literal_with_variables(input_type, input_value):
    # input_b needs to be evaluated as literal while the variable dict for
    # input_a is passed along.

    class Query(ObjectType):
        generic = GenericScalar(input_a=GenericScalar(), input_b=input_type())

        def resolve_generic(self, info, input_a=None, input_b=None):
            return input

    schema = Schema(query=Query)

    query = f"""
        query Test($a: GenericScalar){{
            generic(inputA: $a, inputB: {input_value})
        }}
    """
    result = schema.execute(
        query,
        variables={"a": "bar"},
    )
    assert not result.errors