Skip to content

Commit 577cb1e

Browse files
authored
Merge pull request #73 from openimis/release/25.04
MERGING release/25.04 into develop
2 parents ad81f0a + facd88f commit 577cb1e

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

invoice/tests/gql/base.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from graphene.test import Client
33
from policy.test_helpers import create_test_policy
44
from product.test_helpers import create_test_product
5+
from core.test_helpers import create_test_interactive_user
56

67
from core.forms import User
78
from django.test import TestCase
@@ -15,23 +16,18 @@
1516
create_test_invoice_line_item
1617
from invoice.tests.helpers.invoice_payment_helpers import create_test_invoice_payment
1718

19+
from core.models.openimis_graphql_test_case import openIMISGraphQLTestCase, BaseTestContext
20+
class InvoiceGQLTestCase(openIMISGraphQLTestCase):
1821

19-
class InvoiceGQLTestCase(TestCase):
20-
class BaseTestContext:
21-
def __init__(self, user):
22-
self.user = user
2322

2423
@classmethod
2524
def setUpClass(cls):
2625
super(InvoiceGQLTestCase, cls).setUpClass()
2726
cls._graphene_setup()
2827

2928
cls.maxDiff = None
30-
if not User.objects.filter(username='admin_invoice').first():
31-
User.objects.create_superuser(username='admin_invoice', password='S\/pe®Pąßw0rd™')
32-
33-
cls.user = User.objects.filter(username='admin_invoice').first()
34-
29+
cls.user = create_test_interactive_user(username="admin_invoice")
30+
cls.user_context = BaseTestContext(cls.user)
3531
cls.policy_holder = create_test_policy_holder()
3632
cls.contract = create_test_contract(cls.policy_holder)
3733
cls.insuree = create_test_insuree(with_family=True)

