Skip to content

Commit c1b4ab5

Browse files
Improve automated tests
1 parent 4ed8944 commit c1b4ab5

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

.github/workflows/bot.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ jobs:
3636
pip install pytest requests s3fs cryptography
3737
pip install .
3838
39-
- name: Run CaltechDATA Metadata Validation
39+
- name: Run against CaltechData Test system
4040
env:
41-
CALTECHDATA_TOKEN: ${{ secrets.CALTECHDATA_TOKEN }}
42-
run: |
43-
python tests/bot_yaml.py
44-
- name: Run Unit Tests
41+
RDMTOK: ${{ secrets.CALTECHDATA_TOKEN }}
4542
run: |
4643
cd tests
4744
pytest test_unit.py
4845
pytest test_rdm.py
46+
- name: Run Medata Validation Test and RDM
47+
env:
48+
RDMTOK: ${{ secrets.CALTECHDATA_TOKEN }}
49+
run: |
50+
cd tests
51+
python bot_yaml.py
52+

caltechdata_api/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def decrypt_token(encrypted_token, key):
5858
return f.decrypt(encrypted_token).decode()
5959

6060

61-
# Function to get or set token with support for test systems
61+
# Function to get or set token with support for test system.
6262
def get_or_set_token(production=True):
6363
# First check for environment variable
6464
env_token = os.environ.get("CALTECHDATA_TOKEN")
@@ -68,7 +68,7 @@ def get_or_set_token(production=True):
6868

6969
key = load_or_generate_key()
7070

71-
# Use different token files for production and test environment
71+
# Use different token files for production and test environment.
7272
token_filename = "token.txt" if production else "token_test.txt"
7373
token_file = os.path.join(caltechdata_directory, token_filename)
7474

@@ -609,6 +609,7 @@ def create_record(production):
609609
print_upload_message(rec_id, production)
610610
with open(response + ".json", "w") as file:
611611
json.dump(metadata, file, indent=2)
612+
exit()
612613
break
613614
else:
614615
break

caltechdata_api/customize_schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ def validate_metadata(json_record):
508508
if creator["nameType"] == "Organizational":
509509
if "name" not in creator:
510510
errors.append("Each organizational 'creator' must have 'name'.")
511-
else:
512-
if "familyName" not in creator:
513-
errors.append(
514-
"Each 'creator' must have a 'familyName' or have type Organizational"
515-
)
511+
else:
512+
if "familyName" not in creator:
513+
errors.append(
514+
"Each 'creator' must have a 'familyName' or have type Organizational"
515+
)
516516
if "affiliation" in creator:
517517
if not isinstance(creator["affiliation"], list):
518518
errors.append("'affiliation' in 'creators' should be a list.")

tests/bot_yaml.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ def import_cli_module(self):
6060
def generate_test_responses(self):
6161
"""Generate test responses for CLI prompts"""
6262
return {
63-
"Do you want to create or edit a CaltechDATA record? (create/edit): ": "create",
63+
"What would you like to do? (create/edit/profile/exit): ": "create",
6464
"Do you want to use metadata from an existing file or create new metadata? (existing/create): ": "create",
6565
"Enter the title of the dataset: ": f"Test Dataset {self.timestamp}",
6666
"Enter the abstract or description of the dataset: ": "This is an automated test dataset containing sample climate data for validation purposes.",
6767
"Enter the number corresponding to the desired license: ": "1",
68+
"Use saved profile? (y/n): ": "n",
6869
"Enter your ORCID identifier: ": os.environ.get(
6970
"TEST_ORCID", "0000-0002-1825-0097"
7071
),

tests/test_rdm.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,60 @@
55
get_metadata,
66
)
77
import json
8+
import os
89

910

1011
def test_datacite_rdm_conversion(full_datacite43_record, full_rdm_record):
11-
converted = customize_schema(full_datacite43_record, schema="43", pilot=True)
12+
converted = customize_schema(full_datacite43_record, schema="43")
1213

1314
assert converted == full_rdm_record
1415

1516

1617
def test_datacite_rdm_create_edit(full_datacite43_record):
18+
env_token = os.environ.get("RDMTOK")
1719
doi = caltechdata_write(
18-
full_datacite43_record, schema="43", pilot=True, publish=True
20+
full_datacite43_record,
21+
schema="43",
22+
production=False,
23+
publish=True,
24+
token=env_token,
1925
)
2026

2127
assert doi.startswith("10.33569")
2228

2329
doi = caltechdata_write(
2430
full_datacite43_record,
2531
schema="43",
26-
pilot=True,
32+
production=False,
2733
files=["codemeta.json"],
2834
publish=True,
35+
token=env_token,
2936
)
3037

3138
assert doi.startswith("10.33569")
3239

3340
# If we don't publish, don't get back a DOI
34-
idv = caltechdata_write(full_datacite43_record, schema="43", pilot=True)
41+
idv = caltechdata_write(
42+
full_datacite43_record, schema="43", production=False, token=env_token
43+
)
3544

3645
assert idv.startswith("10.33569") == False
3746

3847
full_datacite43_record["publisher"] = "Edited"
3948

4049
doi = caltechdata_edit(
41-
idv, full_datacite43_record, schema="43", pilot=True, publish=True
50+
idv,
51+
full_datacite43_record,
52+
schema="43",
53+
production=False,
54+
publish=True,
55+
token=env_token,
4256
)
4357

4458
assert doi.startswith("10.33569")
4559
idv = doi.split("/")[1]
4660

47-
new_metadata = get_metadata(idv, production=False, pilot=True)
61+
new_metadata = get_metadata(idv, production=False, publish=True)
4862

4963
assert new_metadata["publisher"] == "Edited"
5064

@@ -55,14 +69,15 @@ def test_datacite_rdm_create_edit(full_datacite43_record):
5569
full_datacite43_record,
5670
files=["codemeta.json"],
5771
schema="43",
58-
pilot=True,
72+
production=False,
5973
publish=True,
74+
token=env_token,
6075
)
6176

6277
assert new_doi != doi
6378

6479
idv = new_doi.split("/")[1]
6580

66-
new_metadata = get_metadata(idv, production=False, pilot=True)
81+
new_metadata = get_metadata(idv, production=False)
6782

6883
assert new_metadata["publisher"] == "Again!"

0 commit comments

Comments
 (0)