Skip to content

Commit 2ee795e

Browse files
author
lruzicki
committed
TECH-717: draft endpoint that always return true added
1 parent b4e7488 commit 2ee795e

File tree

20 files changed

+941
-78
lines changed

20 files changed

+941
-78
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__/
2+
<<<<<<< HEAD
3+
=======
4+
*.pyc
5+
6+
>>>>>>> 64c57dd (DRAFT)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

govstack_test_harness_api/building_blocks/__init__.py

Whitespace-only changes.

govstack_test_harness_api/building_blocks/bb-digital-registries/__init__.py

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import graphene
2+
import datetime
3+
import base64
4+
5+
from django.contrib.auth.models import AnonymousUser
6+
from django.test import TestCase
7+
from graphene import Schema
8+
from graphene.test import Client
9+
from unittest import mock
10+
from uuid import UUID
11+
12+
from insuree.schema import Query, Mutation
13+
from contribution_plan.tests.helpers import *
14+
# from contribution_plan import schema as contribution_plan_schema
15+
16+
17+
class QueryTest(TestCase):
18+
class BaseTestContext:
19+
user = mock.Mock(is_anonymous=False)
20+
user.has_perm = mock.MagicMock(return_value=False)
21+
22+
class AnonymousUserContext:
23+
user = AnonymousUser()
24+
25+
@staticmethod
26+
def set_up_env(request):
27+
client = Client(schema=Schema(query=Query, mutation=Mutation))
28+
context = QueryTest.BaseTestContext()
29+
context.user = None
30+
if request.user.is_authenticated:
31+
context.user = request.user
32+
else:
33+
context = QueryTest.AnonymousUserContext()
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import os
2+
from .insureequery import *
3+
from core.schema import Query as core_query, Mutation as core_mutation
4+
5+
6+
def get_client(schema, query, mutation):
7+
return Client(schema=schema(query=query, mutation=mutation))
8+
9+
10+
def get_context(request):
11+
context = QueryTest.BaseTestContext()
12+
context.user = None
13+
print('Request user: ', request.user)
14+
if request.user.is_authenticated:
15+
context.user = request.user
16+
else:
17+
context = QueryTest.AnonymousUserContext()
18+
print('Context user: ', context.user)
19+
return context
20+
21+
22+
def get_update_registry_query(uuid="", chf_id="", update_fields="") -> str:
23+
query = f'''
24+
mutation {{
25+
updateInsuree(
26+
input: {{
27+
clientMutationId: "552f8e55-ed5a-4e1e-a159-ea8f8cec0560"
28+
clientMutationLabel: "Update insuree"
29+
uuid: "{uuid}"
30+
chfId: "{chf_id}"
31+
{update_fields}
32+
genderId: "F"
33+
head: true
34+
dob: "1974-06-11"
35+
cardIssued:false
36+
familyId: 1
37+
relationshipId: 4
38+
}}
39+
) {{
40+
clientMutationId
41+
internalId
42+
}}
43+
}}
44+
'''
45+
return query
46+
47+
48+
def get_insurees_query(variable_values: str = "", fetched_fields: str = "") -> str:
49+
return f'''
50+
query GetInsurees {{
51+
insurees({variable_values}) {{
52+
edges{{
53+
node{{
54+
{fetched_fields}
55+
}}
56+
}}
57+
}}
58+
}}
59+
'''
60+
61+
62+
def create_insurees_query(variables: dict) -> str:
63+
return f'''
64+
mutation {{
65+
createInsuree(
66+
input: {{
67+
clientMutationLabel: "{variables['clientMutationLabel']}"
68+
chfId: "{variables['chfId']}"
69+
lastName: "{variables['lastName']}"
70+
otherNames: "{variables['otherNames']}"
71+
genderId: "{variables['genderId']}"
72+
dob: "{variables['dob']}"
73+
head: {str(variables['head']).lower()}
74+
cardIssued: {str(variables['cardIssued']).lower()}
75+
jsonExt: "{variables['jsonExt']}"
76+
familyId: 1
77+
}}
78+
) {{
79+
clientMutationId
80+
internalId
81+
}}
82+
}}
83+
'''
84+
85+
def delete_insuree_query(uuid):
86+
return f'''mutation
87+
{{
88+
deleteInsurees(
89+
input: {{
90+
clientMutationId: "c164412c-45a6-4f3f-8a2b-4290739751e2"
91+
clientMutationLabel: "Delete insuree"
92+
93+
uuid: "{uuid}", uuids: ["{uuid}"]
94+
}}
95+
) {{
96+
clientMutationId
97+
internalId
98+
}}
99+
}}
100+
'''
101+
102+
103+
def get_query_content_values(query_content: dict) -> dict:
104+
content_values = {}
105+
if not query_content:
106+
return {}
107+
content_values['chfId'] = query_content.get('ID', "")
108+
content_values['FirstName'] = query_content.get('FirstName', "")
109+
content_values['LastName'] = query_content.get('LastName', "")
110+
content_values['BirthCertificateID'] = query_content.get('BirthCertificateID', "")
111+
return content_values
112+
113+
114+
def get_query_write_values(query_write: dict) -> dict:
115+
write_values = {}
116+
if not query_write:
117+
return {}
118+
write_values['chfId'] = query_write.get('ID', "")
119+
write_values['FirstName'] = query_write.get('FirstName', "")
120+
write_values['LastName'] = query_write.get('LastName', "")
121+
write_values['BirthCertificateID'] = query_write.get('BirthCertificateID', "")
122+
return write_values
123+
124+
125+
def get_values_for_insurees(content_values: dict) -> dict:
126+
return {
127+
'clientMutationLabel': f"Create insuree - {content_values['chfId']}",
128+
'chfId': f"{content_values['chfId']}",
129+
'lastName': f"{content_values['LastName']}",
130+
'otherNames': f"{content_values['FirstName']}",
131+
'genderId': 'M',
132+
'dob': '2000-06-20',
133+
'head': True,
134+
'cardIssued': False,
135+
'jsonExt': '{}',
136+
}
137+
138+
def get_search_insurees_arguments(query_content: dict) -> str:
139+
insurees_arguments = ""
140+
if 'ID' in query_content:
141+
insurees_arguments += f'chfId: "{query_content["ID"]}",'
142+
elif 'chfId' in query_content:
143+
insurees_arguments += f'chfId: "{query_content["chfId"]}",'
144+
if 'FirstName' in query_content:
145+
insurees_arguments += f'otherNames: "{query_content["FirstName"]}",'
146+
if 'LastName' in query_content:
147+
insurees_arguments += f'lastName: "{query_content["LastName"]}",'
148+
# if 'BirthCertificateID' in query_content:
149+
# variable_values += ": $"
150+
151+
if insurees_arguments.endswith(','):
152+
return insurees_arguments[:-1]
153+
return insurees_arguments
154+
155+
156+
def get_update_fields(write_values) -> str:
157+
field_mapping = {
158+
"LastName": "lastName",
159+
"FirstName": "otherNames"
160+
}
161+
return "".join(f'{field_mapping[key]}: "{value}" '
162+
for key, value in write_values.items()
163+
if value and key in field_mapping)
164+
165+
166+
def login_with_env_variables(request):
167+
client = get_client(Schema, core_query, core_mutation)
168+
username = os.getenv('login_openIMIS')
169+
password = os.getenv('password_openIMIS')
170+
171+
mutation = f'''
172+
mutation {{
173+
tokenAuth(username: "{username}", password: "{password}") {{
174+
token
175+
refreshExpiresIn
176+
}}
177+
}}
178+
'''
179+
context = get_context(request)
180+
client.execute(mutation, context=context)
181+
return context

0 commit comments

Comments
 (0)