invoice/tests/gql/detail_payment_invoice_schema.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def test_fetch_detail_payment_invoice_query(self):
6969
mutation = self.create_mutation_str.format(
7070
payment_uuid=payment.id, subject_uuid=invoice.id, mutation_id=mutation_client_id
7171
)
72-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
72+
self.graph_client.execute(mutation, context=self.user_context.get_request())
7373
output = self.graph_client.execute(self.search_for_detail_payment_invoice_query,
74-
context=self.BaseTestContext(self.user))
74+
context=self.user_context.get_request())
7575
expected = \
7676
{'data': {
7777
'detailPaymentInvoice': {
@@ -94,7 +94,7 @@ def test_create_detail_payment_mutation(self):
9494
mutation = self.create_mutation_str.format(
9595
payment_uuid=payment.id, subject_uuid=invoice.id, mutation_id=mutation_client_id
9696
)
97-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
97+
self.graph_client.execute(mutation, context=self.user_context.get_request())
9898
expected = DetailPaymentInvoice.objects.get(payment__id=payment.id)
9999
mutation_log = MutationLog.objects.filter(client_mutation_id=mutation_client_id).first()
100100
obj = DetailPaymentInvoiceMutation.objects.get(mutation_id=mutation_log.id).detail_payment_invoice
@@ -108,11 +108,11 @@ def test_delete_detail_payment_mutation(self):
108108
mutation = self.create_mutation_str.format(
109109
payment_uuid=payment.id, subject_uuid=invoice.id, mutation_id=mutation_client_id
110110
)
111-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
111+
self.graph_client.execute(mutation, context=self.user_context.get_request())
112112
expected = DetailPaymentInvoice.objects.get(payment__id=payment.id)
113113
mutation_client_id = str(uuid.uuid4())
114114
mutation = self.delete_mutation_str.format(payment_uuid=expected.id, mutation_id=mutation_client_id)
115-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
115+
self.graph_client.execute(mutation, context=self.user_context.get_request())
116116
# TODO: Currently deleted entries are not filtered by manager, only in GQL Query. Should we change this?
117117
detail_payment = DetailPaymentInvoice.objects.filter(payment__id=payment.id).all()
118118
mutation_ = DetailPaymentInvoiceMutation.objects.filter(detail_payment_invoice=detail_payment[0]).all()
@@ -128,12 +128,12 @@ def test_update_detail_payment_mutation(self):
128128
mutation = self.create_mutation_str.format(
129129
payment_uuid=payment.id, subject_uuid=invoice.id, mutation_id=mutation_client_id
130130
)
131-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
131+
self.graph_client.execute(mutation, context=self.user_context.get_request())
132132

133133
created = DetailPaymentInvoice.objects.get(payment__id=payment.id)
134134
mutation_client_id = str(uuid.uuid4())
135135
mutation = self.update_mutation_str.format(detail_payment_uuid=created.id, mutation_id=mutation_client_id)
136-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
136+
self.graph_client.execute(mutation, context=self.user_context.get_request())
137137

138138
expected_fees = "12.00"
139139
mutation_log = MutationLog.objects.filter(client_mutation_id=mutation_client_id).first()

invoice/tests/gql/invoice_event_schema.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
from invoice.tests.gql.base import InvoiceGQLTestCase
66

77

8+
9+
810
class InvoiceEventGQLTest(InvoiceGQLTestCase):
911

12+
1013
search_for_message = '''
1114
query {{
1215
invoiceEvent(message_Istartswith: "{message_content}") {{
@@ -31,10 +34,10 @@ class InvoiceEventGQLTest(InvoiceGQLTestCase):
3134
def test_fetch_invoice_query(self):
3235
mutation_client_id = str(uuid.uuid4())
3336
mutation = self.create_mutation_str.format(invoice_id=self.invoice.id, mutation_id=mutation_client_id)
34-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
37+
self.graph_client.execute(mutation, context=self.user_context.get_request())
3538

3639
output = self.graph_client.execute(
37-
self.search_for_message.format(message_content="Some message with"), context=self.BaseTestContext(self.user)
40+
self.search_for_message.format(message_content="Some message with"), context=self.user_context.get_request()
3841
)
3942

4043
expected = \
@@ -49,7 +52,7 @@ def test_fetch_invoice_query(self):
4952
def test_create_payment_mutation(self):
5053
mutation_client_id = str(uuid.uuid4())
5154
mutation = self.create_mutation_str.format(invoice_id=self.invoice.id, mutation_id=mutation_client_id)
52-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
55+
self.graph_client.execute(mutation, context=self.user_context.get_request())
5356
mutation_log = MutationLog.objects.filter(client_mutation_id=mutation_client_id).first()
5457
obj: InvoiceEvent = InvoiceEventMutation.objects.get(mutation_id=mutation_log.id).invoice_event
5558
self.assertEqual(obj.invoice, self.invoice)

invoice/tests/gql/invoice_line_item_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class InvoiceLineItemGQLTest(InvoiceGQLTestCase):
2626
'''
2727

2828
def test_fetch_invoice_query(self):
29-
output = self.graph_client.execute(self.search_for_invoice_query, context=self.BaseTestContext(self.user))
29+
output = self.graph_client.execute(self.search_for_invoice_query, context=self.user_context.get_request())
3030
expected = \
3131
{'data': {
3232
'invoiceLineItem': {

invoice/tests/gql/invoice_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ def test_mutation_invoice_generate_for_time_frame(self):
5252
'result': None
5353
}
5454
mutation = self.create_invoice_mutation
55-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
55+
self.graph_client.execute(mutation, context=self.user_context.get_request())
5656
signal_receiver_mock.assert_called_once_with(**_expected_call_args)
5757
pass
5858

5959
def test_fetch_invoice_query(self):
60-
output = self.graph_client.execute(self.search_for_invoice_query, context=self.BaseTestContext(self.user))
60+
output = self.graph_client.execute(self.search_for_invoice_query, context=self.user_context.get_request())
6161
expected = \
6262
{'data': {
6363
'invoice': {

invoice/tests/gql/payment_invoice_schema.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def test_fetch_payment_invoice_query(self):
116116
mutation = self.create_mutation_str.format(
117117
payment_code=payment_code, mutation_id=mutation_client_id
118118
)
119-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
119+
self.graph_client.execute(mutation, context=self.user_context.get_request())
120120
output = self.graph_client.execute(self.search_for_payment_invoice_query,
121-
context=self.BaseTestContext(self.user))
121+
context=self.user_context.get_request())
122122
expected = \
123123
{'data': {
124124
'paymentInvoice': {
@@ -138,7 +138,7 @@ def test_fetch_payment_invoice_query(self):
138138
def test_fetch_payment_invoice_with_detail_query(self):
139139
payment = create_test_payment_invoice_with_details()
140140
output = self.graph_client.execute(self.search_for_payment_invoice_with_detail_query,
141-
context=self.BaseTestContext(self.user))
141+
context=self.user_context.get_request())
142142
expected = \
143143
{'data': {
144144
'paymentInvoice': {
@@ -174,7 +174,7 @@ def test_create_payment_mutation(self):
174174
mutation = self.create_mutation_str.format(
175175
payment_code=payment_code, mutation_id=mutation_client_id
176176
)
177-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
177+
self.graph_client.execute(mutation, context=self.user_context.get_request())
178178
expected = PaymentInvoice.objects.get(code_ext=payment_code)
179179
mutation_log = MutationLog.objects.filter(client_mutation_id=mutation_client_id).first()
180180
obj = PaymentInvoiceMutation.objects.get(mutation_id=mutation_log.id).payment_invoice
@@ -188,7 +188,7 @@ def test_create_payment_with_detail_mutation(self):
188188
mutation = self.create_mutation_with_detail_str.format(
189189
payment_code=payment_code, mutation_id=mutation_client_id, invoice_uuid=invoice.id
190190
)
191-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
191+
self.graph_client.execute(mutation, context=self.user_context.get_request())
192192
expected = PaymentInvoice.objects.get(code_ext=payment_code)
193193
mutation_log = MutationLog.objects.filter(client_mutation_id=mutation_client_id).first()
194194
obj = PaymentInvoiceMutation.objects.get(mutation_id=mutation_log.id).payment_invoice
@@ -204,11 +204,11 @@ def test_delete_payment_mutation(self):
204204
mutation = self.create_mutation_str.format(
205205
payment_code=payment_code, mutation_id=mutation_client_id
206206
)
207-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
207+
self.graph_client.execute(mutation, context=self.user_context.get_request())
208208
expected = PaymentInvoice.objects.get(code_ext=payment_code)
209209
mutation_client_id = str(uuid.uuid4())
210210
mutation = self.delete_mutation_str.format(payment_uuid=expected.id, mutation_id=mutation_client_id)
211-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
211+
self.graph_client.execute(mutation, context=self.user_context.get_request())
212212
# TODO: Currently deleted entries are not filtered by manager, only in GQL Query. Should we change this?
213213
payment = PaymentInvoice.objects.filter(code_ext=payment_code).all()
214214
mutation_ = PaymentInvoiceMutation.objects.filter(payment_invoice=payment[0]).all()
@@ -222,12 +222,12 @@ def test_update_payment_mutation(self):
222222
mutation = self.create_mutation_str.format(
223223
payment_code=payment_code, mutation_id=mutation_client_id
224224
)
225-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
225+
self.graph_client.execute(mutation, context=self.user_context.get_request())
226226

227227
created = PaymentInvoice.objects.get(code_ext=payment_code)
228228
mutation_client_id = str(uuid.uuid4())
229229
mutation = self.update_mutation_str.format(payment_uuid=created.id, mutation_id=mutation_client_id)
230-
self.graph_client.execute(mutation, context=self.BaseTestContext(self.user))
230+
self.graph_client.execute(mutation, context=self.user_context.get_request())
231231

232232
expected_code_ext = "updExt"
233233
mutation_log = MutationLog.objects.filter(client_mutation_id=mutation_client_id).first()

0 commit comments

Comments
 (0)