def test_should_query_well():
class ReporterType(PynamoObjectType):
class Meta:
model = Reporter
class Query(graphene.ObjectType):
reporter = graphene.Field(ReporterType)
reporters = graphene.List(ReporterType)
def resolve_reporter(self, *args, **kwargs):
return Reporter.get(1)
def resolve_reporters(self, *args, **kwargs):
return list(Reporter.scan())
query = '''
query ReporterQuery {
reporter {
firstName,
lastName,
email,
customMap,
awards
}
reporters {
firstName
}
}
'''
expected = {
'reporter': {
'email': None,
'firstName': 'ABA',
'lastName': 'X',
'customMap': {"key1": "value1", "key2": "value2"},
'awards': ['pulizer']
},
'reporters': [{
'firstName': 'ABO',
}, {
'firstName': 'ABA',
}]
}
schema = graphene.Schema(query=Query)
result = schema.execute(query)
assert not result.errors
result.data['reporter']["customMap"] = json.loads(result.data['reporter']["customMap"])
assert dict(result.data['reporter']) == expected['reporter']
assert all(item in result.data['reporters'] for item in expected['reporters'])
评论列表
文章目录