-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat phone numbers in the contact form
- Loading branch information
Showing
5 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -982,7 +982,7 @@ | |
"name": "Martina Musterfrau", | ||
"location": 6, | ||
"email": "[email protected]", | ||
"phone_number": "0123456789", | ||
"phone_number": "+49 (0) 123456789", | ||
"website": "", | ||
"archived": false, | ||
"last_updated": "2024-08-06T13:23:45.256Z", | ||
|
@@ -1012,7 +1012,7 @@ | |
"name": "Mariana Musterfrau", | ||
"location": 6, | ||
"email": "[email protected]", | ||
"phone_number": "0123456789", | ||
"phone_number": "+49 (0) 123456789", | ||
"website": "https://integreat-app.de/", | ||
"archived": false, | ||
"last_updated": "2024-08-06T13:23:45.256Z", | ||
|
@@ -1027,7 +1027,7 @@ | |
"name": "", | ||
"location": 6, | ||
"email": "[email protected]", | ||
"phone_number": "0123456789", | ||
"phone_number": "+49 (0) 123456789", | ||
"website": "https://integreat-app.de/", | ||
"archived": false, | ||
"last_updated": "2024-08-06T13:23:45.256Z", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import pytest | ||
from django.urls import reverse | ||
|
||
from integreat_cms.cms.forms import ContactForm | ||
from integreat_cms.cms.models import Contact, Region | ||
from tests.conftest import ANONYMOUS, HIGH_PRIV_STAFF_ROLES | ||
from tests.utils import assert_message_in_log | ||
|
@@ -287,3 +288,37 @@ def test_one_primary_contact_per_poi( | |
) | ||
else: | ||
assert response.status_code == 403 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_phone_number_conversion() -> None: | ||
""" | ||
Test that phone numbers are converted to the expected international format. | ||
""" | ||
variants = [ | ||
"+49123456789", | ||
"0123456789", | ||
"012 34/56789", | ||
"01234-56789", | ||
"0049123456789", | ||
"00 (49) (1234) 56789", | ||
" +49/1234-56789", | ||
] | ||
for variant in variants: | ||
form_data = { | ||
"location": POI_ID, | ||
"point_of_contact_for": "test", | ||
"name": "", | ||
"email": "[email protected]", | ||
"phone_number": variant, | ||
"website": "https://integreat-app.de/", | ||
} | ||
|
||
form = ContactForm( | ||
data=form_data, | ||
instance=None, | ||
additional_instance_attributes={"region": REGION_SLUG}, | ||
) | ||
form.is_valid() # this is not an assert, because it would fail. calling is_valid() is required to populate cleaned_data. | ||
cleaned = form.clean() | ||
assert cleaned["phone_number"] == "+49 (0) 123456789" |