Skip to content

Commit

Permalink
remove validation from phone number fields
Browse files Browse the repository at this point in the history
  • Loading branch information
DraKen0009 committed Nov 11, 2024
1 parent f0f35eb commit a6a6ce9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 58 deletions.
9 changes: 2 additions & 7 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
from care.utils.cache.cache_allowed_facilities import get_accessible_facilities
from care.utils.filters.choicefilter import CareChoiceFilter
from care.utils.filters.multiselect import MultiSelectFilter
from care.utils.models.validators import mobile_validator
from care.utils.notification_handler import NotificationGenerator
from care.utils.queryset.patient import get_patient_notes_queryset
from config.authentication import (
Expand All @@ -107,12 +106,8 @@ class PatientFilterSet(filters.FilterSet):
field_name="facility__facility_type",
choice_dict=REVERSE_FACILITY_TYPES,
)
phone_number = filters.CharFilter(
field_name="phone_number", validators=[mobile_validator]
)
emergency_phone_number = filters.CharFilter(
field_name="emergency_phone_number", validators=[mobile_validator]
)
phone_number = filters.CharFilter(field_name="phone_number")
emergency_phone_number = filters.CharFilter(field_name="emergency_phone_number")
allow_transfer = filters.BooleanFilter(field_name="allow_transfer")
name = filters.CharFilter(
field_name="name", lookup_expr="icontains", max_length=200
Expand Down
51 changes: 0 additions & 51 deletions care/facility/tests/test_patient_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from enum import Enum
from urllib.parse import quote

from django.utils.timezone import now, timedelta
from rest_framework import status
Expand Down Expand Up @@ -858,56 +857,6 @@ def test_invalid_covin_id_param(self):
res.json()["covin_id"],
)

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

# invalid phone number (non Indian or non International)
invalid_phone_numbers = [
"9876543210",
"+9123456789",
"+915123456789",
"+9191234",
"+91765432abcd",
"00441234567890",
"+12345",
"+911234567890",
"+151234",
"+44-123-4567-890",
"+1-800-555-1212",
"+91 98765 43210",
"+91987654321000",
"+44 1234 567890",
"+123-456-7890",
"1234567890",
"+91-9876543210",
"+123456",
"+000000000000",
"+9876543210123456",
]

for phone_number in invalid_phone_numbers:
encoded_phone_number = quote(phone_number)
res = self.client.get(
self.get_base_url() + f"?phone_number={encoded_phone_number}"
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn(
f"Invalid phone number. Must be one of the following types: mobile. Received: {phone_number}",
res.json()["phone_number"],
)

for emergency_phone_number in invalid_phone_numbers:
encoded_emergency_phone_number = quote(emergency_phone_number)
res = self.client.get(
self.get_base_url()
+ f"?emergency_phone_number={encoded_emergency_phone_number}"
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn(
f"Invalid phone number. Must be one of the following types: mobile. Received: {emergency_phone_number}",
res.json()["emergency_phone_number"],
)


class DischargePatientFilterTestCase(TestUtils, APITestCase):
@classmethod
Expand Down

0 comments on commit a6a6ce9

Please sign in to comment.