From 82686f21c0ac8af1d0d921112bbf904752a37733 Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Sat, 6 Jul 2024 13:09:04 +0200 Subject: [PATCH] Fix keys in project metadata (#138) --- mobie/metadata/project_metadata.py | 4 ++-- test/metadata/test_project_metadata.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mobie/metadata/project_metadata.py b/mobie/metadata/project_metadata.py index f94ab78..aa705c9 100644 --- a/mobie/metadata/project_metadata.py +++ b/mobie/metadata/project_metadata.py @@ -18,9 +18,9 @@ def create_project_metadata(root, description=None, references=None): "datasets": [] } if description is not None: - metadata[description] = description + metadata["description"] = description if references is not None: - metadata[references] = references + metadata["references"] = references write_project_metadata(root, metadata) diff --git a/test/metadata/test_project_metadata.py b/test/metadata/test_project_metadata.py index d99d5c1..20a450f 100644 --- a/test/metadata/test_project_metadata.py +++ b/test/metadata/test_project_metadata.py @@ -1,8 +1,10 @@ import json import unittest +import tempfile from jsonschema import ValidationError from mobie import SPEC_VERSION +from mobie.metadata import create_project_metadata, read_project_metadata, add_dataset from mobie.validation.utils import validate_with_schema @@ -60,6 +62,22 @@ def test_project_metadata(self): with self.assertRaises(ValidationError): validate_with_schema(metadata, "project") + def test_create_project_metadata(self): + description = "Test project" + schema = self.get_schema() + with tempfile.TemporaryDirectory() as tempdir: + create_project_metadata( + root=tempdir, + description=description, + ) + add_dataset( + root=tempdir, + dataset_name="alpha", + is_default=True, + ) + metadata = read_project_metadata(tempdir) + validate_with_schema(metadata, schema) + if __name__ == '__main__': unittest.main()