From 305649da7130d0db3f5043b154c85d488b99c99e Mon Sep 17 00:00:00 2001 From: delcroip Date: Thu, 15 Aug 2024 10:20:04 +0200 Subject: [PATCH] HotFIx --- social_protection/gql_mutations.py | 6 +++--- social_protection/models.py | 2 +- social_protection/services.py | 2 +- social_protection/tests/beneficiary_gql_test.py | 4 +++- social_protection/tests/beneficiary_service_test.py | 5 ++++- .../tests/group_beneficiary_service_test.py | 12 +++++++----- social_protection/tests/test_helpers.py | 1 + 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/social_protection/gql_mutations.py b/social_protection/gql_mutations.py index 4163417..1551b70 100644 --- a/social_protection/gql_mutations.py +++ b/social_protection/gql_mutations.py @@ -189,7 +189,7 @@ def _mutate(cls, user, **data): with transaction.atomic(): for obj_id in ids: - res = service.delete({'id': obj_id}) + res = service.delete({'id': obj_id, 'user': user}) if not res['success']: transaction.rollback() return res @@ -296,7 +296,7 @@ def _mutate(cls, user, **data): if SocialProtectionConfig.gql_check_beneficiary_crud: res = service.create_delete_task({'id': obj_id}) else: - res = service.delete({'id': obj_id}) + res = service.delete({'id': obj_id, 'user': user}) if not res['success']: transaction.rollback() return res @@ -432,7 +432,7 @@ def _mutate(cls, user, **data): if SocialProtectionConfig.gql_check_group_beneficiary_crud: res = service.create_delete_task({'id': obj_id}) else: - res = service.delete({'id': obj_id}) + res = service.delete({'id': obj_id, 'user': user}) if not res['success']: transaction.rollback() return res diff --git a/social_protection/models.py b/social_protection/models.py index 3c4ad6d..c2a8100 100644 --- a/social_protection/models.py +++ b/social_protection/models.py @@ -77,7 +77,7 @@ class GroupBeneficiary(core_models.HistoryBusinessModel): def clean(self): if self.benefit_plan.type != BenefitPlan.BenefitPlanType.GROUP_TYPE: - raise ValidationError(_("Group beneficiary must be associated with a group benefit plan.")) + raise ValidationError(_("Group beneficiary must be associated with a benefit plan type = GROUP.")) super().clean() diff --git a/social_protection/services.py b/social_protection/services.py index 7119685..1b88eb8 100644 --- a/social_protection/services.py +++ b/social_protection/services.py @@ -417,7 +417,7 @@ def _create_task(self, benefit_plan, upload_id, business_event): 'source_name': upload_record.data_upload.source_name, 'workflow': upload_record.workflow, 'percentage_of_invalid_items': self.__calculate_percentage_of_invalid_items(upload_id), - 'data_upload_id': upload_id + 'data_upload_id': str(upload_id) } TaskService(self.user).create({ 'source': 'import_valid_items', diff --git a/social_protection/tests/beneficiary_gql_test.py b/social_protection/tests/beneficiary_gql_test.py index 028b625..d4e5e32 100644 --- a/social_protection/tests/beneficiary_gql_test.py +++ b/social_protection/tests/beneficiary_gql_test.py @@ -33,7 +33,8 @@ def setUpClass(cls): # some test data so as to created contract properly cls.user_token = get_token(cls.user, cls.BaseTestContext(user=cls.user)) cls.benefit_plan = create_benefit_plan(cls.user.username, payload_override={ - 'code': 'SGQLTest' + 'code': 'SGQLTest', + 'type': "INDIVIDUAL" }) cls.individual_2child = create_individual(cls.user.username) cls.individual_1child = create_individual(cls.user.username, payload_override={ @@ -56,6 +57,7 @@ def setUpClass(cls): } }) cls.service = BeneficiaryService(cls.user) + add_individual_to_benefit_plan(cls.service, cls.individual_2child, cls.benefit_plan) add_individual_to_benefit_plan(cls.service, cls.individual_1child, cls.benefit_plan) add_individual_to_benefit_plan(cls.service, cls.individual, diff --git a/social_protection/tests/beneficiary_service_test.py b/social_protection/tests/beneficiary_service_test.py index 646ebb7..0746489 100644 --- a/social_protection/tests/beneficiary_service_test.py +++ b/social_protection/tests/beneficiary_service_test.py @@ -28,7 +28,10 @@ def setUpClass(cls): cls.user = LogInHelper().get_or_create_user_api() cls.service = BeneficiaryService(cls.user) cls.query_all = Beneficiary.objects.filter(is_deleted=False) - cls.benefit_plan = create_benefit_plan(cls.user.username) + cls.benefit_plan = create_benefit_plan(cls.user.username, payload_override={ + 'code': 'SGQLTest', + 'type': "INDIVIDUAL" + }) cls.individual = create_individual(cls.user.username) cls.payload = { **service_beneficiary_add_payload, diff --git a/social_protection/tests/group_beneficiary_service_test.py b/social_protection/tests/group_beneficiary_service_test.py index 84e4ceb..2c05315 100644 --- a/social_protection/tests/group_beneficiary_service_test.py +++ b/social_protection/tests/group_beneficiary_service_test.py @@ -11,6 +11,7 @@ ) from core.test_helpers import LogInHelper from social_protection.tests.test_helpers import create_benefit_plan +from datetime import datetime class GroupBeneficiaryServiceTest(TestCase): @@ -25,8 +26,10 @@ def setUpClass(cls): cls.user = LogInHelper().get_or_create_user_api() cls.service = GroupBeneficiaryService(cls.user) cls.query_all = GroupBeneficiary.objects.filter(is_deleted=False) - cls.benefit_plan = create_benefit_plan(cls.user.username) - cls.group = cls.__create_group() + cls.benefit_plan = create_benefit_plan(cls.user.username, payload_override={ + 'type': "GROUP" + }) + cls.group = cls.__create_group(object_data={'code': str(datetime.now())}) cls.payload = { **service_beneficiary_add_payload, "group_id": cls.group.id, @@ -65,9 +68,8 @@ def test_delete_group_beneficiary(self): self.assertEqual(query.count(), 0) @classmethod - def __create_group(cls): - object_data = {} - + def __create_group(cls, object_data={}): + group = Group(**object_data) group.save(username=cls.user.username) diff --git a/social_protection/tests/test_helpers.py b/social_protection/tests/test_helpers.py index 3a4a279..00d18e8 100644 --- a/social_protection/tests/test_helpers.py +++ b/social_protection/tests/test_helpers.py @@ -37,6 +37,7 @@ def add_individual_to_benefit_plan(service, individual, benefit_plan, payload_ov "benefit_plan_id": benefit_plan.id, "json_ext": individual.json_ext, } + benefit_plan.type = BenefitPlan.BenefitPlanType.INDIVIDUAL_TYPE updated_payload = merge_dicts(payload, payload_override) result = service.create(updated_payload) assert result.get('success', False), result.get('detail', "No details provided")