fix: unit tests

This commit is contained in:
Cameron Hurst 2021-03-01 08:51:32 -05:00
parent acbd262507
commit 322f37196d
3 changed files with 18 additions and 50 deletions

View File

@ -8,9 +8,7 @@ from snapshottest import Snapshot
snapshots = Snapshot() snapshots = Snapshot()
snapshots["test_correctly_fetches_id_name_rebels 1"] = { snapshots["test_correctly_fetches_id_name_rebels 1"] = {
"data": { "data": {"rebels": {"id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic"}}
"rebels": {"id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic"}
}
} }
snapshots["test_correctly_refetches_rebels 1"] = { snapshots["test_correctly_refetches_rebels 1"] = {
@ -21,13 +19,9 @@ snapshots["test_correctly_fetches_id_name_empire 1"] = {
"data": {"empire": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}} "data": {"empire": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}}
} }
snapshots["test_correctly_refetches_empire 1"] = { snapshots["test_correctly_refetches_empire 1"] = {"data": {"node": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}}}
"data": {"node": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}}
}
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" "test_str_schema 1"
@ -49,7 +43,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

@ -128,9 +128,7 @@ def test_query_interface():
executed = hello_schema.execute("{ interfaces { __typename } }") executed = hello_schema.execute("{ interfaces { __typename } }")
assert not executed.errors assert not executed.errors
assert executed.data == { assert executed.data == {"interfaces": [{"__typename": "One"}, {"__typename": "Two"}]}
"interfaces": [{"__typename": "One"}, {"__typename": "Two"}]
}
def test_query_dynamic(): def test_query_dynamic():
@ -179,10 +177,7 @@ def test_query_wrong_default_value():
executed = hello_schema.execute("{ hello { field } }") executed = hello_schema.execute("{ hello { field } }")
assert len(executed.errors) == 1 assert len(executed.errors) == 1
assert ( assert executed.errors[0].message == GraphQLError("Expected value of type 'MyType' but got: 'hello'.").message
executed.errors[0].message
== GraphQLError("Expected value of type 'MyType' but got: 'hello'.").message
)
assert executed.data == {"hello": None} assert executed.data == {"hello": None}
@ -229,11 +224,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
@ -258,19 +253,15 @@ 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
assert result.data == {"test": '["Source!",{"a_input":{"a_field":"String!"}}]'} assert result.data == {"test": '["Source!",{"a_input":{"a_field":"String!"}}]'}
result = test_schema.execute( result = test_schema.execute('{ test(aInput: {recursiveField: {aField: "String!"}}) }', "Source!")
'{ test(aInput: {recursiveField: {aField: "String!"}}) }', "Source!"
)
assert not result.errors assert not result.errors
assert result.data == { assert result.data == {"test": '["Source!",{"a_input":{"recursive_field":{"a_field":"String!"}}}]'}
"test": '["Source!",{"a_input":{"recursive_field":{"a_field":"String!"}}}]'
}
def test_query_middlewares(): def test_query_middlewares():
@ -289,9 +280,7 @@ def test_query_middlewares():
hello_schema = Schema(Query) hello_schema = Schema(Query)
executed = hello_schema.execute( executed = hello_schema.execute("{ hello, other }", middleware=[reversed_middleware])
"{ hello, other }", middleware=[reversed_middleware]
)
assert not executed.errors assert not executed.errors
assert executed.data == {"hello": "dlroW", "other": "rehto"} assert executed.data == {"hello": "dlroW", "other": "rehto"}
@ -397,11 +386,7 @@ def test_big_list_of_containers_multiple_fields_query_benchmark(benchmark):
big_list_query = partial(hello_schema.execute, "{ allContainers { x, y, z, o } }") big_list_query = partial(hello_schema.execute, "{ allContainers { x, y, z, o } }")
result = benchmark(big_list_query) result = benchmark(big_list_query)
assert not result.errors assert not result.errors
assert result.data == { assert result.data == {"allContainers": [{"x": c.x, "y": c.y, "z": c.z, "o": c.o} for c in big_container_list]}
"allContainers": [
{"x": c.x, "y": c.y, "z": c.z, "o": c.o} for c in big_container_list
]
}
def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark( def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark(
@ -438,11 +423,7 @@ def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark
big_list_query = partial(hello_schema.execute, "{ allContainers { x, y, z, o } }") big_list_query = partial(hello_schema.execute, "{ allContainers { x, y, z, o } }")
result = benchmark(big_list_query) result = benchmark(big_list_query)
assert not result.errors assert not result.errors
assert result.data == { assert result.data == {"allContainers": [{"x": c.x, "y": c.y, "z": c.z, "o": c.o} for c in big_container_list]}
"allContainers": [
{"x": c.x, "y": c.y, "z": c.z, "o": c.o} for c in big_container_list
]
}
def test_query_annotated_resolvers(): def test_query_annotated_resolvers():

View File

@ -1,3 +1,4 @@
from graphql import Undefined
from graphql.type import ( from graphql.type import (
GraphQLArgument, GraphQLArgument,
GraphQLEnumType, GraphQLEnumType,
@ -51,9 +52,7 @@ def test_enum():
assert graphql_enum.name == "MyEnum" assert graphql_enum.name == "MyEnum"
assert graphql_enum.description == "Description" assert graphql_enum.description == "Description"
assert graphql_enum.values == { assert graphql_enum.values == {
"foo": GraphQLEnumValue( "foo": GraphQLEnumValue(value=1, description="Description foo=1", deprecation_reason="Is deprecated"),
value=1, description="Description foo=1", deprecation_reason="Is deprecated"
),
"bar": GraphQLEnumValue(value=2, description="Description bar=2"), "bar": GraphQLEnumValue(value=2, description="Description bar=2"),
} }
@ -227,9 +226,7 @@ def test_objecttype_camelcase():
assert list(fields) == ["fooBar"] assert list(fields) == ["fooBar"]
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=Undefined, out_name="bar_foo")}
"barFoo": GraphQLArgument(GraphQLString, default_value=None, out_name="bar_foo")
}
def test_objecttype_camelcase_disabled(): def test_objecttype_camelcase_disabled():
@ -249,11 +246,7 @@ def test_objecttype_camelcase_disabled():
assert list(fields) == ["foo_bar"] assert list(fields) == ["foo_bar"]
foo_field = fields["foo_bar"] foo_field = fields["foo_bar"]
assert isinstance(foo_field, GraphQLField) assert isinstance(foo_field, GraphQLField)
assert foo_field.args == { assert foo_field.args == {"bar_foo": GraphQLArgument(GraphQLString, default_value=Undefined, out_name="bar_foo")}
"bar_foo": GraphQLArgument(
GraphQLString, default_value=None, out_name="bar_foo"
)
}
def test_objecttype_with_possible_types(): def test_objecttype_with_possible_types():