Skip to content

Commit

Permalink
improved test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
DraKen0009 committed Nov 10, 2024
1 parent 99e69c2 commit 26c4c6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ class PatientFilterSet(filters.FilterSet):
field_name="name", lookup_expr="icontains", max_length=200
)
patient_no = filters.CharFilter(
field_name=f"{last_consultation_field}__patient_no", lookup_expr="iexact"
field_name=f"{last_consultation_field}__patient_no",
lookup_expr="iexact",
max_length=100,
)
gender = filters.ChoiceFilter(field_name="gender", choices=GENDER_CHOICES)
age = filters.NumberFilter(field_name="age", validators=[MinValueValidator(0)])
Expand Down
11 changes: 11 additions & 0 deletions care/facility/tests/test_patient_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,17 @@ def test_filter_by_invalid_params(self):
res.json()["state_name"],
)

# invalid patient no value > 100
invalid_patient_no_param = "A" * 101
res = self.client.get(
self.get_base_url() + f"?patient_no={invalid_patient_no_param}"
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn(
"Ensure this value has at most 100 characters (it has 101).",
res.json()["patient_no"],
)

def test_invalid_phone_params(self):
self.client.force_authenticate(user=self.user)

Expand Down

0 comments on commit 26c4c6a

Please sign in to comment.