diff --git a/.github/workflows/bot.yaml b/.github/workflows/bot.yaml index eafab97..e05d105 100644 --- a/.github/workflows/bot.yaml +++ b/.github/workflows/bot.yaml @@ -36,13 +36,17 @@ jobs: pip install pytest requests s3fs cryptography pip install . - - name: Run CaltechDATA Metadata Validation + - name: Run against CaltechData Test system env: - CALTECHDATA_TOKEN: ${{ secrets.CALTECHDATA_TOKEN }} - run: | - python tests/bot_yaml.py - - name: Run Unit Tests + RDMTOK: ${{ secrets.CALTECHDATA_TOKEN }} run: | cd tests pytest test_unit.py pytest test_rdm.py + - name: Run Medata Validation Test and RDM + env: + RDMTOK: ${{ secrets.CALTECHDATA_TOKEN }} + run: | + cd tests + python bot_yaml.py + diff --git a/caltechdata_api/cli.py b/caltechdata_api/cli.py index b0e9c00..3e99fde 100644 --- a/caltechdata_api/cli.py +++ b/caltechdata_api/cli.py @@ -58,7 +58,7 @@ def decrypt_token(encrypted_token, key): return f.decrypt(encrypted_token).decode() -# Function to get or set token with support for test systems +# Function to get or set token with support for test system. def get_or_set_token(production=True): # First check for environment variable env_token = os.environ.get("CALTECHDATA_TOKEN") @@ -68,7 +68,7 @@ def get_or_set_token(production=True): key = load_or_generate_key() - # Use different token files for production and test environment + # Use different token files for production and test environment. token_filename = "token.txt" if production else "token_test.txt" token_file = os.path.join(caltechdata_directory, token_filename) @@ -609,6 +609,7 @@ def create_record(production): print_upload_message(rec_id, production) with open(response + ".json", "w") as file: json.dump(metadata, file, indent=2) + exit() break else: break diff --git a/caltechdata_api/customize_schema.py b/caltechdata_api/customize_schema.py index d3bfbf9..519342c 100644 --- a/caltechdata_api/customize_schema.py +++ b/caltechdata_api/customize_schema.py @@ -508,11 +508,11 @@ def validate_metadata(json_record): if creator["nameType"] == "Organizational": if "name" not in creator: errors.append("Each organizational 'creator' must have 'name'.") - else: - if "familyName" not in creator: - errors.append( - "Each 'creator' must have a 'familyName' or have type Organizational" - ) + else: + if "familyName" not in creator: + errors.append( + "Each 'creator' must have a 'familyName' or have type Organizational" + ) if "affiliation" in creator: if not isinstance(creator["affiliation"], list): errors.append("'affiliation' in 'creators' should be a list.") diff --git a/tests/bot_yaml.py b/tests/bot_yaml.py index fe3d489..0a2162e 100644 --- a/tests/bot_yaml.py +++ b/tests/bot_yaml.py @@ -60,11 +60,12 @@ def import_cli_module(self): def generate_test_responses(self): """Generate test responses for CLI prompts""" return { - "Do you want to create or edit a CaltechDATA record? (create/edit): ": "create", + "What would you like to do? (create/edit/profile/exit): ": "create", "Do you want to use metadata from an existing file or create new metadata? (existing/create): ": "create", "Enter the title of the dataset: ": f"Test Dataset {self.timestamp}", "Enter the abstract or description of the dataset: ": "This is an automated test dataset containing sample climate data for validation purposes.", "Enter the number corresponding to the desired license: ": "1", + "Use saved profile? (y/n): ": "n", "Enter your ORCID identifier: ": os.environ.get( "TEST_ORCID", "0000-0002-1825-0097" ), diff --git a/tests/test_rdm.py b/tests/test_rdm.py index 2dd0fcd..ddd94fd 100644 --- a/tests/test_rdm.py +++ b/tests/test_rdm.py @@ -5,17 +5,23 @@ get_metadata, ) import json +import os def test_datacite_rdm_conversion(full_datacite43_record, full_rdm_record): - converted = customize_schema(full_datacite43_record, schema="43", pilot=True) + converted = customize_schema(full_datacite43_record, schema="43") assert converted == full_rdm_record def test_datacite_rdm_create_edit(full_datacite43_record): + env_token = os.environ.get("RDMTOK") doi = caltechdata_write( - full_datacite43_record, schema="43", pilot=True, publish=True + full_datacite43_record, + schema="43", + production=False, + publish=True, + token=env_token, ) assert doi.startswith("10.33569") @@ -23,28 +29,36 @@ def test_datacite_rdm_create_edit(full_datacite43_record): doi = caltechdata_write( full_datacite43_record, schema="43", - pilot=True, + production=False, files=["codemeta.json"], publish=True, + token=env_token, ) assert doi.startswith("10.33569") # If we don't publish, don't get back a DOI - idv = caltechdata_write(full_datacite43_record, schema="43", pilot=True) + idv = caltechdata_write( + full_datacite43_record, schema="43", production=False, token=env_token + ) assert idv.startswith("10.33569") == False full_datacite43_record["publisher"] = "Edited" doi = caltechdata_edit( - idv, full_datacite43_record, schema="43", pilot=True, publish=True + idv, + full_datacite43_record, + schema="43", + production=False, + publish=True, + token=env_token, ) assert doi.startswith("10.33569") idv = doi.split("/")[1] - new_metadata = get_metadata(idv, production=False, pilot=True) + new_metadata = get_metadata(idv, production=False, publish=True) assert new_metadata["publisher"] == "Edited" @@ -55,14 +69,15 @@ def test_datacite_rdm_create_edit(full_datacite43_record): full_datacite43_record, files=["codemeta.json"], schema="43", - pilot=True, + production=False, publish=True, + token=env_token, ) assert new_doi != doi idv = new_doi.split("/")[1] - new_metadata = get_metadata(idv, production=False, pilot=True) + new_metadata = get_metadata(idv, production=False) assert new_metadata["publisher"] == "Again!"