Skip to content

Commit 448f37a

Browse files
committed
fixes phones
1 parent f882ba8 commit 448f37a

File tree

5 files changed

+59
-38
lines changed

5 files changed

+59
-38
lines changed

packages/models-library/src/models_library/api_schemas_webserver/auth.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from models_library.rest_base import RequestParameters
66
from pydantic import AliasGenerator, ConfigDict, Field, HttpUrl, SecretStr
77
from pydantic.alias_generators import to_camel
8+
from pydantic.config import JsonDict
89

910
from ..emails import LowerCaseEmailStr
1011
from ._base import InputSchema, OutputSchema
@@ -14,33 +15,39 @@ class AccountRequestInfo(InputSchema):
1415
form: dict[str, Any]
1516
captcha: str
1617

18+
@staticmethod
19+
def _update_json_schema_extra(schema: JsonDict) -> None:
20+
schema.update(
21+
{
22+
"example": {
23+
"form": {
24+
"firstName": "James",
25+
"lastName": "Maxwel",
26+
"email": "[email protected]",
27+
"phone": "+41 44 245 96 96",
28+
"company": "EM Com",
29+
"address": "Infinite Loop",
30+
"city": "Washington",
31+
"postalCode": "98001",
32+
"country": "Switzerland",
33+
"application": "Antenna_Design",
34+
"description": "Description of something",
35+
"hear": "Search_Engine",
36+
"privacyPolicy": True,
37+
"eula": True,
38+
},
39+
"captcha": "A12B34",
40+
}
41+
}
42+
)
43+
1744
model_config = ConfigDict(
1845
str_strip_whitespace=True,
1946
str_max_length=200,
2047
# NOTE: this is just informative. The format of the form is defined
2148
# currently in the front-end and it might change
2249
# SEE image in https://github.com/ITISFoundation/osparc-simcore/pull/5378
23-
json_schema_extra={
24-
"example": {
25-
"form": {
26-
"firstName": "James",
27-
"lastName": "Maxwel",
28-
"email": "[email protected]",
29-
"phone": "+1 123456789",
30-
"company": "EM Com",
31-
"address": "Infinite Loop",
32-
"city": "Washington",
33-
"postalCode": "98001",
34-
"country": "USA",
35-
"application": "Antenna_Design",
36-
"description": "Description of something",
37-
"hear": "Search_Engine",
38-
"privacyPolicy": True,
39-
"eula": True,
40-
},
41-
"captcha": "A12B34",
42-
}
43-
},
50+
json_schema_extra=_update_json_schema_extra,
4451
)
4552

4653

services/web/server/tests/unit/isolated/test_models.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,37 @@
1414
PhoneNumberStr,
1515
)
1616

17-
multiple_format_valid_phone_numbers = [
18-
"+41763456789",
19-
"+19104630364",
20-
"+1 301-304-4567",
21-
] + [
22-
# tests hand-made random_phone_number
23-
# WARNING: keed constant since pytest-xdist will run this test in parallel
24-
random_phone_number(Faker(seed=42))
25-
for _ in range(6)
26-
]
27-
28-
29-
@pytest.mark.parametrize("phone", multiple_format_valid_phone_numbers)
17+
18+
@pytest.mark.parametrize(
19+
"phone",
20+
[
21+
"+41763456789",
22+
"+19104630364",
23+
"+1 301-304-4567",
24+
"+41763456686",
25+
"+19104630873",
26+
"+19104630424",
27+
"+34 950 453 772",
28+
"+19104630700",
29+
"+13013044719",
30+
],
31+
)
3032
def test_valid_phone_numbers(phone: str):
3133
# This test is used to tune options of PhoneNumberValidator
3234
assert MyPhoneRegister.model_validate({"phone": phone}).phone == TypeAdapter(
3335
PhoneNumberStr
3436
).validate_python(phone)
3537

3638

39+
def test_random_phone_number():
40+
# This test is used to tune options of PhoneNumberValidator
41+
for _ in range(10):
42+
phone = random_phone_number(Faker(seed=42))
43+
assert MyPhoneRegister.model_validate({"phone": phone}).phone == TypeAdapter(
44+
PhoneNumberStr
45+
).validate_python(phone)
46+
47+
3748
@pytest.mark.parametrize(
3849
"phone",
3950
[

services/web/server/tests/unit/with_dbs/03/login/test_login_change_password.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async def test_wrong_confirm_pass(client: TestClient, new_password: str):
9090
"field": "confirm",
9191
}
9292
],
93+
"message": "Invalid field/s 'confirm' in request body",
9394
}
9495

9596

services/web/server/tests/unit/with_dbs/03/login/test_login_registration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ async def test_register_body_validation(
107107
"field": "confirm",
108108
},
109109
],
110+
"message": "Invalid field/s 'email, confirm' in request body",
110111
}
111112

112113

services/web/server/tests/unit/with_dbs/03/test_users_rest_profiles.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ async def test_phone_registration_basic_workflow(
602602
user_role: UserRole,
603603
logged_user: UserInfoDict,
604604
client: TestClient,
605-
user_phone_number: PhoneNumberStr,
606605
):
607606
assert client.app
608607

@@ -613,9 +612,11 @@ async def test_phone_registration_basic_workflow(
613612

614613
initial_profile = MyProfileRestGet.model_validate(data)
615614
initial_phone = initial_profile.phone
615+
assert initial_phone
616616

617617
# REGISTER phone number
618-
new_phone = user_phone_number
618+
# Change the last 3 digits of the initial phone number to '999'
619+
new_phone = f"{initial_phone[:-3]}999"
619620
url = client.app.router["my_phone_register"].url_for()
620621
resp = await client.post(
621622
f"{url}",
@@ -658,7 +659,6 @@ async def test_phone_registration_workflow(
658659
user_role: UserRole,
659660
logged_user: UserInfoDict,
660661
client: TestClient,
661-
user_phone_number: PhoneNumberStr,
662662
):
663663
assert client.app
664664

@@ -669,9 +669,10 @@ async def test_phone_registration_workflow(
669669

670670
initial_profile = MyProfileRestGet.model_validate(data)
671671
initial_phone = initial_profile.phone
672+
assert initial_phone
672673

673674
# STEP 1: REGISTER phone number
674-
new_phone = user_phone_number
675+
new_phone = f"{initial_phone[:-3]}999" # Change the last 3 digits to '999'
675676
url = client.app.router["my_phone_register"].url_for()
676677
resp = await client.post(
677678
f"{url}",

0 commit comments

Comments
 (0)