Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for loan dref type in final report #2049

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)