Skip to content

Commit

Permalink
BF: move reused _basic_publishmeta into dandischema/datacite/__init__…
Browse files Browse the repository at this point in the history
….py + fix typing issue
  • Loading branch information
yarikoptic committed Nov 4, 2024
1 parent 115bee0 commit a9c909f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dandischema/datacite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
34 changes: 1 addition & 33 deletions dandischema/datacite/tests/test_datacite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
import json
import os
from pathlib import Path
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dandischema/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions dandischema/tests/utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a9c909f

Please sign in to comment.