Skip to content

Commit

Permalink
Merge pull request #125 from openimis/develop
Browse files Browse the repository at this point in the history
fix family
  • Loading branch information
delcroip authored Mar 8, 2024
2 parents ca9ebab + de07d4e commit d136d06
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions insuree/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def custom_insuree_number_validation(insuree_number):
"message": _("validator_function_not_found")}]


def validate_insuree_number(insuree_number, uuid=None):
def validate_insuree_number(insuree_number, insuree_uuid=None):
query = Insuree.objects.filter(
chf_id=insuree_number, validity_to__isnull=True)
insuree = query.first()
if uuid and insuree and str(insuree.uuid.lower()) != str(uuid.lower()):
if insuree_uuid and insuree and uuid.UUID(insuree.uuid) != uuid.UUID(insuree_uuid):
return [{"errorCode": InsureeConfig.validation_code_taken_insuree_number,
"message": "Insuree number has to be unique, %s exists in system" % insuree_number}]

Expand Down
2 changes: 1 addition & 1 deletion insuree/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_test_insuree(with_family=True, is_head=False, custom_props=None, fami


insuree = Insuree.objects.create(
last_name = get_from_custom_props(custom_props, 'last_name',"last" ),
last_name = get_from_custom_props(custom_props, 'last_name',"Test Last" ),
other_names= get_from_custom_props(custom_props, 'other_names', "First Second"),
family= family,
gender= get_from_custom_props(custom_props, 'gender', Gender.objects.get(code='M')),
Expand Down
27 changes: 17 additions & 10 deletions insuree/tests/test_graphql.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import base64
import json
import time
import uuid
from dataclasses import dataclass
from django.utils.translation import gettext as _
from core.models import User, filter_validity
from core.test_helpers import create_test_interactive_user
from core.test_helpers import create_test_interactive_user, AssertMutation
from django.conf import settings
from graphene_django.utils.testing import GraphQLTestCase
from graphql_jwt.shortcuts import get_token
Expand All @@ -24,6 +26,7 @@ class DummyContext:
user: User



class InsureeGQLTestCase(GraphQLTestCase):
GRAPHQL_URL = f'/{settings.SITE_ROOT()}graphql'
# This is required by some version of graphene but is never used. It should be set to the schema but the import
Expand Down Expand Up @@ -198,11 +201,12 @@ def test_query_ignore_location(self):
self.assertResponseNoErrors(response)

def test_create_insuree(self):
muuid = 'ffa465c5-6807-4de0-847e-202b7f42122b'
response = self.query(f'''
mutation {{
createInsuree(
input: {{
clientMutationId: "ffa465c5-6807-4de0-847e-202b7f42122b"
clientMutationId: "{muuid}"
clientMutationLabel: "Create insuree - 12343456234"
chfId: "12343456234"
Expand Down Expand Up @@ -234,15 +238,17 @@ def test_create_insuree(self):

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

AssertMutation(self,muuid, self.admin_dist_token )


def test_create_family(self):
muuid='50f8f2c9-7685-4cd5-a7d8-b1fa78d46470'
fuuid='50f8f2c9-7685-4cd5-a770-b1fa34d46470'
response = self.query(f'''
mutation {{
createFamily(
input: {{
clientMutationId: "50f8f2c9-7685-4cd5-a7d8-b1fa78d46470"
clientMutationId: "{muuid}"
clientMutationLabel: "Create Family - test create family (445566778899)"
headInsuree: {{
chfId: "4455667788"
Expand All @@ -263,7 +269,7 @@ def test_create_family(self):
}}
locationId: {self.test_village.id}
poverty: false
uuid: "50f8f2c9-7685-4cd5-a7d8-b1fa78d46475"
uuid: "{fuuid}"
jsonExt: "{{}}"
}}
) {{
Expand All @@ -279,13 +285,14 @@ def test_create_family(self):

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

AssertMutation(self,muuid, self.admin_dist_token )
mmuid = '50f8f2c9-7685-4cd5-a778-b1fa78d46471'
# update
response = self.query(f'''
mutation {{
updateFamily(
input: {{
clientMutationId: "50f8f2c9-7685-4cd5-a778-b1fa78d46470"
clientMutationId: "{muuid}"
clientMutationLabel: "Update Family - test create family (445566778899)"
headInsuree: {{
chfId: "4455667788"
Expand All @@ -306,7 +313,7 @@ def test_create_family(self):
}}
locationId: {self.test_village.id}
poverty: true
uuid: "50f8f2c9-7685-4cd5-a7d8-b1fa78d46475"
uuid: "{fuuid}"
jsonExt: "{{}}"
}}
) {{
Expand All @@ -322,8 +329,8 @@ def test_create_family(self):

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
family = Family.objects.filter(*filter_validity(),uuid= "50f8f2c9-7685-4cd5-a7d8-b1fa78d46475".upper()).first()
content= AssertMutation(self,muuid, self.admin_dist_token )
family = Family.objects.filter(*filter_validity(),uuid= uuid.UUID(fuuid)).first()
self.assertEqual(family.poverty, True)


Expand Down

0 comments on commit d136d06

Please sign in to comment.