Skip to content
Snippets Groups Projects
Verified Commit c6e040a8 authored by Mark's avatar Mark
Browse files

Add getUser API test

parent f6b5de82
No related branches found
No related tags found
No related merge requests found
...@@ -42,9 +42,9 @@ class Role(SQLAlchemyObjectType): ...@@ -42,9 +42,9 @@ class Role(SQLAlchemyObjectType):
class Query(graphene.ObjectType): class Query(graphene.ObjectType):
node = relay.Node.Field() node = relay.Node.Field()
all_users = SQLAlchemyConnectionField(User) all_users = SQLAlchemyConnectionField(User)
find_user = graphene.Field(User,username=graphene.String()) get_user = graphene.Field(User,username=graphene.String())
def resolve_find_user(root, info, username): def resolve_get_user(root, info, username):
query = User.get_query(info) query = User.get_query(info)
return query.filter(UserModel.username == username).first() return query.filter(UserModel.username == username).first()
......
...@@ -21,7 +21,7 @@ class GraphQlTests(LiveServerTestCase): ...@@ -21,7 +21,7 @@ class GraphQlTests(LiveServerTestCase):
users = User.query.filter_by(username="graphqluser").delete() users = User.query.filter_by(username="graphqluser").delete()
db_session.commit() db_session.commit()
def test_query_create_user(self): def test_query_create_and_get_user(self):
username = "graphqluser" username = "graphqluser"
password = "randompassword" password = "randompassword"
email = "user@example.com" email = "user@example.com"
...@@ -43,3 +43,17 @@ class GraphQlTests(LiveServerTestCase): ...@@ -43,3 +43,17 @@ class GraphQlTests(LiveServerTestCase):
user = result["data"]["createUser"]["user"] user = result["data"]["createUser"]["user"]
self.assertEqual(user["username"], username) self.assertEqual(user["username"], username)
self.assertEqual(user["email"], email) self.assertEqual(user["email"], email)
querystring = '''
{{
getUser(username: "{0}"){{
username,
email
}}
}}
'''.format(username).strip()
result = loads(self.client.execute(querystring))
self.assertIn("data", result)
self.assertIn("getUser", result["data"])
user = result["data"]["getUser"]
self.assertEqual(user["username"], username)
self.assertEqual(user["email"], email)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment