Skip to content

Commit

Permalink
DPMETA-9: Move backend tests into backend folder. New __init__.py in …
Browse files Browse the repository at this point in the history
…backend folder. Setting up first test for save filepath value
  • Loading branch information
tilen1976 committed Jan 22, 2024
1 parent 96e6a6f commit 22ef56e
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Unit tests for backend Datadoc."""
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
File renamed without changes.
257 changes: 257 additions & 0 deletions tests/resources/person_data_v1__DOC.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"metadata_last_updated_date": "2022-01-01T00:00:00Z",
"metadata_last_updated_by": "[email protected]",
"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
}

0 comments on commit 22ef56e

Please sign in to comment.