From bea82a1f923709ad629b1689127f1e49c6219f97 Mon Sep 17 00:00:00 2001 From: pavlo-mk Date: Mon, 16 Dec 2024 12:37:59 +0100 Subject: [PATCH] fix filters & update tests :100: :star: --- src/hct_mis_api/apps/payment/filters.py | 5 +---- src/hct_mis_api/apps/payment/schema.py | 1 + .../payment_verification/test_payment_verification.py | 4 +++- .../snapshots/snap_test_all_payment_plan_queries.py | 3 +++ .../apps/payment/test_all_payment_plan_queries.py | 11 ++++++----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/hct_mis_api/apps/payment/filters.py b/src/hct_mis_api/apps/payment/filters.py index 11d95ebbc8..28ef1774ba 100644 --- a/src/hct_mis_api/apps/payment/filters.py +++ b/src/hct_mis_api/apps/payment/filters.py @@ -96,10 +96,7 @@ def payment_plan_filter(self, qs: QuerySet, name: str, value: str) -> QuerySet: ) def business_area_filter(self, qs: QuerySet, name: str, value: str) -> QuerySet: - return qs.filter( - Q(payment_verification_plan__payment_plan__business_area__slug=value) - | Q(payment_verification_plan__cash_plan__business_area__slug=value) - ) + return qs.filter(payment_verification_plan__payment_plan__business_area__slug=value) class PaymentVerificationPlanFilter(FilterSet): diff --git a/src/hct_mis_api/apps/payment/schema.py b/src/hct_mis_api/apps/payment/schema.py index 801be243ff..03b3ea2977 100644 --- a/src/hct_mis_api/apps/payment/schema.py +++ b/src/hct_mis_api/apps/payment/schema.py @@ -365,6 +365,7 @@ def resolve_target_population(self, info: Any) -> TargetPopulation: return self.parent.target_population def resolve_full_name(self, info: Any) -> str: + # TODO: add to test this one return self.head_of_household.full_name if self.head_of_household else "" def resolve_verification(self, info: Any) -> Optional[Any]: diff --git a/tests/selenium/payment_verification/test_payment_verification.py b/tests/selenium/payment_verification/test_payment_verification.py index 3b2b6941ff..ba88b48bc2 100644 --- a/tests/selenium/payment_verification/test_payment_verification.py +++ b/tests/selenium/payment_verification/test_payment_verification.py @@ -194,8 +194,9 @@ def add_payment_verification_xlsx() -> PV: def payment_verification_creator(channel: str = PaymentVerificationPlan.VERIFICATION_CHANNEL_MANUAL) -> PV: + user = User.objects.first() registration_data_import = RegistrationDataImportFactory( - imported_by=User.objects.first(), business_area=BusinessArea.objects.first() + imported_by=user, business_area=BusinessArea.objects.first() ) program = Program.objects.filter(name="Active Program").first() household, individuals = create_household( @@ -214,6 +215,7 @@ def payment_verification_creator(channel: str = PaymentVerificationPlan.VERIFICA business_area=BusinessArea.objects.first(), start_date=datetime.now() - relativedelta(months=1), end_date=datetime.now() + relativedelta(months=1), + created_by=user, ) payment_plan.unicef_id = "PP-0000-00-1122334" diff --git a/tests/unit/apps/payment/snapshots/snap_test_all_payment_plan_queries.py b/tests/unit/apps/payment/snapshots/snap_test_all_payment_plan_queries.py index 675e9fedae..7d078d975b 100644 --- a/tests/unit/apps/payment/snapshots/snap_test_all_payment_plan_queries.py +++ b/tests/unit/apps/payment/snapshots/snap_test_all_payment_plan_queries.py @@ -420,6 +420,7 @@ 'data': { 'payment': { 'additionalCollectorName': None, + 'fullName': 'First1 Mid1 Last1', 'reasonForUnsuccessfulPayment': 'reason 123', 'snapshotCollectorBankAccountNumber': None, 'snapshotCollectorBankName': None, @@ -436,6 +437,7 @@ 'data': { 'payment': { 'additionalCollectorName': 'AddCollectorName11', + 'fullName': 'First2 Mid2 Last3', 'reasonForUnsuccessfulPayment': 'reason 222', 'snapshotCollectorBankAccountNumber': 'PrimaryCollBankNumber', 'snapshotCollectorBankName': 'PrimaryCollBankName', @@ -452,6 +454,7 @@ 'data': { 'payment': { 'additionalCollectorName': 'AddCollectorName22', + 'fullName': 'First3 Mid3 Last3', 'reasonForUnsuccessfulPayment': 'reason 333', 'snapshotCollectorBankAccountNumber': 'AlternateCollBankNumber', 'snapshotCollectorBankName': 'AlternateCollBankName', diff --git a/tests/unit/apps/payment/test_all_payment_plan_queries.py b/tests/unit/apps/payment/test_all_payment_plan_queries.py index 085522fb8b..549ca2d9f8 100644 --- a/tests/unit/apps/payment/test_all_payment_plan_queries.py +++ b/tests/unit/apps/payment/test_all_payment_plan_queries.py @@ -207,6 +207,7 @@ class TestPaymentPlanQueries(APITestCase): query Payment($id: ID!) { payment(id: $id) { totalPersonsCovered + fullName snapshotCollectorFullName snapshotCollectorDeliveryPhoneNo snapshotCollectorBankName @@ -475,9 +476,9 @@ def test_payment_node_with_legacy_data(self) -> None: dispersion_end_date=datetime(2023, 12, 10), is_follow_up=False, ) - hoh_1 = IndividualFactory(household=None) - hoh_2 = IndividualFactory(household=None) - hoh_3 = IndividualFactory(household=None) + hoh_1 = IndividualFactory(household=None, given_name="First1", middle_name="Mid1", family_name="Last1") + hoh_2 = IndividualFactory(household=None, given_name="First2", middle_name="Mid2", family_name="Last3") + hoh_3 = IndividualFactory(household=None, given_name="First3", middle_name="Mid3", family_name="Last3") household_1 = HouseholdFactory(head_of_household=hoh_1, size=5) household_2 = HouseholdFactory(head_of_household=hoh_2, size=10) household_3 = HouseholdFactory(head_of_household=hoh_3, size=15) @@ -548,7 +549,7 @@ def test_payment_node_with_legacy_data(self) -> None: ) def test_all_payment_verification_log_entries(self) -> None: - QUERY = """ + query = """ query allPaymentVerificationLogEntries($objectId: UUID, $businessArea: String!) { allPaymentVerificationLogEntries(objectId: $objectId, businessArea: $businessArea) { totalCount @@ -584,7 +585,7 @@ def test_all_payment_verification_log_entries(self) -> None: ) self.snapshot_graphql_request( - request_string=QUERY, + request_string=query, context={"user": self.user}, variables={"objectId": payment_plan_id, "businessArea": "afghanistan"}, )