Skip to content

Commit

Permalink
Added link and unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
JanhSander committed Apr 5, 2024
1 parent eeb802b commit d98f0e8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/datadoc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ def get_unit_code() -> int | None:
def get_organisational_unit_code() -> int | None:
"""The code for the organisational units code list in Klass."""
return int(_get_config_item("DATADOC_ORGANISATIONAL_UNIT_CODE") or 83)


def get_dapla_manual_naming_standard_url() -> str | None:
"""Get the URL to naming standard in the DAPLA manual."""
return _get_config_item("DAPLA_MANUAL_NAMING_STANDARD_URL")
8 changes: 1 addition & 7 deletions src/datadoc/frontend/callbacks/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ def open_dataset_handling(
if n_clicks and n_clicks > 0:
dapla_dataset_path_info = DaplaDatasetPathInfo(file_path)
if not dapla_dataset_path_info.path_complies_with_naming_standard():
return (
True,
False,
True,
"",
state.current_metadata_language.value,
)
return (True, False, True, "", state.current_metadata_language.value)
return True, False, False, "", state.current_metadata_language.value
# no message
return False, False, False, "", state.current_metadata_language.value
Expand Down
4 changes: 3 additions & 1 deletion src/datadoc/frontend/components/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from datadoc.config import get_dapla_manual_naming_standard_url
from datadoc.frontend.components.builders import AlertTypes
from datadoc.frontend.components.builders import build_ssb_alert

Expand Down Expand Up @@ -43,6 +44,7 @@
naming_convention_warning = build_ssb_alert(
AlertTypes.WARNING,
"opened-dataset_warning",
"Filen følger ikke navnestandard",
"Filen følger ikke navnestandard. Vennlist se",
"opened-dataset-warning-explanation",
link=get_dapla_manual_naming_standard_url(),
)
2 changes: 2 additions & 0 deletions src/datadoc/frontend/components/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def build_ssb_alert( # noqa: PLR0913 not immediately obvious how to improve thi
message: str | None = None,
*,
start_open: bool = False,
link: str | None = None,
) -> dbc.Alert:
"""Make a Dash Alert according to SSBs Design System."""
alert = AlertType.get_type(alert_type)
Expand All @@ -96,6 +97,7 @@ def build_ssb_alert( # noqa: PLR0913 not immediately obvious how to improve thi
id=content_identifier,
children=message,
),
html.A(link, href=link, target="_blank"),
],
style={"width": "70%"},
)
Expand Down
40 changes: 34 additions & 6 deletions tests/frontend/callbacks/test_dataset_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def file_path():
return "valid/path/to/file.json"


@pytest.fixture()
def file_path_without_dates():
return "valid/path/to/person_data_v1.parquet"


@pytest.mark.parametrize(
("metadata_identifier", "provided_value", "expected_model_value"),
[
Expand Down Expand Up @@ -278,13 +283,13 @@ def test_open_dataset_handling_normal(
):
state.current_metadata_language = SupportedLanguages.ENGLISH

opened, show_error, error_msg, language = open_dataset_handling(
opened, show_error, naming_standard, error_msg, language = open_dataset_handling(
n_clicks_1,
file_path,
)

assert opened
assert not show_error
assert naming_standard
assert error_msg == ""
assert language == "en"

Expand All @@ -298,12 +303,13 @@ def test_open_dataset_handling_file_not_found(
state.current_metadata_language = SupportedLanguages.ENGLISH
open_file_mock.side_effect = FileNotFoundError()

opened, show_error, error_msg, language = open_dataset_handling(
opened, show_error, naming_standard, error_msg, language = open_dataset_handling(
n_clicks_1,
file_path,
)
assert not opened
assert show_error
assert not naming_standard
assert error_msg.startswith(f"Filen '{file_path}' finnes ikke.")
assert language == "en"

Expand All @@ -317,12 +323,13 @@ def test_open_dataset_handling_general_exception(
state.current_metadata_language = SupportedLanguages.ENGLISH
open_file_mock.side_effect = ValueError()

opened, show_error, error_msg, language = open_dataset_handling(
opened, show_error, naming_standard, error_msg, language = open_dataset_handling(
n_clicks_1,
file_path,
)
assert not opened
assert show_error
assert not naming_standard
assert error_msg.startswith("ValueError")
assert language == "en"

Expand All @@ -333,10 +340,31 @@ def test_open_dataset_handling_no_click(
file_path: str,
):
state.current_metadata_language = SupportedLanguages.ENGLISH
opened, show_error, error_msg, language = open_dataset_handling(0, file_path)

opened, show_error, naming_standard, error_msg, language = open_dataset_handling(
0,
file_path,
)
assert not opened
assert not show_error
assert not naming_standard
assert error_msg == ""
assert language == "en"


@patch(f"{DATASET_CALLBACKS_MODULE}.open_file")
def test_open_dataset_handling_naming_standard(
open_file_mock: Mock, # noqa: ARG001
n_clicks_1: int,
file_path_without_dates: str,
):
state.current_metadata_language = SupportedLanguages.ENGLISH
opened, show_error, naming_standard, error_msg, language = open_dataset_handling(
n_clicks_1,
file_path_without_dates,
)
assert opened is True
assert not show_error
assert naming_standard
assert error_msg == ""
assert language == "en"

Expand Down

0 comments on commit d98f0e8

Please sign in to comment.