diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0a30742..4b7ba89 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,4 +31,5 @@ jobs: - name: Run pytest env: ZENODO_TOKEN: ${{ secrets.ZENODO_TOKEN }} + DEPOSITION_ID: ${{ secrets.DEPOSITION_ID }} run: pytest tests/test_zenodopy.py -v diff --git a/src/zenodopy/zenodopy.py b/src/zenodopy/zenodopy.py index 214f4e5..8f7986e 100644 --- a/src/zenodopy/zenodopy.py +++ b/src/zenodopy/zenodopy.py @@ -62,6 +62,20 @@ class ZenodoMetadata: license: str = "Apache-2.0" keywords: List[str] = field(default_factory=lambda: ["zenodo", "github", "git"]) creators: List[dict] = field(default_factory=lambda: [{"name": "Jhon, Doe", "orcid": "0000-0003-2584-3576"}]) + @classmethod + def parse_metadata_from_json(cls, json_file_path: Path) -> 'ZenodoMetadata': + """Parse metadata from a JSON file into a ZenodoMetadata object.""" + json_file_path = Path(json_file_path).expanduser() + if not json_file_path.exists(): + raise ValueError( + f"{json_file_path} does not exist. Please check you entered the correct path." + ) + + with json_file_path.open("r") as json_file: + data = json.load(json_file) + + metadata_dict = data.get("metadata", {}) + return cls(**metadata_dict) class BearerAuth(requests.auth.AuthBase): diff --git a/tests/test_version.py b/tests/test_version.py index d4bc16f..04fc524 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -5,21 +5,6 @@ import argparse import zenodopy -def parse_metadata_from_json(json_file_path: Path) -> zenodopy.ZenodoMetadata: - """Parse metadata from a JSON file into a ZenodoMetadata object.""" - json_file_path = json_file_path.expanduser() - if not json_file_path.exists(): - raise ValueError( - f"{json_file_path} does not exist. Please check you entered the correct path." - ) - - with json_file_path.open("r") as json_file: - data = json.load(json_file) - - metadata_dict = data.get("metadata", {}) - return zenodopy.ZenodoMetadata(**metadata_dict) - - def main(): # Set up argument parsing parser = argparse.ArgumentParser(description='Update Zenodo deposition with new version and files.') @@ -42,7 +27,7 @@ def main(): print("Version Tag:", version_tag) # Parse and update metadata with new version tag - metadata = parse_metadata_from_json(zenodo_metadata_file) + metadata = zenodopy.ZenodoMetadata.parse_metadata_from_json(zenodo_metadata_file) metadata.version = version_tag max_retries = 5 diff --git a/tests/test_zenodopy.py b/tests/test_zenodopy.py index 603b1ce..bf02f52 100644 --- a/tests/test_zenodopy.py +++ b/tests/test_zenodopy.py @@ -18,6 +18,7 @@ # use this when using pytest import os ACCESS_TOKEN = os.getenv('ZENODO_TOKEN') +DEPOSITION_ID = os.getenv('DEPOSITION_ID') # can also hardcode sandbox token using tox locally # ACCESS_TOKEN = '' @@ -67,7 +68,7 @@ def test_get_baseurl(): def test_get_depositions(): zeno = zen.Client(sandbox=True,token=ACCESS_TOKEN) - dep_id=106299 + dep_id=DEPOSITION_ID zeno.set_project(dep_id=dep_id) depositions = zeno._get_depositions() deposition_by_id = zeno._get_depositions_by_id() @@ -83,7 +84,7 @@ def test_get_depositions(): def test_get_bucket(): zeno = zen.Client(sandbox=True,token=ACCESS_TOKEN) - dep_id=106299 + dep_id=DEPOSITION_ID zeno.set_project(dep_id=dep_id) bucket_link = zeno._get_bucket_by_id() assert bucket_link.startswith('https://sandbox.zenodo.org/api/files/') @@ -93,7 +94,7 @@ def test_get_bucket(): def test_get_projects_and_files(): zeno = zen.Client(sandbox=True,token=ACCESS_TOKEN) - dep_id=106299 + dep_id=DEPOSITION_ID zeno.set_project(dep_id=dep_id) _ = zeno.list_projects _ = zeno.list_files