diff --git a/calculation/schema.py b/calculation/schema.py index 11d1f78..aca5393 100644 --- a/calculation/schema.py +++ b/calculation/schema.py @@ -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 = [] diff --git a/calculation/tests/test_gql.py b/calculation/tests/test_gql.py index 47e2117..adb367e 100644 --- a/calculation/tests/test_gql.py +++ b/calculation/tests/test_gql.py @@ -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 @@ -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 @@ -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. @@ -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) @@ -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( @@ -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)