mirror of
https://github.com/graphql-python/graphene.git
synced 2025-09-21 11:22:33 +03:00
Make use of the fact that dicts are iterable
This commit is contained in:
parent
5752b48a0b
commit
df0657b816
|
@ -24,7 +24,7 @@ def test_connection():
|
|||
|
||||
assert MyObjectConnection._meta.name == "MyObjectConnection"
|
||||
fields = MyObjectConnection._meta.fields
|
||||
assert list(fields.keys()) == ["page_info", "edges", "extra"]
|
||||
assert list(fields) == ["page_info", "edges", "extra"]
|
||||
edge_field = fields["edges"]
|
||||
pageinfo_field = fields["page_info"]
|
||||
|
||||
|
@ -48,7 +48,7 @@ def test_connection_inherit_abstracttype():
|
|||
|
||||
assert MyObjectConnection._meta.name == "MyObjectConnection"
|
||||
fields = MyObjectConnection._meta.fields
|
||||
assert list(fields.keys()) == ["page_info", "edges", "extra"]
|
||||
assert list(fields) == ["page_info", "edges", "extra"]
|
||||
|
||||
|
||||
def test_connection_name():
|
||||
|
@ -76,7 +76,7 @@ def test_edge():
|
|||
Edge = MyObjectConnection.Edge
|
||||
assert Edge._meta.name == "MyObjectEdge"
|
||||
edge_fields = Edge._meta.fields
|
||||
assert list(edge_fields.keys()) == ["node", "cursor", "other"]
|
||||
assert list(edge_fields) == ["node", "cursor", "other"]
|
||||
|
||||
assert isinstance(edge_fields["node"], Field)
|
||||
assert edge_fields["node"].type == MyObject
|
||||
|
@ -99,7 +99,7 @@ def test_edge_with_bases():
|
|||
Edge = MyObjectConnection.Edge
|
||||
assert Edge._meta.name == "MyObjectEdge"
|
||||
edge_fields = Edge._meta.fields
|
||||
assert list(edge_fields.keys()) == ["node", "cursor", "extra", "other"]
|
||||
assert list(edge_fields) == ["node", "cursor", "extra", "other"]
|
||||
|
||||
assert isinstance(edge_fields["node"], Field)
|
||||
assert edge_fields["node"].type == MyObject
|
||||
|
@ -122,7 +122,7 @@ def test_edge_with_nonnull_node():
|
|||
def test_pageinfo():
|
||||
assert PageInfo._meta.name == "PageInfo"
|
||||
fields = PageInfo._meta.fields
|
||||
assert list(fields.keys()) == [
|
||||
assert list(fields) == [
|
||||
"has_next_page",
|
||||
"has_previous_page",
|
||||
"start_cursor",
|
||||
|
|
|
@ -117,12 +117,12 @@ def test_no_mutate_and_get_payload():
|
|||
|
||||
def test_mutation():
|
||||
fields = SaySomething._meta.fields
|
||||
assert list(fields.keys()) == ["phrase", "client_mutation_id"]
|
||||
assert list(fields) == ["phrase", "client_mutation_id"]
|
||||
assert SaySomething._meta.name == "SaySomethingPayload"
|
||||
assert isinstance(fields["phrase"], Field)
|
||||
field = SaySomething.Field()
|
||||
assert field.type == SaySomething
|
||||
assert list(field.args.keys()) == ["input"]
|
||||
assert list(field.args) == ["input"]
|
||||
assert isinstance(field.args["input"], Argument)
|
||||
assert isinstance(field.args["input"].type, NonNull)
|
||||
assert field.args["input"].type.of_type == SaySomething.Input
|
||||
|
@ -135,7 +135,7 @@ def test_mutation_input():
|
|||
Input = SaySomething.Input
|
||||
assert issubclass(Input, InputObjectType)
|
||||
fields = Input._meta.fields
|
||||
assert list(fields.keys()) == ["what", "client_mutation_id"]
|
||||
assert list(fields) == ["what", "client_mutation_id"]
|
||||
assert isinstance(fields["what"], InputField)
|
||||
assert fields["what"].type == String
|
||||
assert isinstance(fields["client_mutation_id"], InputField)
|
||||
|
@ -144,11 +144,11 @@ def test_mutation_input():
|
|||
|
||||
def test_subclassed_mutation():
|
||||
fields = OtherMutation._meta.fields
|
||||
assert list(fields.keys()) == ["name", "my_node_edge", "client_mutation_id"]
|
||||
assert list(fields) == ["name", "my_node_edge", "client_mutation_id"]
|
||||
assert isinstance(fields["name"], Field)
|
||||
field = OtherMutation.Field()
|
||||
assert field.type == OtherMutation
|
||||
assert list(field.args.keys()) == ["input"]
|
||||
assert list(field.args) == ["input"]
|
||||
assert isinstance(field.args["input"], Argument)
|
||||
assert isinstance(field.args["input"].type, NonNull)
|
||||
assert field.args["input"].type.of_type == OtherMutation.Input
|
||||
|
@ -158,7 +158,7 @@ def test_subclassed_mutation_input():
|
|||
Input = OtherMutation.Input
|
||||
assert issubclass(Input, InputObjectType)
|
||||
fields = Input._meta.fields
|
||||
assert list(fields.keys()) == ["shared", "additional_field", "client_mutation_id"]
|
||||
assert list(fields) == ["shared", "additional_field", "client_mutation_id"]
|
||||
assert isinstance(fields["shared"], InputField)
|
||||
assert fields["shared"].type == String
|
||||
assert isinstance(fields["additional_field"], InputField)
|
||||
|
|
|
@ -20,7 +20,7 @@ class InputObjectTypeContainer(dict, BaseType):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
dict.__init__(self, *args, **kwargs)
|
||||
for key in self._meta.fields.keys():
|
||||
for key in self._meta.fields:
|
||||
setattr(self, key, self.get(key, None))
|
||||
|
||||
def __init_subclass__(cls, *args, **kwargs):
|
||||
|
|
|
@ -33,5 +33,5 @@ def test_generate_objecttype_inherit_abstracttype():
|
|||
assert MyObjectType._meta.description is None
|
||||
assert MyObjectType._meta.interfaces == ()
|
||||
assert MyObjectType._meta.name == "MyObjectType"
|
||||
assert list(MyObjectType._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyObjectType._meta.fields) == ["field1", "field2"]
|
||||
assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]
|
||||
|
|
|
@ -122,7 +122,7 @@ def test_field_name_as_argument():
|
|||
def test_field_source_argument_as_kw():
|
||||
MyType = object()
|
||||
field = Field(MyType, b=NonNull(True), c=Argument(None), a=NonNull(False))
|
||||
assert list(field.args.keys()) == ["b", "c", "a"]
|
||||
assert list(field.args) == ["b", "c", "a"]
|
||||
assert isinstance(field.args["b"], Argument)
|
||||
assert isinstance(field.args["b"].type, NonNull)
|
||||
assert field.args["b"].type.of_type is True
|
||||
|
|
|
@ -50,7 +50,7 @@ def test_ordered_fields_in_inputobjecttype():
|
|||
field = MyScalar()
|
||||
asa = InputField(MyType)
|
||||
|
||||
assert list(MyInputObjectType._meta.fields.keys()) == ["b", "a", "field", "asa"]
|
||||
assert list(MyInputObjectType._meta.fields) == ["b", "a", "field", "asa"]
|
||||
|
||||
|
||||
def test_generate_inputobjecttype_unmountedtype():
|
||||
|
@ -84,7 +84,7 @@ def test_generate_inputobjecttype_inherit_abstracttype():
|
|||
class MyInputObjectType(InputObjectType, MyAbstractType):
|
||||
field2 = MyScalar(MyType)
|
||||
|
||||
assert list(MyInputObjectType._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyInputObjectType._meta.fields) == ["field1", "field2"]
|
||||
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [
|
||||
InputField,
|
||||
InputField,
|
||||
|
@ -98,7 +98,7 @@ def test_generate_inputobjecttype_inherit_abstracttype_reversed():
|
|||
class MyInputObjectType(MyAbstractType, InputObjectType):
|
||||
field2 = MyScalar(MyType)
|
||||
|
||||
assert list(MyInputObjectType._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyInputObjectType._meta.fields) == ["field1", "field2"]
|
||||
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [
|
||||
InputField,
|
||||
InputField,
|
||||
|
|
|
@ -45,7 +45,7 @@ def test_ordered_fields_in_interface():
|
|||
field = MyScalar()
|
||||
asa = Field(MyType)
|
||||
|
||||
assert list(MyInterface._meta.fields.keys()) == ["b", "a", "field", "asa"]
|
||||
assert list(MyInterface._meta.fields) == ["b", "a", "field", "asa"]
|
||||
|
||||
|
||||
def test_generate_interface_unmountedtype():
|
||||
|
@ -63,7 +63,7 @@ def test_generate_interface_inherit_abstracttype():
|
|||
class MyInterface(Interface, MyAbstractType):
|
||||
field2 = MyScalar()
|
||||
|
||||
assert list(MyInterface._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyInterface._meta.fields) == ["field1", "field2"]
|
||||
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]
|
||||
|
||||
|
||||
|
@ -75,7 +75,7 @@ def test_generate_interface_inherit_interface():
|
|||
field2 = MyScalar()
|
||||
|
||||
assert MyInterface._meta.name == "MyInterface"
|
||||
assert list(MyInterface._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyInterface._meta.fields) == ["field1", "field2"]
|
||||
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]
|
||||
|
||||
|
||||
|
@ -86,5 +86,5 @@ def test_generate_interface_inherit_abstracttype_reversed():
|
|||
class MyInterface(MyAbstractType, Interface):
|
||||
field2 = MyScalar()
|
||||
|
||||
assert list(MyInterface._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyInterface._meta.fields) == ["field1", "field2"]
|
||||
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]
|
||||
|
|
|
@ -102,7 +102,7 @@ def test_ordered_fields_in_objecttype():
|
|||
field = MyScalar()
|
||||
asa = Field(MyType)
|
||||
|
||||
assert list(MyObjectType._meta.fields.keys()) == ["b", "a", "field", "asa"]
|
||||
assert list(MyObjectType._meta.fields) == ["b", "a", "field", "asa"]
|
||||
|
||||
|
||||
def test_generate_objecttype_inherit_abstracttype():
|
||||
|
@ -115,7 +115,7 @@ def test_generate_objecttype_inherit_abstracttype():
|
|||
assert MyObjectType._meta.description is None
|
||||
assert MyObjectType._meta.interfaces == ()
|
||||
assert MyObjectType._meta.name == "MyObjectType"
|
||||
assert list(MyObjectType._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyObjectType._meta.fields) == ["field1", "field2"]
|
||||
assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]
|
||||
|
||||
|
||||
|
@ -129,7 +129,7 @@ def test_generate_objecttype_inherit_abstracttype_reversed():
|
|||
assert MyObjectType._meta.description is None
|
||||
assert MyObjectType._meta.interfaces == ()
|
||||
assert MyObjectType._meta.name == "MyObjectType"
|
||||
assert list(MyObjectType._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(MyObjectType._meta.fields) == ["field1", "field2"]
|
||||
assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]
|
||||
|
||||
|
||||
|
@ -142,11 +142,11 @@ def test_generate_objecttype_unmountedtype():
|
|||
|
||||
|
||||
def test_parent_container_get_fields():
|
||||
assert list(Container._meta.fields.keys()) == ["field1", "field2"]
|
||||
assert list(Container._meta.fields) == ["field1", "field2"]
|
||||
|
||||
|
||||
def test_parent_container_interface_get_fields():
|
||||
assert list(ContainerWithInterface._meta.fields.keys()) == [
|
||||
assert list(ContainerWithInterface._meta.fields) == [
|
||||
"ifield",
|
||||
"field1",
|
||||
"field2",
|
||||
|
|
|
@ -80,7 +80,7 @@ def test_objecttype():
|
|||
assert graphql_type.description == "Description"
|
||||
|
||||
fields = graphql_type.fields
|
||||
assert list(fields.keys()) == ["foo", "gizmo"]
|
||||
assert list(fields) == ["foo", "gizmo"]
|
||||
foo_field = fields["foo"]
|
||||
assert isinstance(foo_field, GraphQLField)
|
||||
assert foo_field.description == "Field description"
|
||||
|
@ -104,11 +104,11 @@ def test_dynamic_objecttype():
|
|||
|
||||
type_map = create_type_map([MyObjectType])
|
||||
assert "MyObjectType" in type_map
|
||||
assert list(MyObjectType._meta.fields.keys()) == ["bar", "own"]
|
||||
assert list(MyObjectType._meta.fields) == ["bar", "own"]
|
||||
graphql_type = type_map["MyObjectType"]
|
||||
|
||||
fields = graphql_type.fields
|
||||
assert list(fields.keys()) == ["bar", "own"]
|
||||
assert list(fields) == ["bar", "own"]
|
||||
assert fields["bar"].type == GraphQLString
|
||||
assert fields["own"].type == graphql_type
|
||||
|
||||
|
@ -135,9 +135,9 @@ def test_interface():
|
|||
assert graphql_type.description == "Description"
|
||||
|
||||
fields = graphql_type.fields
|
||||
assert list(fields.keys()) == ["foo", "gizmo", "own"]
|
||||
assert list(fields) == ["foo", "gizmo", "own"]
|
||||
assert fields["own"].type == graphql_type
|
||||
assert list(fields["gizmo"].args.keys()) == ["firstArg", "oth_arg"]
|
||||
assert list(fields["gizmo"].args) == ["firstArg", "oth_arg"]
|
||||
foo_field = fields["foo"]
|
||||
assert isinstance(foo_field, GraphQLField)
|
||||
assert foo_field.description == "Field description"
|
||||
|
@ -203,7 +203,7 @@ def test_inputobject():
|
|||
assert container.baz.some_other_field[1].thingy == 2
|
||||
|
||||
fields = graphql_type.fields
|
||||
assert list(fields.keys()) == ["fooBar", "gizmo", "baz", "own"]
|
||||
assert list(fields) == ["fooBar", "gizmo", "baz", "own"]
|
||||
own_field = fields["own"]
|
||||
assert own_field.type == graphql_type
|
||||
foo_field = fields["fooBar"]
|
||||
|
@ -225,7 +225,7 @@ def test_objecttype_camelcase():
|
|||
assert graphql_type.description == "Description"
|
||||
|
||||
fields = graphql_type.fields
|
||||
assert list(fields.keys()) == ["fooBar"]
|
||||
assert list(fields) == ["fooBar"]
|
||||
foo_field = fields["fooBar"]
|
||||
assert isinstance(foo_field, GraphQLField)
|
||||
assert foo_field.args == {
|
||||
|
@ -251,7 +251,7 @@ def test_objecttype_camelcase_disabled():
|
|||
assert graphql_type.description == "Description"
|
||||
|
||||
fields = graphql_type.fields
|
||||
assert list(fields.keys()) == ["foo_bar"]
|
||||
assert list(fields) == ["foo_bar"]
|
||||
foo_field = fields["foo_bar"]
|
||||
assert isinstance(foo_field, GraphQLField)
|
||||
assert foo_field.args == {
|
||||
|
|
|
@ -43,7 +43,7 @@ class SubclassWithMeta(metaclass=SubclassWithMeta_Meta):
|
|||
assert not options, (
|
||||
"Abstract types can only contain the abstract attribute. "
|
||||
"Received: abstract, {option_keys}"
|
||||
).format(option_keys=", ".join(options.keys()))
|
||||
).format(option_keys=", ".join(options))
|
||||
else:
|
||||
super_class = super(cls, cls)
|
||||
if hasattr(super_class, "__init_subclass_with_meta__"):
|
||||
|
|
Loading…
Reference in New Issue
Block a user