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

Change warning message for illegal shortnames #434

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/datadoc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
ILLEGAL_SHORTNAME_WARNING = (
"Noen av variablene i datasetter følger ikke navnestandard for kortnavn"
)
ILLEGAL_SHORTNAME_WARNING_MESSAGE = "Følgende navnestandard er utarbeidet for variabler: Alfanumerisk begrenset til a-z, A-Z, 0-9, - (bindestrek) og (understrek). Kortnavn som ikke følger standarden:"
ILLEGAL_SHORTNAME_WARNING_MESSAGE = "Følgende navnestandard er utarbeidet for variabler: Alfanumerisk begrenset til a-z (kun små bokstaver), 0-9 og _ (understrek). Kortnavn som ikke følger standarden:"
48 changes: 32 additions & 16 deletions tests/frontend/callbacks/test_callbacks_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dash import html

from datadoc import state
from datadoc.frontend.callbacks.utils import check_variable_names
from datadoc.frontend.callbacks.utils import find_existing_language_string
from datadoc.frontend.callbacks.utils import render_tabs
from datadoc.frontend.callbacks.utils import save_metadata_and_generate_alerts
Expand Down Expand Up @@ -84,32 +85,47 @@ class Variable:

mock_metadata.variables = [
Variable(short_name="var"),
Variable(short_name="var"),
Variable(short_name="var illegal"),
]
state.metadata = mock_metadata
result = save_metadata_and_generate_alerts(
mock_metadata,
)
assert (result[1] and result[2] and result[3]) is None
assert (result[1] and result[2]) is None
assert isinstance(result[0], dbc.Alert)
assert isinstance(result[3], dbc.Alert)


def test_save_and_generate_illegal_shortname_alert():
mock_metadata = mock.Mock()
@pytest.mark.parametrize(
("shortname"),
[
("rådyr"),
("Var"),
("Var illegal"),
("V"),
],
)
def test_illegal_shortname(shortname: str):
@dataclass
class MockVariable:
short_name: str

mock_metadata = mock.Mock(variables=[MockVariable(short_name=shortname)])
assert isinstance(check_variable_names(mock_metadata.variables), dbc.Alert)


@pytest.mark.parametrize(
("shortname"),
[
("var"),
("var1"),
("var_2"),
],
)
def test_legal_shortname(shortname: str):
@dataclass
class MockVariable:
short_name: str

mock_metadata.variables = [
MockVariable(short_name="var illegal"),
MockVariable(short_name="rådyr"),
]
state.metadata = mock_metadata
result = save_metadata_and_generate_alerts(
mock_metadata,
)
assert (result[1] and result[2]) is None
assert isinstance(result[0], dbc.Alert)
assert isinstance(result[3], dbc.Alert)
assert result[3].color == "warning"
mock_metadata = mock.Mock(variables=[MockVariable(short_name=shortname)])
assert check_variable_names(mock_metadata.variables) is None
Loading