Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
JanhSander committed Jan 22, 2024
1 parent 22ef56e commit 5b4f5ef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/datadoc/backend/datadoc_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 16 additions & 1 deletion tests/backend/test_datadoc_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

2 changes: 1 addition & 1 deletion tests/backend/test_model_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/person_data_v1__DOC.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"metadata_last_updated_date": "2022-01-01T00:00:00Z",
Expand Down Expand Up @@ -254,4 +254,4 @@
]
},
"pseudonymization": null
}
}

0 comments on commit 5b4f5ef

Please sign in to comment.