diff --git a/tests/backend/__init__.py b/tests/backend/__init__.py new file mode 100644 index 00000000..73cc186f --- /dev/null +++ b/tests/backend/__init__.py @@ -0,0 +1 @@ +"""Unit tests for backend Datadoc.""" diff --git a/tests/test_datadoc_metadata.py b/tests/backend/test_datadoc_metadata.py similarity index 92% rename from tests/test_datadoc_metadata.py rename to tests/backend/test_datadoc_metadata.py index 24a1dc04..00ba3f79 100644 --- a/tests/test_datadoc_metadata.py +++ b/tests/backend/test_datadoc_metadata.py @@ -19,11 +19,10 @@ from datadoc.enums import DatasetState from datadoc.enums import DataType from datadoc.enums import VariableRole - -from .utils import TEST_EXISTING_METADATA_DIRECTORY -from .utils import TEST_EXISTING_METADATA_FILE_NAME -from .utils import TEST_PARQUET_FILEPATH -from .utils import TEST_RESOURCES_DIRECTORY +from tests.utils import TEST_EXISTING_METADATA_DIRECTORY +from tests.utils import TEST_EXISTING_METADATA_FILE_NAME +from tests.utils import TEST_PARQUET_FILEPATH +from tests.utils import TEST_RESOURCES_DIRECTORY if TYPE_CHECKING: from datetime import datetime @@ -201,3 +200,13 @@ def test_variable_role_default_value(metadata: DataDocMetadata): def test_direct_person_identifying_default_value(metadata: DataDocMetadata): assert all(not v.direct_person_identifying for v in metadata.meta.variables) + + +def test_save_file_path_metadata_field( + existing_metadata_file: str, + metadata: DataDocMetadata, +): + metadata.write_metadata_document() + with Path.open(Path(existing_metadata_file)) as f: + saved_file_path = json.load(f)["datadoc"]["dataset"]["file_path"] + assert saved_file_path == str(metadata.dataset) diff --git a/tests/test_dataset_parser.py b/tests/backend/test_dataset_parser.py similarity index 96% rename from tests/test_dataset_parser.py rename to tests/backend/test_dataset_parser.py index 580595bf..4c325696 100644 --- a/tests/test_dataset_parser.py +++ b/tests/backend/test_dataset_parser.py @@ -16,10 +16,9 @@ from datadoc.backend.dataset_parser import DatasetParserParquet from datadoc.enums import DataType from datadoc.enums import SupportedLanguages - -from .utils import TEST_PARQUET_FILEPATH -from .utils import TEST_PARQUET_GZIP_FILEPATH -from .utils import TEST_SAS7BDAT_FILEPATH +from tests.utils import TEST_PARQUET_FILEPATH +from tests.utils import TEST_PARQUET_GZIP_FILEPATH +from tests.utils import TEST_SAS7BDAT_FILEPATH def test_use_abstract_class_directly(): diff --git a/tests/test_model_backwards_compatibility.py b/tests/backend/test_model_backwards_compatibility.py similarity index 96% rename from tests/test_model_backwards_compatibility.py rename to tests/backend/test_model_backwards_compatibility.py index 264f63d6..688cd51d 100644 --- a/tests/test_model_backwards_compatibility.py +++ b/tests/backend/test_model_backwards_compatibility.py @@ -8,8 +8,7 @@ from datadoc.backend.datadoc_metadata import DataDocMetadata from datadoc.backend.model_backwards_compatibility import UnknownModelVersionError from datadoc.backend.model_backwards_compatibility import upgrade_metadata - -from .utils import TEST_COMPATIBILITY_DIRECTORY +from datadoc.utils import TEST_COMPATIBILITY_DIRECTORY BACKWARDS_COMPATIBLE_VERSION_DIRECTORIES = [ d for d in TEST_COMPATIBILITY_DIRECTORY.iterdir() if d.is_dir() diff --git a/tests/test_storage_adapter.py b/tests/backend/test_storage_adapter.py similarity index 100% rename from tests/test_storage_adapter.py rename to tests/backend/test_storage_adapter.py diff --git a/tests/resources/person_data_v1__DOC.json b/tests/resources/person_data_v1__DOC.json new file mode 100644 index 00000000..ddc52891 --- /dev/null +++ b/tests/resources/person_data_v1__DOC.json @@ -0,0 +1,257 @@ +{ + "document_version": "0.0.1", + "datadoc": { + "percentage_complete": 98, + "document_version": "2.0.0", + "dataset": { + "short_name": "person_data_v1", + "assessment": "SENSITIVE", + "dataset_status": "DRAFT", + "dataset_state": "PROCESSED_DATA", + "name": { + "en": "successfully_read_existing_file", + "nn": "", + "nb": "Persondata" + }, + "description": { + "en": "", + "nn": "", + "nb": "" + }, + "data_source": { + "en": "", + "nn": "", + "nb": "Skatteetaten" + }, + "register_uri": null, + "population_description": { + "en": "", + "nn": "", + "nb": "Norsk befolkning" + }, + "version": "1", + "version_description": null, + "unit_type": "PERSON", + "temporality_type": "STATUS", + "subject_field": { + "en": "", + "nn": "", + "nb": "Skatt" + }, + "keyword": [ + "Skatt", + "Person", + "Helsepenger" + ], + "spatial_coverage_description": { + "en": "", + "nn": "", + "nb": "Norge" + }, + "id": "143fca77-ef56-419c-a1e1-d69c4199f020", + "owner": null, + "file_path": null, + "metadata_created_date": "2022-09-05T11:07:14Z", + "metadata_created_by": "default_user@ssb.no", + "metadata_last_updated_date": "2022-01-01T00:00:00Z", + "metadata_last_updated_by": "default_user@ssb.no", + "contains_data_from": "2010-09-05", + "contains_data_until": "2022-09-05" + }, + "variables": [ + { + "short_name": "pers_id", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "STRING", + "variable_role": "IDENTIFIER", + "definition_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/26/nb", + "direct_person_identifying": true, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "tidspunkt", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "DATETIME", + "variable_role": "START_TIME", + "definition_uri": null, + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "sivilstand", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "STRING", + "variable_role": "MEASURE", + "definition_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/91/nb", + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "alm_inntekt", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "INTEGER", + "variable_role": "MEASURE", + "definition_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1438/nb", + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "sykepenger", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "INTEGER", + "variable_role": "MEASURE", + "definition_uri": "https://www.ssb.no/metadata/conceptvariable/vardok/3366/nb", + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "ber_bruttoformue", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "INTEGER", + "variable_role": "MEASURE", + "definition_uri": "https://www.ssb.no/metadata/conceptvariable/vardok/3327/nb", + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "fullf_utdanning", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "STRING", + "variable_role": "MEASURE", + "definition_uri": "https://www.ssb.no/metadata/conceptvariable/vardok/3242/nb", + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + }, + { + "short_name": "hoveddiagnose", + "name": { + "en": "", + "nn": "", + "nb": "g" + }, + "data_type": "STRING", + "variable_role": "MEASURE", + "definition_uri": "https://www.ssb.no/metadata/conceptvariable/vardok/2578/nb", + "direct_person_identifying": false, + "data_source": null, + "population_description": null, + "comment": null, + "temporality_type": null, + "measurement_unit": null, + "format": null, + "classification_uri": null, + "sentinel_value_uri": null, + "invalid_value_description": null, + "id": null, + "contains_data_from": null, + "contains_data_until": null + } + ] + }, + "pseudonymization": null +}