Skip to content

Commit

Permalink
required reason
Browse files Browse the repository at this point in the history
  • Loading branch information
abarolo authored and abarolo committed Feb 25, 2025
1 parent 06196a1 commit 8edec22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/barriers/serializers/estimated_resolution_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def get_created_by(self, obj):


class CreateERDRequestSerializer(ERDRequestSerializer):
reason = serializers.CharField(required=True)

def validate(self, data):
"""
Check that the start is before the stop.
Expand Down
15 changes: 15 additions & 0 deletions tests/barriers/test_estimated_resolution_date_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def test_create_erd_request_no_date_201(self):
assert not barrier.get_active_erd_request()
assert barrier.estimated_resolution_date == data["estimated_resolution_date"]

def test_create_erd_request_no_reason_201(self):
barrier = BarrierFactory(estimated_resolution_date=None)
url = reverse(
"estimated-resolution-date-request", kwargs={"barrier_id": barrier.id}
)
data = {
"estimated_resolution_date": datetime.date.today() + timedelta(days=31),
}

response = self.api_client.post(url, data=data, format="json")

barrier.refresh_from_db()
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {'reason': ['This field is required.']}

def test_create_erd_has_existing_erd_request(self):
barrier = BarrierFactory(estimated_resolution_date=datetime.date.today())
EstimatedResolutionDateRequest.objects.create(
Expand Down

0 comments on commit 8edec22

Please sign in to comment.