From a9c909fd55b33c0ad81b470b79b7cf75d17c2439 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 4 Nov 2024 11:01:51 -0500 Subject: [PATCH] BF: move reused _basic_publishmeta into dandischema/datacite/__init__.py + fix typing issue --- dandischema/datacite/__init__.py | 2 +- dandischema/datacite/tests/test_datacite.py | 34 +-------------------- dandischema/tests/test_models.py | 2 +- dandischema/tests/utils.py | 33 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/dandischema/datacite/__init__.py b/dandischema/datacite/__init__.py index 57423823..8a8040d7 100644 --- a/dandischema/datacite/__init__.py +++ b/dandischema/datacite/__init__.py @@ -252,7 +252,7 @@ def to_datacite( @lru_cache() -def _get_datacite_schema(version_id: str = "datacite-4.3-17-gaa5db56") -> dict: +def _get_datacite_schema(version_id: str = "datacite-4.3-17-gaa5db56") -> Any: """Load datacite schema based on the version id provided.""" schema_folder = Path(__file__).parent / "schema" return json.loads((schema_folder / f"{version_id}.json").read_text()) diff --git a/dandischema/datacite/tests/test_datacite.py b/dandischema/datacite/tests/test_datacite.py index efdfdd8d..f1d129ae 100644 --- a/dandischema/datacite/tests/test_datacite.py +++ b/dandischema/datacite/tests/test_datacite.py @@ -1,4 +1,3 @@ -from datetime import datetime import json import os from pathlib import Path @@ -17,7 +16,7 @@ RoleType, ) import dandischema.tests -from dandischema.tests.utils import skipif_no_network +from dandischema.tests.utils import _basic_publishmeta, skipif_no_network from .. import _get_datacite_schema, to_datacite @@ -103,37 +102,6 @@ def metadata_basic() -> Dict[str, Any]: return meta_dict -def _basic_publishmeta( - dandi_id: str, version: str = "0.0.0", prefix: str = "10.80507" -) -> Dict[str, Any]: - """Return extra metadata required by PublishedDandiset - - Returned fields are additional to fields required by Dandiset - """ - publish_meta = { - "datePublished": str(datetime.now().year), - "publishedBy": { - "id": "urn:uuid:08fffc59-9f1b-44d6-8e02-6729d266d1b6", - "name": "DANDI publish", - "startDate": "2021-05-18T19:58:39.310338-04:00", - "endDate": "2021-05-18T19:58:39.310361-04:00", - "wasAssociatedWith": [ - { - "id": "urn:uuid:9267d2e1-4a37-463b-9b10-dad3c66d8eaa", - "identifier": "RRID:SCR_017571", - "name": "DANDI API", - "version": "0.1.0", - "schemaKey": "Software", - } - ], - "schemaKey": "PublishActivity", - }, - "version": version, - "doi": f"{prefix}/dandi.{dandi_id}/{version}", - } - return publish_meta - - @skipif_no_network @pytest.mark.skipif( not os.getenv("DATACITE_DEV_PASSWORD"), reason="no datacite password available" diff --git a/dandischema/tests/test_models.py b/dandischema/tests/test_models.py index 801dab2a..9b0e5101 100644 --- a/dandischema/tests/test_models.py +++ b/dandischema/tests/test_models.py @@ -7,7 +7,7 @@ from pydantic import Field, ValidationError import pytest -from .test_datacite import _basic_publishmeta +from .utils import _basic_publishmeta from .. import models from ..models import ( DANDI_INSTANCE_URL_PATTERN, diff --git a/dandischema/tests/utils.py b/dandischema/tests/utils.py index e01da850..5e76d5da 100644 --- a/dandischema/tests/utils.py +++ b/dandischema/tests/utils.py @@ -1,7 +1,40 @@ +from datetime import datetime import os +from typing import Any, Dict import pytest skipif_no_network = pytest.mark.skipif( bool(os.environ.get("DANDI_TESTS_NONETWORK")), reason="no network settings" ) + + +def _basic_publishmeta( + dandi_id: str, version: str = "0.0.0", prefix: str = "10.80507" +) -> Dict[str, Any]: + """Return extra metadata required by PublishedDandiset + + Returned fields are additional to fields required by Dandiset + """ + publish_meta = { + "datePublished": str(datetime.now().year), + "publishedBy": { + "id": "urn:uuid:08fffc59-9f1b-44d6-8e02-6729d266d1b6", + "name": "DANDI publish", + "startDate": "2021-05-18T19:58:39.310338-04:00", + "endDate": "2021-05-18T19:58:39.310361-04:00", + "wasAssociatedWith": [ + { + "id": "urn:uuid:9267d2e1-4a37-463b-9b10-dad3c66d8eaa", + "identifier": "RRID:SCR_017571", + "name": "DANDI API", + "version": "0.1.0", + "schemaKey": "Software", + } + ], + "schemaKey": "PublishActivity", + }, + "version": version, + "doi": f"{prefix}/dandi.{dandi_id}/{version}", + } + return publish_meta