Skip to content

Commit 51322b7

Browse files
Merge branch 'caltechlibrary:main' into tests
2 parents ab4153e + 7fd6982 commit 51322b7

File tree

21 files changed

+103
-3999
lines changed

21 files changed

+103
-3999
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ keywords:
2222
- metadata
2323
- software
2424
- InvenioRDM
25-
date-released: 2024-12-18
25+

caltechdata_api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
caltechdata_unembargo,
1010
caltechdata_accept,
1111
)
12-
from .customize_schema import customize_schema
12+
from .customize_schema import customize_schema, validate_metadata
1313
from .get_metadata import get_metadata
1414
from .download_file import download_file, download_url
1515
from .utils import humanbytes
16+
from .md_to_json import parse_readme_to_json

caltechdata_api/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import argparse
22
import requests
33
import s3fs
4-
from caltechdata_api import caltechdata_write, caltechdata_edit
5-
from md_to_json import parse_readme_to_json
4+
from caltechdata_api import caltechdata_write, caltechdata_edit, parse_readme_to_json
65
import json
76
import os
87
from cryptography.fernet import Fernet
@@ -69,7 +68,7 @@ def get_or_set_token(production=True):
6968

7069
key = load_or_generate_key()
7170

72-
# Use different token files for production and test environments
71+
# Use different token files for production and test environment
7372
token_filename = "token.txt" if production else "token_test.txt"
7473
token_file = os.path.join(caltechdata_directory, token_filename)
7574

caltechdata_api/customize_schema.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,17 @@ def validate_metadata(json_record):
480480
errors.append("Each 'subject' must have a 'subject' key.")
481481

482482
# Check for 'dates'
483-
if "dates" not in json_record:
484-
errors.append("'dates' field is missing.")
485-
elif not isinstance(json_record["dates"], list) or len(json_record["dates"]) == 0:
486-
errors.append("'dates' should be a non-empty list.")
487-
else:
488-
for date in json_record["dates"]:
489-
if (
490-
not isinstance(date, dict)
491-
or "date" not in date
492-
or "dateType" not in date
493-
):
494-
errors.append("Each 'date' must have 'date' and 'dateType'.")
483+
if "dates" in json_record:
484+
if not isinstance(json_record["dates"], list) or len(json_record["dates"]) == 0:
485+
errors.append("'dates' should be a non-empty list.")
486+
else:
487+
for date in json_record["dates"]:
488+
if (
489+
not isinstance(date, dict)
490+
or "date" not in date
491+
or "dateType" not in date
492+
):
493+
errors.append("Each 'date' must have 'date' and 'dateType'.")
495494

496495
# Check for 'creators'
497496
if "creators" not in json_record:
@@ -601,10 +600,9 @@ def validate_metadata(json_record):
601600
errors.append("'publisher' should be a string.")
602601

603602
# Check for 'publicationYear'
604-
if "publicationYear" not in json_record:
605-
errors.append("'publicationYear' field is missing.")
606-
elif not isinstance(json_record["publicationYear"], str):
607-
errors.append("'publicationYear' should be a string.")
603+
if "publicationYear" in json_record:
604+
if not isinstance(json_record["publicationYear"], str):
605+
errors.append("'publicationYear' should be a string.")
608606

609607
# Check for 'types'
610608
if "types" not in json_record:

tests/10.22002-D1.1098

-15.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)