diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..155fc6a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,72 @@ +name: Build and Install + +on: + push: + branches: [ "main" ] + pull_request: + types: + - opened + - synchronize + - reopened + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: | + 3.10.19 + 3.9 + + - name: Set up Docker Compose + uses: docker/setup-compose-action@v1 + + # Building mandb triggers take 45s+ for no benefit (we don't use man in CI) + - name: Disable mandb + run: | + echo "set man-db/auto-update false" | sudo debconf-communicate + sudo dpkg-reconfigure man-db + + - name: Setup Invenio deps + run: | + sudo apt-get update + sudo apt-get install libcairo2-dev fonts-dejavu imagemagick + pip install --upgrade pip pipfile + pip install invenio-cli click invenio invenio-oauth2server invenio-accounts + + - name: Setup Invenio + run: | + invenio-cli check-requirements + yes "" | invenio-cli init rdm # (choose defaults as test) + + - name: start invenio + run: | + invenio-cli install all + invenio-cli services setup + invenio-cli services start + invenio-cli run all & + echo "Starting:" + invenio users create --password 123 test@test.com + invenio tokens create -n test-token -u test@test.com + exit 1 + working-directory: my-site + + - uses: actions/checkout@v4 + - name: Install dependencies + run: | + /opt/hostedtoolcache/Python/3.10.19/x64/python -m pip install setuptools build + + - name: Install + run: | + /opt/hostedtoolcache/Python/3.10.19/x64/python -m pip install ".[test]" + + - name: Run Tests + run: | + /opt/hostedtoolcache/Python/3.10.19/x64/python -m pytest --doctest-modules diff --git a/data_collections_api/invenio.py b/data_collections_api/invenio.py index 1a0c618..23e95fc 100644 --- a/data_collections_api/invenio.py +++ b/data_collections_api/invenio.py @@ -1115,7 +1115,7 @@ class InvenioRepository: my_repo = InvenioRepository(url="companyname.website", api_key="abc123") my_repo.depositions["my_repo"].files["file"].upload(my_file) - my_repo.records.get() + my_repo.depositions.get() my_repo.licenses.list() """ diff --git a/tests/test_send.py b/tests/test_send.py new file mode 100644 index 0000000..44f7ac5 --- /dev/null +++ b/tests/test_send.py @@ -0,0 +1,46 @@ +"""Test repository API functions.""" + +from __future__ import annotations + +from pathlib import Path + +import pytest + +from data_collections_api.dumpers import get_loader +from data_collections_api.invenio import InvenioRepository + +LOCAL_SERVER = "127.0.0.1" +LOCAL_PORT = "5000" + +DATA_DIR = Path(__file__).parent / "test_data" + + +@pytest.fixture +def repo(): + return InvenioRepository(url=f"http://{LOCAL_SERVER}:{LOCAL_PORT}", api_key="") + + +def test_create_depo(repo): + # create an empty draft record in Invenio and retrieve its id + draft = repo.depositions.create() + draft_id = draft.get()["id"] + + print(draft_id) + + metadata_path = DATA_DIR / "bare_example.yml" + + # open metadata record + loader = get_loader("yaml") + data = loader(metadata_path) + + # add metadata to draft + repo.depositions.draft(draft_id).update(data) + + # add files to draft + repo.depositions.draft(draft_id).files.upload({"metadata": metadata_path}) + + # bind draft to a community + repo.depositions.draft(draft_id).bind("geoff") + + # submit draft for review + repo.depositions.draft(draft_id).submit_review()