Skip to content

Commit bb6415c

Browse files
committed
splits tests
1 parent 95f2a4e commit bb6415c

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _validate_user_name(cls, value: str):
169169

170170
# Ensure it doesn't end with a special character
171171
if {value[0], value[-1]}.intersection({"_", "-", "."}):
172-
msg = f"Username '{value}' cannot end or start with a special character."
172+
msg = f"Username '{value}' cannot end with a special character."
173173
raise ValueError(msg)
174174

175175
# Check reserved words (example list; extend as needed)

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,56 @@ def test_mapping_update_models_from_rest_to_db():
187187
}
188188

189189

190-
def test_my_profile_patch_username_validation():
190+
def test_my_profile_patch_username_min_len():
191191
# minimum length username is 4
192192
with pytest.raises(ValidationError) as err_info:
193193
MyProfilePatch.model_validate({"userName": "abc"})
194194

195195
assert err_info.value.error_count() == 1
196196
assert err_info.value.errors()[0]["type"] == "too_short"
197197

198-
MyProfilePatch.model_validate({"userName": "abcd"})
198+
MyProfilePatch.model_validate({"userName": "abcd"}) # OK
199199

200+
201+
def test_my_profile_patch_username_valid_characters():
200202
# Ensure valid characters (alphanumeric + . _ -)
201203
with pytest.raises(ValidationError, match="start with a letter") as err_info:
202204
MyProfilePatch.model_validate({"userName": "1234"})
203205

204206
assert err_info.value.error_count() == 1
205207
assert err_info.value.errors()[0]["type"] == "value_error"
206208

207-
MyProfilePatch.model_validate({"userName": "u1234"})
209+
MyProfilePatch.model_validate({"userName": "u1234"}) # OK
210+
211+
212+
def test_my_profile_patch_username_special_characters():
213+
# Ensure no consecutive special characters
214+
with pytest.raises(
215+
ValidationError, match="consecutive special characters"
216+
) as err_info:
217+
MyProfilePatch.model_validate({"userName": "u1__234"})
218+
219+
assert err_info.value.error_count() == 1
220+
assert err_info.value.errors()[0]["type"] == "value_error"
221+
222+
MyProfilePatch.model_validate({"userName": "u1_234"}) # OK
223+
224+
# Ensure it doesn't end with a special character
225+
with pytest.raises(ValidationError, match="end with") as err_info:
226+
MyProfilePatch.model_validate({"userName": "u1234_"})
227+
228+
assert err_info.value.error_count() == 1
229+
assert err_info.value.errors()[0]["type"] == "value_error"
230+
231+
MyProfilePatch.model_validate({"userName": "u1_234"}) # OK
232+
233+
234+
def test_my_profile_patch_username_reserved_words():
235+
# Check reserved words (example list; extend as needed)
236+
with pytest.raises(ValidationError, match="cannot be used") as err_info:
237+
MyProfilePatch.model_validate({"userName": "admin"})
238+
239+
assert err_info.value.error_count() == 1
240+
assert err_info.value.errors()[0]["type"] == "value_error"
241+
242+
MyProfilePatch.model_validate({"userName": "midas"}) # OK

0 commit comments

Comments
 (0)