Fixed tests

This commit is contained in:
Stefano Tabacco 2022-01-06 16:33:17 +11:00
parent 7ecb4e68ba
commit c0a9942248
4 changed files with 44 additions and 21 deletions

View File

@ -7,31 +7,52 @@ from snapshottest import Snapshot
snapshots = Snapshot() snapshots = Snapshot()
snapshots["test_correctly_fetches_id_name_rebels 1"] = { snapshots['test_correctly_fetches_id_name_empire 1'] = {
"data": { 'data': {
"rebels": {"id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic"} 'empire': {
'id': 'RmFjdGlvbjoy',
'name': 'Galactic Empire'
}
} }
} }
snapshots["test_correctly_refetches_rebels 1"] = { snapshots['test_correctly_fetches_id_name_rebels 1'] = {
"data": {"node": {"id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic"}} 'data': {
'rebels': {
'id': 'RmFjdGlvbjox',
'name': 'Alliance to Restore the Republic'
}
}
} }
snapshots["test_correctly_fetches_id_name_empire 1"] = { snapshots['test_correctly_refetches_empire 1'] = {
"data": {"empire": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}} 'data': {
'node': {
'id': 'RmFjdGlvbjoy',
'name': 'Galactic Empire'
}
}
} }
snapshots["test_correctly_refetches_empire 1"] = { snapshots['test_correctly_refetches_rebels 1'] = {
"data": {"node": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}} 'data': {
'node': {
'id': 'RmFjdGlvbjox',
'name': 'Alliance to Restore the Republic'
}
}
} }
snapshots["test_correctly_refetches_xwing 1"] = { snapshots['test_correctly_refetches_xwing 1'] = {
"data": {"node": {"id": "U2hpcDox", "name": "X-Wing"}} 'data': {
'node': {
'id': 'U2hpcDox',
'name': 'X-Wing'
}
}
} }
snapshots[ snapshots['test_str_schema 1'] = '''type Query {
"test_str_schema 1"
] = '''type Query {
rebels: Faction rebels: Faction
empire: Faction empire: Faction
node( node(
@ -49,7 +70,7 @@ type Faction implements Node {
name: String name: String
"""The ships used by the faction.""" """The ships used by the faction."""
ships(before: String = null, after: String = null, first: Int = null, last: Int = null): ShipConnection ships(before: String, after: String, first: Int, last: Int): ShipConnection
} }
"""An object with an ID""" """An object with an ID"""

View File

@ -4,6 +4,7 @@ from .dynamic import Dynamic
from .mountedtype import MountedType from .mountedtype import MountedType
from .structures import NonNull from .structures import NonNull
from .utils import get_type from .utils import get_type
from graphql import Undefined
class Argument(MountedType): class Argument(MountedType):
@ -41,7 +42,7 @@ class Argument(MountedType):
def __init__( def __init__(
self, self,
type_, type_,
default_value=None, default_value=Undefined,
description=None, description=None,
name=None, name=None,
required=False, required=False,

View File

@ -229,11 +229,11 @@ def test_query_arguments():
result = test_schema.execute("{ test }", None) result = test_schema.execute("{ test }", None)
assert not result.errors assert not result.errors
assert result.data == {"test": '[null,{"a_str":null,"a_int":null}]'} assert result.data == {"test": "[null,{}]"}
result = test_schema.execute('{ test(aStr: "String!") }', "Source!") result = test_schema.execute('{ test(aStr: "String!") }', "Source!")
assert not result.errors assert not result.errors
assert result.data == {"test": '["Source!",{"a_str":"String!","a_int":null}]'} assert result.data == {"test": '["Source!",{"a_str":"String!"}]'}
result = test_schema.execute('{ test(aInt: -123, aStr: "String!") }', "Source!") result = test_schema.execute('{ test(aInt: -123, aStr: "String!") }', "Source!")
assert not result.errors assert not result.errors
@ -243,6 +243,7 @@ def test_query_arguments():
] ]
def test_query_input_field(): def test_query_input_field():
class Input(InputObjectType): class Input(InputObjectType):
a_field = String() a_field = String()
@ -258,7 +259,7 @@ def test_query_input_field():
result = test_schema.execute("{ test }", None) result = test_schema.execute("{ test }", None)
assert not result.errors assert not result.errors
assert result.data == {"test": '[null,{"a_input":null}]'} assert result.data == {"test": "[null,{}]"}
result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', "Source!") result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', "Source!")
assert not result.errors assert not result.errors

View File

@ -244,7 +244,7 @@ def test_objecttype_camelcase():
foo_field = fields["fooBar"] foo_field = fields["fooBar"]
assert isinstance(foo_field, GraphQLField) assert isinstance(foo_field, GraphQLField)
assert foo_field.args == { assert foo_field.args == {
"barFoo": GraphQLArgument(GraphQLString, default_value=None, out_name="bar_foo") "barFoo": GraphQLArgument(GraphQLString, out_name="bar_foo")
} }
@ -267,7 +267,7 @@ def test_objecttype_camelcase_disabled():
assert isinstance(foo_field, GraphQLField) assert isinstance(foo_field, GraphQLField)
assert foo_field.args == { assert foo_field.args == {
"bar_foo": GraphQLArgument( "bar_foo": GraphQLArgument(
GraphQLString, default_value=None, out_name="bar_foo" GraphQLString, out_name="bar_foo"
) )
} }