Skip to content

Commit

Permalink
Add validation for loan dref type in final report
Browse files Browse the repository at this point in the history
  • Loading branch information
k9845 committed Feb 26, 2024
1 parent 2ab1b27 commit 1ff471d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dref/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ def validate_photos(self, photos):
raise serializers.ValidationError("Can add utmost %s photos" % self.MAX_NUMBER_OF_PHOTOS)
return photos

def validate_type_of_dref(self, type_of_dref):
if self.instance and self.instance.type_of_dref == Dref.DrefType.LOAN:
raise serializers.ValidationError("Can't change dref type for %s in Final Report" % Dref.DrefType.LOAN)
return type_of_dref

def create(self, validated_data):
# here check if there is operational update for corresponding dref
# if yes copy from the latest operational update
Expand Down
24 changes: 24 additions & 0 deletions dref/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,3 +1309,27 @@ def test_dref_share_users(self):
set(response.data['results'][0]['users']),
set([user2.id, user3.id, user4.id])
)

def test_dref_final_report_change_for_loan_type(self):
country_1 = Country.objects.create(name="country1")
dref = DrefFactory.create(
is_published=True,
type_of_dref=Dref.DrefType.LOAN,
country=country_1,
created_by=self.root_user
)
final_report = DrefFinalReportFactory.create(
is_published=False,
country=country_1,
type_of_dref=Dref.DrefType.LOAN,
dref=dref,
created_by=self.root_user
)
url = f"/api/v2/dref-final-report/{final_report.id}/"
data = {
"type_of_dref": Dref.DrefType.ASSESSMENT,
"modified_at": datetime.now() + timedelta(days=1)
}
self.authenticate(self.root_user)
response = self.client.patch(url, data=data)
self.assertEqual(response.status_code, 400)

0 comments on commit 1ff471d

Please sign in to comment.