Skip to content

Commit

Permalink
Merge pull request #66 from openimis/develop
Browse files Browse the repository at this point in the history
MERGING develop into release/24.10
  • Loading branch information
delcroip authored Oct 22, 2024
2 parents 196ff12 + 5f38f20 commit e5c0abf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 9 deletions.
13 changes: 9 additions & 4 deletions calculation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ def resolve_calculation_rules(parent, info, **kwargs):
if calculation or calcrule_type:
list_cr = []
for cr in CALCULATION_RULES:
calculation = f'{calculation}'
if (UUID(cr.uuid) == calculation and calcrule_type == cr.type) \
or (UUID(cr.uuid) == calculation and calcrule_type is None) \
or (calculation == 'None' and calcrule_type == cr.type):
if (
(
calculation and
UUID(cr.uuid) == UUID(str(calculation)) and
(calcrule_type == cr.type or calcrule_type is None)
) or (
not calculation and calcrule_type == cr.type
)
):
list_cr = _append_to_calcrule_list(list_cr, cr)
else:
list_cr = []
Expand Down
80 changes: 75 additions & 5 deletions calculation/tests/test_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass

from core.models import User, filter_validity
from core.models.openimis_graphql_test_case import openIMISGraphQLTestCase
from core.test_helpers import create_test_interactive_user
from django.conf import settings
from graphene_django.utils.testing import GraphQLTestCase
Expand All @@ -13,7 +14,7 @@
from insuree.test_helpers import create_test_insuree
from policy.test_helpers import create_test_policy
from contribution.models import Premium, PayTypeChoices

from calculation.calculation_rule import ContributionValuationRule
from location.test_helpers import create_test_location, create_test_health_facility, create_test_village
from payer.models import Payer
from product.models import Product
Expand All @@ -28,7 +29,7 @@ class DummyContext:
user: User


class CalcualtionGQLTestCase(GraphQLTestCase):
class CalcualtionGQLTestCase(openIMISGraphQLTestCase):
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
# is shown as an error in the IDE, so leaving it as True.
Expand Down Expand Up @@ -65,7 +66,7 @@ def test_by_class_name(self):
)

content = json.loads(response.content)

self.assertTrue('data' in content and 'calculationRulesByClassName' in content['data'])
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

Expand All @@ -86,12 +87,81 @@ def test_simple(self):
)

content = json.loads(response.content)

self.assertTrue('data' in content and 'calculationRules' in content['data'])
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

# Add some more asserts if you like

def test_account_payable(self):

response = self.query(
'''
query{
calculationRules(calcruleType: "account_payable")
{
calculationRules{uuid, calculationClassName}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
)

content = json.loads(response.content)
self.assertTrue('data' in content and 'calculationRules' in content['data'])

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

# Add some more asserts if you like


def test_account_receivable(self):

response = self.query(
'''
query{
calculationRules(calcruleType: "account_receivable")
{
calculationRules{uuid, calculationClassName}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
)

content = json.loads(response.content)
self.assertTrue('data' in content and 'calculationRules' in content['data'])
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

# Add some more asserts if you like

def test_uuid(self):

response = self.query(
f'''
query{{
calculationRules(calculation: "{ContributionValuationRule.uuid}")
{{
calculationRules{{uuid, calculationClassName}}
}}
}}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
)

content = json.loads(response.content)
self.assertTrue('data' in content and 'calculationRules' in content['data'])
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

# Add some more asserts if you like


def test_params(self):

response = self.query(
Expand All @@ -107,7 +177,7 @@ def test_params(self):
)

content = json.loads(response.content)

self.assertTrue('data' in content and 'linkedClass' in content['data'])
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

Expand Down

0 comments on commit e5c0abf

Please sign in to comment.