diff --git a/src/datadoc/backend/datadoc_metadata.py b/src/datadoc/backend/datadoc_metadata.py index 427f4ff3..82ed37b6 100644 --- a/src/datadoc/backend/datadoc_metadata.py +++ b/src/datadoc/backend/datadoc_metadata.py @@ -233,7 +233,7 @@ def write_metadata_document(self) -> None: self.meta.dataset.metadata_created_by = self.current_user self.meta.dataset.metadata_last_updated_date = timestamp self.meta.dataset.metadata_last_updated_by = self.current_user - + self.meta.dataset.file_path= str(self.dataset) if self.container: self.container.datadoc = self.meta else: diff --git a/tests/backend/test_datadoc_metadata.py b/tests/backend/test_datadoc_metadata.py index 00ba3f79..87571161 100644 --- a/tests/backend/test_datadoc_metadata.py +++ b/tests/backend/test_datadoc_metadata.py @@ -19,7 +19,7 @@ from datadoc.enums import DatasetState from datadoc.enums import DataType from datadoc.enums import VariableRole -from tests.utils import TEST_EXISTING_METADATA_DIRECTORY +from tests.utils import TEST_EXISTING_METADATA_DIRECTORY, TEST_RESOURCES_METADATA_DOCUMENT from tests.utils import TEST_EXISTING_METADATA_FILE_NAME from tests.utils import TEST_PARQUET_FILEPATH from tests.utils import TEST_RESOURCES_DIRECTORY @@ -202,6 +202,7 @@ def test_direct_person_identifying_default_value(metadata: DataDocMetadata): assert all(not v.direct_person_identifying for v in metadata.meta.variables) +# Test with existing dataset and metadata document def test_save_file_path_metadata_field( existing_metadata_file: str, metadata: DataDocMetadata, @@ -210,3 +211,17 @@ def test_save_file_path_metadata_field( 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) + + +# Test with dataset and no metadata document +def test_save_file_path_dataset_and_no_metadata( + metadata: DataDocMetadata, +): + metadata.write_metadata_document() + with Path.open(Path(TEST_RESOURCES_METADATA_DOCUMENT)) as f: + saved_file_path = json.load(f)["datadoc"]["dataset"]["file_path"] + assert saved_file_path == str(metadata.dataset) + + +# Test with metadata document and no dataset + diff --git a/tests/backend/test_model_backwards_compatibility.py b/tests/backend/test_model_backwards_compatibility.py index 688cd51d..e1adb638 100644 --- a/tests/backend/test_model_backwards_compatibility.py +++ b/tests/backend/test_model_backwards_compatibility.py @@ -8,7 +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 datadoc.utils import TEST_COMPATIBILITY_DIRECTORY +from tests.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/resources/person_data_v1__DOC.json b/tests/resources/person_data_v1__DOC.json index ddc52891..2015384b 100644 --- a/tests/resources/person_data_v1__DOC.json +++ b/tests/resources/person_data_v1__DOC.json @@ -50,7 +50,7 @@ }, "id": "143fca77-ef56-419c-a1e1-d69c4199f020", "owner": null, - "file_path": null, + "file_path": "tests/resources/person_data_v1.parquet", "metadata_created_date": "2022-09-05T11:07:14Z", "metadata_created_by": "default_user@ssb.no", "metadata_last_updated_date": "2022-01-01T00:00:00Z", @@ -254,4 +254,4 @@ ] }, "pseudonymization": null -} +} \ No newline at end of file