diff --git a/policy/reports/primary_operational_indicators.py b/policy/reports/primary_operational_indicators.py index d87ba3d..0e4733f 100644 --- a/policy/reports/primary_operational_indicators.py +++ b/policy/reports/primary_operational_indicators.py @@ -4301,7 +4301,10 @@ INNER JOIN "tblProduct" prod ON prod."ProdID" = pl."ProdID" INNER JOIN "tblFamilies" fam ON fam."FamilyID" = pl."FamilyID" INNER JOIN "tblInsuree" ins ON ins."InsureeID" = fam."InsureeID" - INNER JOIN "uvwLocations" l ON l."VillageId" = fam."LocationId" + INNER JOIN "tblLocations" v ON v."LocationId" = fam."LocationId" + INNER JOIN "tblLocations" w ON w."LocationId" = v."ParentLocationId" + INNER JOIN "tblLocations" d ON d."LocationId" = w."ParentLocationId" + INNER JOIN "tblLocations" r ON r."LocationId" = d."ParentLocationId" LEFT JOIN "tblPremium" pr ON pr."PolicyID" = pl."PolicyID" WHERE pl."ValidityTo" IS NULL AND prod."ValidityTo" IS NULL @@ -4309,7 +4312,7 @@ AND ins."ValidityTo" IS NULL and pr."ValidityTo" IS NULL AND (prod."ProdID" = %(ProdId)s OR %(ProdId)s = 0) - AND (l."RegionId" = %(LocationId)s OR l."DistrictId" = %(LocationId)s OR COALESCE(%(LocationId)s, 0) = 0 OR %(LocationId)s = 0) + AND (r."LocationId" = %(LocationId)s OR d."LocationId" = %(LocationId)s OR COALESCE(%(LocationId)s, 0) = 0 OR %(LocationId)s = 0) GROUP BY prod."ProdID", prod."ProductCode"; """ diff --git a/policy/tests/__init__.py b/policy/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/policy/test_services.py b/policy/tests/test_services.py similarity index 99% rename from policy/test_services.py rename to policy/tests/test_services.py index 5d137f6..653a601 100644 --- a/policy/test_services.py +++ b/policy/tests/test_services.py @@ -13,7 +13,7 @@ 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 policy.services import * from medical_pricelist.test_helpers import ( create_test_item_pricelist, create_test_service_pricelist diff --git a/policy/test_values.py b/policy/tests/test_values.py similarity index 98% rename from policy/test_values.py rename to policy/tests/test_values.py index 92ae8ff..102c464 100644 --- a/policy/test_values.py +++ b/policy/tests/test_values.py @@ -4,8 +4,8 @@ from insuree.test_helpers import create_test_insuree, create_test_photo from product.test_helpers import create_test_product from insuree.models import Relation -from .values import * -from .test_helpers import create_test_policy +from policy.values import * +from policy.test_helpers import create_test_policy from core.apps import CoreConfig from dateutil.relativedelta import relativedelta diff --git a/policy/tests.py b/policy/tests/tests.py similarity index 100% rename from policy/tests.py rename to policy/tests/tests.py diff --git a/policy/tests_gql.py b/policy/tests/tests_gql.py similarity index 100% rename from policy/tests_gql.py rename to policy/tests/tests_gql.py diff --git a/policy/tests/tests_reports.py b/policy/tests/tests_reports.py new file mode 100644 index 0000000..7e9c5f6 --- /dev/null +++ b/policy/tests/tests_reports.py @@ -0,0 +1,36 @@ +from core.test_helpers import create_test_interactive_user +from rest_framework import status +from rest_framework.test import APITestCase +from dataclasses import dataclass +from graphql_jwt.shortcuts import get_token +from core.models import User +from django.conf import settings + + +@dataclass +class DummyContext: + """ Just because we need a context to generate. """ + user: User + + +class ReportAPITests( APITestCase): + + admin_user = None + admin_token = None + POI_URL = f'/{settings.SITE_ROOT()}report/policy_primary_operational_indicators/pdf/?yearMonth=2019-04-01' + PR_URL = f'/{settings.SITE_ROOT()}report/policy_renewals/pdf/?date_start=2019-04-01&date_end=2019-04-30' + @classmethod + 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)) + + def test_primary_operational_indicators_report(self): + headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"} + response = self.client.get(self.POI_URL, format='json', **headers) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_policy_renewal_report(self): + headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"} + response = self.client.get(self.PR_URL, format='json', **headers) + self.assertEqual(response.status_code, status.HTTP_200_OK) \ No newline at end of file