Commit a7433e70 authored by Cage, Gregory's avatar Cage, Gregory
Browse files

Merge branch '17-initial-testing' into 'main'

Add initial testing for library

Closes #17

See merge request ndip/public-packages/nova-galaxy!3
parents 112b0973 d08e8652
Loading
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ variables:
  GIT_STRATEGY: clone
  IMAGE_NAME: ${NDIP_DOCKER_REPOSITORY}/${CI_PROJECT_PATH}
  IMAGE_TAG: "0.1.0"
  GALAXY_URL: "https://calvera-test.ornl.gov"
  GALAXY_KEY: ${SERVICE_ACCOUNT_API_KEY}

before_script:
  - curl https://code.ornl.gov/rse-deployment/rse-sharables/raw/master/rse-bash-modules.sh -O
@@ -36,9 +38,9 @@ unit-tests:
  stage: test
  script:
    - mkdir reports
    - docker run -u `id -u`:`id -g` -v `pwd`/reports:/src/reports ${IMAGE_NAME}:src-${CI_COMMIT_SHA} poetry run coverage run
    - docker run -u `id -u`:`id -g` -v `pwd`/reports:/src/reports ${IMAGE_NAME}:src-${CI_COMMIT_SHA} poetry run coverage report
    - docker run -u `id -u`:`id -g` -v `pwd`/reports:/src/reports ${IMAGE_NAME}:src-${CI_COMMIT_SHA} poetry run coverage xml -o reports/coverage.xml
    - docker run -u `id -u`:`id -g` -v `pwd`/reports:/src/reports -e NOVA_GALAXY_TEST_GALAXY_KEY=${GALAXY_KEY} -e NOVA_GALAXY_TEST_GALAXY_URL=${GALAXY_URL} ${IMAGE_NAME}:src-${CI_COMMIT_SHA} poetry run coverage run
    - docker run -u `id -u`:`id -g` -v `pwd`/reports:/src/reports -e NOVA_GALAXY_TEST_GALAXY_KEY=${GALAXY_KEY} -e NOVA_GALAXY_TEST_GALAXY_URL=${GALAXY_URL} ${IMAGE_NAME}:src-${CI_COMMIT_SHA} poetry run coverage report
    - docker run -u `id -u`:`id -g` -v `pwd`/reports:/src/reports -e NOVA_GALAXY_TEST_GALAXY_KEY=${GALAXY_KEY} -e NOVA_GALAXY_TEST_GALAXY_URL=${GALAXY_URL} ${IMAGE_NAME}:src-${CI_COMMIT_SHA} poetry run coverage xml -o reports/coverage.xml
    - sed -i "s:<source>/src:<source>${CI_BUILDS_DIR}/${CI_PROJECT_PATH}:" reports/coverage.xml

  coverage: '/TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
+6 −2
Original line number Diff line number Diff line
@@ -32,10 +32,14 @@ poetry run mypy .
```

## Testing
You can run the tests for this package with the following command from the base directory:
```commandline
poetry run pytest
NOVA_GALAXY_TEST_GALAXY_URL=galaxy-url NOVA_GALAXY_TEST_GALAXY_KEY=key poetry run pytest tests/
```
or, with coverage
with `NOVA_GALAXY_TEST_GALAXY_URL` being the url of your Galaxy instance and `NOVA_GALAXY_TEST_GALAXY_KEY` being your
Galaxy API Key.

To run tests with coverage (include the above environment variables):
```commandline
poetry run coverage run
poetry run coverage report
+5 −3
Original line number Diff line number Diff line
"""Contains classes to run tools in Galaxy via Nova."""

import time
from typing import List, Union
from typing import List, Optional, Union

from bioblend import galaxy

@@ -77,7 +77,9 @@ class Tool(AbstractWork):

        return outputs

    def run_interactive(self, data_store: Datastore, params: Parameters, max_tries: int = 100) -> str:
    def run_interactive(
        self, data_store: Datastore, params: Parameters, max_tries: int = 100, check_url: bool = True
    ) -> Optional[str]:
        galaxy_instance = data_store.nova_connection.galaxy_instance
        datasets_to_upload = {}
        # Set Tool Inputs
@@ -107,7 +109,7 @@ class Tool(AbstractWork):
                if ep["job_id"] == job_id and ep.get("target", None):
                    url = f"{data_store.nova_connection.galaxy_url}{ep['target']}"
                    response = galaxy_instance.make_get_request(url)
                    if response.status_code == 200:
                    if response.status_code == 200 or not check_url:
                        return url
            timer -= 1
            time.sleep(1)

tests/conftest.py

0 → 100644
+23 −0
Original line number Diff line number Diff line
"""Config for testing."""

import os

import pytest
from bioblend.galaxy import GalaxyInstance

from nova.galaxy.nova import Nova

GALAXY_URL = os.environ.get("NOVA_GALAXY_TEST_GALAXY_URL", "https://calvera-test.ornl.gov")
GALAXY_API_KEY = os.environ.get("NOVA_GALAXY_TEST_GALAXY_KEY")


@pytest.fixture
def nova_instance() -> Nova:
    nova = Nova(GALAXY_URL, GALAXY_API_KEY)
    return nova


@pytest.fixture
def galaxy_instance() -> GalaxyInstance:
    galaxy = GalaxyInstance(url=GALAXY_URL, key=GALAXY_API_KEY)
    return galaxy
+26 −0
Original line number Diff line number Diff line
"""Tests for data stores."""

from bioblend.galaxy import GalaxyInstance

from nova.galaxy.nova import Nova


def test_no_persist_store(nova_instance: Nova, galaxy_instance: GalaxyInstance) -> None:
    with nova_instance.connect() as connection:
        store = connection.create_data_store(name="nova_galaxy_testing")
        history = galaxy_instance.histories.get_histories(name=store.name)
        assert len(history) > 0
    history = galaxy_instance.histories.get_histories(name=store.history_id, deleted=False)
    assert len(history) < 1


def test_persist_store(nova_instance: Nova, galaxy_instance: GalaxyInstance) -> None:
    with nova_instance.connect() as connection:
        store = connection.create_data_store(name="nova_galaxy_testing")
        store.persist()
        history = galaxy_instance.histories.get_histories(name=store.name)
        assert len(history) > 0
    history = galaxy_instance.histories.get_histories(name=store.name, deleted=False)
    assert len(history) > 0
    # TODO: Can maybe do global cleanup
    galaxy_instance.histories.delete_history(history_id=history[0]["id"], purge=True)
Loading