Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion data_collections_api/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
"""

Expand Down
46 changes: 46 additions & 0 deletions tests/test_send.py
Original file line number Diff line number Diff line change
@@ -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():

Check failure on line 19 in tests/test_send.py

View workflow job for this annotation

GitHub Actions / ruff-lint

Ruff (D103)

tests/test_send.py:19:5: D103 Missing docstring in public function
return InvenioRepository(url=f"http://{LOCAL_SERVER}:{LOCAL_PORT}", api_key="")


def test_create_depo(repo):

Check failure on line 23 in tests/test_send.py

View workflow job for this annotation

GitHub Actions / ruff-lint

Ruff (D103)

tests/test_send.py:23:5: D103 Missing docstring in public function
# 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()
Loading