Beispiel #1
0
 def test_resolve_recipe_by_id(self, gql_client):
     r = RecipeFactory()
     res = gql_client.execute(GQ().query.recipe(id=r.id).fields(
         GQ().latestRevision.fields("id")))
     assert res == {
         "data": {
             "recipe": {
                 "latestRevision": {
                     "id": str(r.latest_revision.id)
                 }
             }
         }
     }
Beispiel #2
0
 def test_resolve_approval_request_by_id(self, gql_client):
     a = ApprovalRequestFactory()
     res = gql_client.execute(GQ().query.approvalRequest(id=a.id).fields(
         GQ().revision.fields("id")))
     assert res == {
         "data": {
             "approvalRequest": {
                 "revision": {
                     "id": str(a.revision.id)
                 }
             }
         }
     }
Beispiel #3
0
 def test_resolve_all_recipe_revisions(self, gql_client):
     r = RecipeFactory()
     res = gql_client.execute(GQ().query.allRecipeRevisions.fields("id"))
     assert res == {
         "data": {
             "allRecipeRevisions": [{
                 "id": str(r.latest_revision.id)
             }]
         }
     }
Beispiel #4
0
 def test_password_not_queryable(self, gql_client):
     u = UserFactory()
     res = gql_client.execute(GQ().query.user(id=u.id).fields("password"))
     assert res == {
         "errors": [{
             "locations":
             Whatever(),
             "message":
             'Cannot query field "password" on type "UserType".',
         }]
     }
Beispiel #5
0
 def test_resolve_user_by_id(self, gql_client):
     u = UserFactory()
     res = gql_client.execute(GQ().query.user(id=u.id).fields("username"))
     assert res == {"data": {"user": {"username": u.username}}}
Beispiel #6
0
 def test_resolve_all_users(self, gql_client):
     u = UserFactory()
     res = gql_client.execute(GQ().query.allUsers.fields("id"))
     assert res == {"data": {"allUsers": [{"id": str(u.id)}]}}
Beispiel #7
0
 def test_nested_object_in_fields(self):
     assert (GQ().query.users.fields("id",
                                     GQ("group").fields("id"))
             ) == "query { users { id, group { id } } }"
Beispiel #8
0
 def test_compose(self):
     assert str(GQ().query) == "query"
     assert (str(GQ().query.user(id=1).fields(
         "id", "name")) == "query { user(id: 1) { id, name } }")
Beispiel #9
0
 def test_resolve_action_by_name(self, gql_client):
     a = ActionFactory()
     res = gql_client.execute(GQ().query.action(name=a.name).fields("id"))
     assert res == {"data": {"action": {"id": str(a.id)}}}
Beispiel #10
0
 def test_resolve_group_by_name(self, gql_client):
     g = GroupFactory()
     res = gql_client.execute(GQ().query.group(name=g.name).fields("id"))
     assert res == {"data": {"group": {"id": str(g.id)}}}
Beispiel #11
0
 def test_resolve_all_groups(self, gql_client):
     g = GroupFactory()
     res = gql_client.execute(GQ().query.allGroups.fields("id"))
     assert res == {"data": {"allGroups": [{"id": str(g.id)}]}}
Beispiel #12
0
 def test_resolve_all_extensions(self, gql_client, storage):
     e = ExtensionFactory()
     res = gql_client.execute(GQ().query.allExtensions.fields("id"))
     assert res == {"data": {"allExtensions": [{"id": str(e.id)}]}}
Beispiel #13
0
 def test_resolve_extension_by_id(self, gql_client, storage):
     e = ExtensionFactory()
     res = gql_client.execute(GQ().query.extension(id=e.id).fields("name"))
     assert res == {"data": {"extension": {"name": e.name}}}
Beispiel #14
0
 def test_resolve_all_action(self, gql_client):
     a = ActionFactory()
     res = gql_client.execute(GQ().query.allActions.fields("id"))
     assert res == {"data": {"allActions": [{"id": str(a.id)}]}}
Beispiel #15
0
 def test_resolve_all_approval_requests(self, gql_client):
     a = ApprovalRequestFactory()
     res = gql_client.execute(GQ().query.allApprovalRequests.fields("id"))
     assert res == {"data": {"allApprovalRequests": [{"id": str(a.id)}]}}
Beispiel #16
0
 def test_basic_query(self, client):
     u = UserFactory()
     query = GQ().query.allUsers.fields("id")
     res = client.get(f"/api/graphql/?query={query}")
     assert res.json() == {"data": {"allUsers": [{"id": str(u.id)}]}}
Beispiel #17
0
 def test_resolve_user_by_email(self, gql_client):
     u = UserFactory()
     res = gql_client.execute(GQ().query.user(email=u.email).fields("id"))
     assert res == {"data": {"user": {"id": str(u.id)}}}
Beispiel #18
0
 def test_get_includes_cache_headers(self, api_client):
     query = GQ().query.allUsers.fields("id")
     res = api_client.get(f"/api/graphql/?query={query}")
     assert res.status_code == 200
     assert "max-age=" in res["Cache-Control"]
     assert "public" in res["Cache-Control"]
Beispiel #19
0
 def test_resolve_group_by_id(self, gql_client):
     g = GroupFactory()
     res = gql_client.execute(GQ().query.group(id=g.id).fields("name"))
     assert res == {"data": {"group": {"name": g.name}}}
Beispiel #20
0
 def test_post_explicit_no_cache(self, api_client):
     query = GQ().query.allUsers.fields("id")
     res = api_client.post(f"/api/graphql/?query={query}")
     assert res.status_code == 200
     assert "no-cache" in res["Cache-Control"]
Beispiel #21
0
 def test_simple_build(self):
     assert str(GQ("query")) == "query"
     assert str(GQ("query", attrs={"id": 1})) == "query(id: 1)"
Beispiel #22
0
 def test_resolve_action_by_id(self, gql_client):
     a = ActionFactory()
     res = gql_client.execute(GQ().query.action(id=a.id).fields("name"))
     assert res == {"data": {"action": {"name": a.name}}}