Skip to content

Commit

Permalink
Merge pull request #92 from openimis/feature/test-fix
Browse files Browse the repository at this point in the history
HotFIx
  • Loading branch information
delcroip authored Aug 15, 2024
2 parents 1a78826 + 305649d commit 04c109f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions social_protection/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion social_protection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion social_protection/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion social_protection/tests/beneficiary_gql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion social_protection/tests/beneficiary_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions social_protection/tests/group_beneficiary_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions social_protection/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 04c109f

Please sign in to comment.