Skip to content

Commit

Permalink
une[pected change of task, delete name validation and change of key v…
Browse files Browse the repository at this point in the history
…alidation to only english with underscore
  • Loading branch information
v.khadyev committed Jan 11, 2024
1 parent 39bed8e commit 3ba9d44
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
4 changes: 1 addition & 3 deletions overhave/admin/views/testing_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions tests/unit/admin/test_testing_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3ba9d44

Please sign in to comment.