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) } } } }
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) } } } }
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) }] } }
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".', }] }
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}}}
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)}]}}
def test_nested_object_in_fields(self): assert (GQ().query.users.fields("id", GQ("group").fields("id")) ) == "query { users { id, group { id } } }"
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 } }")
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)}}}
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)}}}
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)}]}}
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)}]}}
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}}}
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)}]}}
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)}]}}
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)}]}}
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)}}}
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"]
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}}}
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"]
def test_simple_build(self): assert str(GQ("query")) == "query" assert str(GQ("query", attrs={"id": 1})) == "query(id: 1)"
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}}}