From 74aea485d4c437c663c52b5fd2194c49b0f1b3ca Mon Sep 17 00:00:00 2001 From: c8y3 <25362953+c8y3@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:54:57 +0100 Subject: [PATCH] [ADD] Started implementation of query cases, which should return the list of cases visible by the user --- source/app/blueprints/graphql/graphql_route.py | 12 +++++++++++- source/requirements.txt | 1 + tests/tests.py | 17 ++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/source/app/blueprints/graphql/graphql_route.py b/source/app/blueprints/graphql/graphql_route.py index 7bb01416d..c01eccc15 100644 --- a/source/app/blueprints/graphql/graphql_route.py +++ b/source/app/blueprints/graphql/graphql_route.py @@ -21,18 +21,28 @@ from flask_wtf import FlaskForm from flask import Blueprint from graphql_server.flask import GraphQLView -from graphene import ObjectType, String, Schema +from graphene import ObjectType, String, Schema, List +from graphene_sqlalchemy import SQLAlchemyObjectType +from app.models.cases import Cases from app.util import is_user_authenticated from app.util import response_error +class CaseObject(SQLAlchemyObjectType): + class Meta: + model = Cases + + class Query(ObjectType): """Query documentation""" hello = String(first_name=String(default_value='stranger'), description='Field documentation') goodbye = String() + # starting with the conversion of '/manage/cases/list' + cases = List(lambda: CaseObject, description='author documentation') + def resolve_hello(root, info, first_name): return f'Hello {first_name}!' diff --git a/source/requirements.txt b/source/requirements.txt index 83a15151c..772a01057 100644 --- a/source/requirements.txt +++ b/source/requirements.txt @@ -35,6 +35,7 @@ pyintelowl>=4.4.0 graphene==3.3 # unfortunately we are relying on a beta version here. I hope a definitive version gets released soon graphql-server[flask]==3.0.0b7 +graphene-sqlalchemy==3.0.0rc1 dependencies/docx_generator-0.8.0-py3-none-any.whl dependencies/iris_interface-1.2.0-py3-none-any.whl diff --git a/tests/tests.py b/tests/tests.py index 6ddf80bb8..dbb1049c2 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -57,6 +57,14 @@ def test_update_case_should_not_require_case_name_issue_358(self): response = self._subject.update_case(case_identifier, {'case_tags': 'test,example'}) self.assertEqual('success', response['status']) + def test_graphql_endpoint_should_reject_requests_with_wrong_authentication_token(self): + graphql_api = GraphQLApi(API_URL + '/graphql', 64*'0') + payload = { + 'query': '{ hello(firstName: "friendly") }' + } + response = graphql_api.execute(payload) + self.assertEqual(401, response.status_code) + def test_graphql_endpoint_should_not_fail(self): payload = { 'query': '{ hello(firstName: "Paul") }' @@ -64,10 +72,9 @@ def test_graphql_endpoint_should_not_fail(self): body = self._subject.execute_graphql_query(payload) self.assertEqual('Hello Paul!', body['data']['hello']) - def test_graphql_endpoint_should_reject_requests_with_wrong_authentication_token(self): - graphql_api = GraphQLApi(API_URL + '/graphql', 64*'0') + def test_graphql_cases_should_contain_the_initial_case(self): payload = { - 'query': '{ hello(firstName: "friendly") }' + 'query': '{ cases { name } }' } - response = graphql_api.execute(payload) - self.assertEqual(401, response.status_code) + body = self._subject.execute_graphql_query(payload) + # TODO should check the list contains an element with name "#1 - Initial Demo"