def test_custom_scalar(self): class MyCustomScalar(quiz.Scalar): """a custom scalar string""" def __init__(self, value): self.value = value def __gql_dump__(self): return self.value.upper() assert quiz.argument_as_gql(MyCustomScalar("Hello")) == "HELLO"
def test_float(self, value, expect): assert quiz.argument_as_gql(value) == expect
def test_enum(self): class MyEnum(quiz.Enum): FOO = "FOOVALUE" BLA = "QUX" assert quiz.argument_as_gql(MyEnum.BLA) == "QUX"
def test_none(self): assert quiz.argument_as_gql(None) == "null"
def test_bool(self): assert quiz.argument_as_gql(True) == "true" assert quiz.argument_as_gql(False) == "false"
def test_int(self): assert quiz.argument_as_gql(4) == "4"
def test_invalid(self): class MyClass(object): pass with pytest.raises(TypeError, match="MyClass"): quiz.argument_as_gql(MyClass())
def test_string(self): assert quiz.argument_as_gql('foo\nb"ar') == '"foo\\nb\\"ar"'
def test_enum(self): class MyEnum(quiz.Enum): FOO = 'FOOVALUE' BLA = 'QUX' assert quiz.argument_as_gql(MyEnum.BLA) == 'QUX'
def test_bool(self): assert quiz.argument_as_gql(True) == 'true' assert quiz.argument_as_gql(False) == 'false'