Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate full model name in the deprecate model flow #427

Merged
merged 22 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gto/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def assert_name_is_valid(value):
if not check_string_is_valid(value, regex=name_re):
raise ValidationError(
f"Invalid value '{value}'. Only letters, numbers, '_', '-', '/' are allowed."
"Value must be of len >= 2 and must start and end with a letter or a number."
" Value must be of len >= 2 and must start and end with a letter or a number."
)


Expand All @@ -81,7 +81,7 @@ def assert_fullname_is_valid(value):
# fix error message to be regex-specific
raise ValidationError(
f"Invalid value '{value}'. Only letters, numbers, '_', '-', '/' are allowed."
"Value must be of len >= 2 and must start and end with a letter or a number."
" Value must be of len >= 2 and must start and end with a letter or a number."
)


Expand Down
2 changes: 2 additions & 0 deletions gto/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ def deprecate(
author: Optional[str] = None,
author_email: Optional[str] = None,
) -> Optional[Deprecation]:
"""Deprecate artifact"""
assert_fullname_is_valid(name)
if force:
if simple:
raise WrongArgs("Can't use 'force' with 'simple=True'")
Expand Down
17 changes: 16 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
import typer
import re
from packaging import version
from pytest_test_utils import TmpDir
from typer.main import get_command_from_info
Expand All @@ -18,7 +19,11 @@ def _check_output_contains(output: str, search_value: str) -> bool:


def _check_output_exact_match(output: str, search_value: str) -> bool:
return search_value == output
print("search_value: ", search_value)
print("after re.sub: ", re.sub(r"[\r\n]+", " ", search_value))
print("output: ", output)
print("after re.sub: ", re.sub(r"[\r\n]+", " ", output))
return re.sub(r"[\r\n]+", " ", search_value) == re.sub(r"[\r\n]+", " ", output)


def _check_successful_cmd(
Expand Down Expand Up @@ -348,6 +353,16 @@ def test_assign(repo_with_commit: str):
)


def test_deprecate_artifact(repo_with_commit: str):
_check_failing_cmd(
"deprecate",
["-r", repo_with_commit, "a4!"],
"❌ Invalid value 'a4!'."
" Only letters, numbers, '_', '-', '/' are allowed."
" Value must be of len >= 2 and must start and end with a letter or a number.\n",
)


GTO_EXCEPTION_MESSAGE = "Test GTOException Message"


Expand Down
Loading