Skip to content

Commit

Permalink
Merge pull request #99 from openimis/feature/fix-test-inquire-service
Browse files Browse the repository at this point in the history
fix test
  • Loading branch information
delcroip authored Mar 8, 2024
2 parents d9c1f55 + 1758e31 commit a8add75
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 44 deletions.
37 changes: 5 additions & 32 deletions policy/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from contribution.models import Premium
from insuree.models import InsureePolicy, Family, Gender, Insuree
from insuree.test_helpers import create_test_insuree
from policy.models import Policy
from policy.values import policy_values
from product.models import Product
from core.utils import filter_validity
import datetime


def create_test_policy(product, insuree, link=True, valid=True, custom_props=None, check=False):
"""
Compatibility method that only return the Policy
Expand Down Expand Up @@ -132,37 +135,7 @@ def create_test_policy_with_IPs(product, insuree, valid=True, policy_props=None,
def create_test_insuree_for_policy(with_family=True, is_head=False, custom_props=None, family_custom_props=None):
# To establish the mandatory reference between "Insuree" and "Family" objects, we can insert the "Family" object
# with a temporary ID and later update it to associate with the respective "Insuree" object.
if with_family:
family = Family.objects.create(
validity_from="2019-01-01",
head_insuree_id=1, # dummy
audit_user_id=-1,
**(family_custom_props if family_custom_props else {})
)
else:
family = None
insuree= create_test_insuree(with_family=with_family, is_head=is_head, custom_props=custom_props, family_custom_props=family_custom_props)

insuree = Insuree.objects.create(
**{
"last_name": "Test Last",
"other_names": "First Second",
"chf_id": "chf_dflt",
"family": family,
"gender": Gender.objects.get(code='M'),
"dob": dts("1970-01-01"),
"head": is_head,
"card_issued": True,
"validity_from": dts("2019-01-01"),
"audit_user_id": -1,
**(custom_props if custom_props else {})
}
)
insuree.save()
if with_family:
family.head_insuree_id = insuree.id
if family_custom_props:
for k, v in family_custom_props.items():
setattr(family, k, v)
family.save()

return insuree, family
return insuree, insuree.family
27 changes: 17 additions & 10 deletions policy/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
from insuree.test_helpers import create_test_insuree
from policy.test_helpers import create_test_policy2, create_test_insuree_for_policy
from product.test_helpers import create_test_product, create_test_product_service, create_test_product_item

from location.test_helpers import create_test_health_facility
from .services import *

from medical_pricelist.test_helpers import (
create_test_item_pricelist,
create_test_service_pricelist
)

class EligibilityServiceTestCase(TestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -330,7 +333,12 @@ def test_eligibility_stored_proc_item_no_insuree_policy(self):
insuree.delete()

def test_eligibility_signal(self):

insuree, family = create_test_insuree_for_policy()
#spl = create_test_service_pricelist(location_id=family.location.parent.id)
#ipl = create_test_item_pricelist(location_id=family.location.parent.id)
#hf =create_test_health_facility(code= 'tst-18', location_id=family.location.parent.id, custom_props={'id':18, 'items_pricelist': ipl, 'services_pricelist': spl })

product = create_test_product("ELI1")
(policy, insuree_policy) = create_test_policy2(product, insuree)
item = create_test_item("A")
Expand Down Expand Up @@ -475,12 +483,11 @@ def test_renewals_sms(self):
from core import datetime, datetimedelta

insuree, family = create_test_insuree_for_policy(
custom_props={"chf_id": "TESTCHFSMS", "phone": "+33644444719"},
family_custom_props={"location_id": 62},
)
custom_props={"chf_id": "TESTCHFSMS", 'last_name':'Test Last',"phone": "+33644444719"} )
product = create_test_product("VISIT")
officer = create_test_officer(
custom_props={"phone": "+32444444444", "phone_communication": True}
custom_props={"phone": "+32444444444", "phone_communication": True},
villages = [family.location]
)

(policy_expiring, _) = create_test_policy2(
Expand Down Expand Up @@ -518,9 +525,9 @@ def test_renewals_sms(self):
officer_sms = [sms for sms in sms_queue if sms.phone == "+32444444444"]
self.assertEquals(len(officer_sms), 1)
self.assertIn("TESTCHFSMS", officer_sms[0].sms_message)
self.assertIn("Agilo", officer_sms[0].sms_message)
self.assertIn("Remorlogy", officer_sms[0].sms_message)
self.assertIn("Jambero", officer_sms[0].sms_message)
self.assertIn(family.location.name, officer_sms[0].sms_message)
self.assertIn(family.location.parent.name, officer_sms[0].sms_message)
self.assertIn(family.location.parent.parent.name, officer_sms[0].sms_message)
self.assertIn("Test product VISIT", officer_sms[0].sms_message)

# tearDown
Expand All @@ -541,7 +548,7 @@ def test_insert_renewal_details(self):
insuree_newpic, family_newpic = create_test_insuree_for_policy(
custom_props={"photo_date": datetime.datetime.now() - datetimedelta(days=30)})
insuree_oldpic, family_oldpic = create_test_insuree_for_policy(
custom_props={"photo_date": "2010-01-01", "chf_id": "CHFMARK"}) # 5 years by default
custom_props={"photo_date": "2010-01-01", "chf_id": "CHFMARK", 'last_name':'Test Last'}) # 5 years by default
product = create_test_product("VISIT")
officer = create_test_officer(custom_props={"phone": "+32444444444", "phone_communication": True})
photo_newpic = create_test_photo(insuree_newpic.id, officer.id)
Expand Down
79 changes: 77 additions & 2 deletions policy/tests_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,23 @@
from graphene_django.utils.testing import GraphQLTestCase
from graphql_jwt.shortcuts import get_token
#credits https://docs.graphene-python.org/projects/django/en/latest/testing/

from medical.test_helpers import (
create_test_item,
create_test_service
)
from insuree.test_helpers import create_test_insuree
from policy.test_helpers import create_test_policy
from contribution.test_helpers import create_test_premium
from product.models import ProductItemOrService
from product.test_helpers import (
create_test_product,
create_test_product_service,
create_test_product_item,
)
from location.test_helpers import (
create_test_health_facility,
create_test_village
)

@dataclass
class DummyContext:
Expand All @@ -28,6 +44,41 @@ def setUpClass(cls):
super().setUpClass()
cls.admin_user = create_test_interactive_user(username="testLocationAdmin")
cls.admin_token = get_token(cls.admin_user, DummyContext(user=cls.admin_user))

cls.test_village =create_test_village()
cls.test_ward =cls.test_village.parent
cls.test_region =cls.test_village.parent.parent.parent
cls.test_district = cls.test_village.parent.parent
# Given
cls.insuree = create_test_insuree(custom_props={'current_village':cls.test_village})
cls.service = create_test_service("A", custom_props={"name": "test_simple_batch"})
cls.item = create_test_item("A", custom_props={"name": "test_simple_batch"})

cls.product = create_test_product(
"BCUL0001",
custom_props={
"name": "simplebatch",
"lump_sum": 10_000,
"location_id": cls.test_region.id
},
)

cls.product_service = create_test_product_service(
cls.product,
cls.service,
custom_props={},
)
cls.product_item = create_test_product_item(
cls.product,
cls.item,
custom_props={"price_origin": ProductItemOrService.ORIGIN_RELATIVE},
)
cls.policy = create_test_policy(cls.product, cls.insuree, link=True)
cls.premium = create_test_premium(
policy_id=cls.policy.id, custom_props={}
)



def test_insuree_policy_query(self):

Expand Down Expand Up @@ -91,10 +142,14 @@ def test_query_with_variables(self):

def test_insuree_policy_query(self):





response = self.query(
f'''
{{
policyServiceEligibilityByInsuree(chfId:"070707070", serviceCode:"{Service.objects.filter(*filter_validity()).order_by('id').first().code}")
policyServiceEligibilityByInsuree(chfId:"{self.insuree.chf_id}", serviceCode:"{self.service.code}")
{{
minDateService, serviceLeft, isServiceOk
}}
Expand All @@ -108,5 +163,25 @@ def test_insuree_policy_query(self):
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)


# Add some more asserts if you like
response = self.query(
f'''
{{
policyItemEligibilityByInsuree(chfId:"{self.insuree.chf_id}",itemCode:"{self.item.code}")
{{
minDateItem,itemLeft,isItemOk
}}
}}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
)

content = json.loads(response.content)

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

# Add some more asserts if you like
...

0 comments on commit a8add75

Please sign in to comment.