Skip to content

Commit

Permalink
Add validation test for deprecate local unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rup-Narayan-Rajbanshi committed Dec 11, 2024
1 parent 79aa205 commit b9a0c18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions local_units/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ class Meta:

def validate(self, attrs):
instance = self.instance
if instance and instance.is_deprecated and attrs.get("is_deprecated", False):
if instance and instance.is_deprecated:
raise serializers.ValidationError("This object is already deprecated.")

if attrs.get("is_deprecated", False) and not attrs.get("deprecated_reason"):
if not attrs.get("deprecated_reason"):
raise serializers.ValidationError("A reason must be provided when deprecating an object.")

return attrs
Expand Down
4 changes: 4 additions & 0 deletions local_units/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def test_deprecate_local_unit(self):
self.assertEqual(local_unit_obj.is_deprecated, True)
self.assertEqual(local_unit_obj.deprecated_reason, LocalUnit.DeprecateReason.INCORRECTLY_ADDED)

# Test for validation
response = self.client.post(url, data=data)
self.assert_400(response)

# test revert deprecate
data = {}
url = f"/api/v2/local-units/{local_unit_obj.id}/revert-deprecate/"
Expand Down

0 comments on commit b9a0c18

Please sign in to comment.