From 6abd8283861f052b6425f8978db2b2135818139b Mon Sep 17 00:00:00 2001 From: Kyle O'Brien <65071578+TawneeOwl@users.noreply.github.com> Date: Wed, 16 Oct 2024 08:43:16 +0100 Subject: [PATCH] bug/LGA-3278 fix property eligibility check (#1246) * Update serializers * Remove main * Update serializer * Change to float * Add main and disputed to serializers * Add validator * Linting * Add whitespace * remove base serializer * Fix the main property * Amend tests --------- Co-authored-by: Ben Millar --- cla_backend/apps/call_centre/serializers.py | 15 +++++++++++++++ .../tests/views/mixins/eligibility_check_api.py | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cla_backend/apps/call_centre/serializers.py b/cla_backend/apps/call_centre/serializers.py index 2d9518864..8854d0c5d 100644 --- a/cla_backend/apps/call_centre/serializers.py +++ b/cla_backend/apps/call_centre/serializers.py @@ -196,6 +196,21 @@ class Meta(EODDetailsSerializerBase.Meta): class EligibilityCheckSerializer(EligibilityCheckSerializerBase): + def validate_property_set(self, value): + property_item = super(EligibilityCheckSerializer, self).validate_property_set(value) + # Iterate through each item (property) in the property_set list + for property_item in value: + if property_item.get('value') is None: + raise serializers.ValidationError("Property 'value' cannot be null.") + if property_item.get('mortgage_left') is None: + raise serializers.ValidationError("Property 'mortgage_left' cannot be null.") + if property_item.get('share') is None: + raise serializers.ValidationError("Property 'share' cannot be null.") + if property_item.get('disputed') is None: + raise serializers.ValidationError("Property 'disputed' cannot be null.") + if property_item.get('main') is None: + raise serializers.ValidationError("Property 'main' cannot be null.") + return value property_set = PropertySerializer(many=True, required=False) you = PersonSerializer(required=False, allow_null=True) partner = PartnerPersonSerializer(required=False, allow_null=True) diff --git a/cla_backend/apps/legalaid/tests/views/mixins/eligibility_check_api.py b/cla_backend/apps/legalaid/tests/views/mixins/eligibility_check_api.py index c933f9155..dadc33723 100644 --- a/cla_backend/apps/legalaid/tests/views/mixins/eligibility_check_api.py +++ b/cla_backend/apps/legalaid/tests/views/mixins/eligibility_check_api.py @@ -742,7 +742,7 @@ def test_patch_properties(self): """ PATCH should add/remove/change properties. """ - properties = make_recipe("legalaid.property", eligibility_check=self.resource, _quantity=4, disputed=False) + properties = make_recipe("legalaid.property", eligibility_check=self.resource, _quantity=4, disputed=False, main=False) # making extra properties not associated to this eligibility check make_recipe("legalaid.property", _quantity=5) @@ -753,8 +753,8 @@ def test_patch_properties(self): # an extra one data = { "property_set": [ - {"value": 111, "mortgage_left": 222, "share": 33, "id": properties[0].id, "disputed": True}, - {"value": 999, "mortgage_left": 888, "share": 77, "disputed": True}, + {"value": 111, "mortgage_left": 222, "share": 33, "id": properties[0].id, "disputed": True, "main": False}, + {"value": 999, "mortgage_left": 888, "share": 77, "disputed": True, "main": False}, ] } response = self.client.patch( @@ -1114,7 +1114,7 @@ def test_others_property_cannot_be_set(self): """ other_property = make_recipe("legalaid.property") data = { - "property_set": [{"value": 0, "mortgage_left": 0, "share": 0, "id": other_property.pk, "disputed": False}] + "property_set": [{"value": 0, "mortgage_left": 0, "share": 0, "id": other_property.pk, "disputed": False, "main": False}] } response = self.client.patch( self.detail_url, data, format="json", HTTP_AUTHORIZATION=self.get_http_authorization()