Skip to content

Commit

Permalink
bug/LGA-3278 fix property eligibility check (#1246)
Browse files Browse the repository at this point in the history
* 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 <ben.millar@digital.justice.gov.uk>
  • Loading branch information
TawneeOwl and BenMillar-MOJ authored Oct 16, 2024
1 parent 00b792e commit 6abd828
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions cla_backend/apps/call_centre/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6abd828

Please sign in to comment.