Skip to content

Commit

Permalink
[ADD] Started implementation of query cases, which should return the …
Browse files Browse the repository at this point in the history
…list of cases visible by the user
  • Loading branch information
c8y3 committed Mar 15, 2024
1 parent b1d73f8 commit 74aea48
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 11 additions & 1 deletion source/app/blueprints/graphql/graphql_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}!'

Expand Down
1 change: 1 addition & 0 deletions source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,24 @@ 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") }'
}
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"

0 comments on commit 74aea48

Please sign in to comment.