From 3ba9d449ee2f956e411ee9342a614075754bc8f6 Mon Sep 17 00:00:00 2001 From: "v.khadyev" Date: Thu, 11 Jan 2024 11:54:39 +0500 Subject: [PATCH] une[pected change of task, delete name validation and change of key validation to only english with underscore --- overhave/admin/views/testing_users.py | 4 +--- tests/unit/admin/test_testing_users.py | 13 ------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/overhave/admin/views/testing_users.py b/overhave/admin/views/testing_users.py index b705bd3f..880ba263 100644 --- a/overhave/admin/views/testing_users.py +++ b/overhave/admin/views/testing_users.py @@ -51,7 +51,7 @@ class TestUserView(ModelViewConfigured): _feature_type: FeatureTypeName | None = None - _allowed_symbols = r"\w*" + _allowed_symbols = r"[a-zA-Z_]*" def on_form_prefill(self, form: Form, id) -> None: # type: ignore # noqa: A002 if not isinstance(form._obj, db.TestUser): @@ -81,8 +81,6 @@ def _validate_json(model: db.TestUser) -> None: raise ValidationError(f"Could not convert specified data into {parser.__name__} model!") def on_model_change(self, form: Form, model: db.TestUser, is_created: bool) -> None: - if model.name is not None and not fullmatch(self._allowed_symbols, model.name): - raise ValidationError("Name should contain only characters, digits or underscore!") if model.key is not None and not fullmatch(self._allowed_symbols, model.key): raise ValidationError("Key should contain only characters, digits or underscore!") self._feature_type = cast(FeatureTypeName, model.feature_type.name) diff --git a/tests/unit/admin/test_testing_users.py b/tests/unit/admin/test_testing_users.py index 2804015e..75179a89 100644 --- a/tests/unit/admin/test_testing_users.py +++ b/tests/unit/admin/test_testing_users.py @@ -47,19 +47,6 @@ def test_incorrect_model_raises_error( with pytest.raises(ValidationError): test_testing_user_view.on_model_change(form=form_mock, model=db_test_user, is_created=test_is_created) - @pytest.mark.parametrize("user_role", [db.Role.user, db.Role.admin], indirect=True) - @pytest.mark.parametrize("test_is_created", [False, True]) - def test_name_with_spaces_for_model_raises_errors( - self, - test_testing_user_view: TestUserView, - current_user_mock: mock.MagicMock, - form_mock: mock.MagicMock, - test_is_created: bool, - ) -> None: - db_test_user = db.TestUser(name="kek kek") - with pytest.raises(ValidationError): - test_testing_user_view.on_model_change(form=form_mock, model=db_test_user, is_created=test_is_created) - @pytest.mark.parametrize("user_role", [db.Role.user, db.Role.admin], indirect=True) @pytest.mark.parametrize("test_is_created", [False, True]) def test_key_with_spaces_for_model_raises_errors(