Skip to content

Commit

Permalink
Merge pull request #567 from sennetconsortium/tjmadonna/496-tests
Browse files Browse the repository at this point in the history
Tjmadonna/496 tests
  • Loading branch information
maxsibilla authored Jan 13, 2025
2 parents ddb7a2a + b60c5a2 commit 3ce746d
Show file tree
Hide file tree
Showing 42 changed files with 1,764 additions and 4,088 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: [3.9]

services:
neo4j:
image: neo4j:5.20.0-ubi8
ports:
- 7474:7474
- 7687:7687
env:
NEO4J_AUTH: none
NEO4JLABS_PLUGINS: '["apoc"]'

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -29,7 +40,11 @@ jobs:
pip install -r src/requirements.dev.txt
- name: Setup test config file
run: |
cp test/config/app.cfg src/instance/app.cfg
cp test/config/app.test.cfg src/instance/app.cfg
- name: Test with pytest
env:
UBKG_SERVER: ${{ secrets.UBKG_SERVER }}
UBKG_ENDPOINT_VALUESET: ${{ secrets.UBKG_ENDPOINT_VALUESET }}
UBKG_CODES: ${{ secrets.UBKG_CODES }}
run: |
pytest -W ignore::DeprecationWarning
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ cd docker
The documentation for the API calls is hosted on SmartAPI. Modifying the `entity-api-spec.yaml` file and committing the changes to github should update the API shown on SmartAPI. SmartAPI allows users to register API documents. The documentation is associated with this github account: api-developers@sennetconsortium.org.

## Testing
Install the development dependencies using `pip install -r src/requirements.dev.txt`.

Execute `pytest` in the root directory to run all unit tests. `pytest -W ignore::DeprecationWarning` will execute all unit tests without deprecation warnings.
Install the development dependencies using `pip install -r src/requirements.dev.txt`. Install Docker and ensure it is running. Run `./run_tests.sh` at the root of the project. This test script will create a temporary Neo4J database using Docker for integration tests.
344 changes: 344 additions & 0 deletions docker/test/neo4j/neo4j.conf

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# check if the neo4j-test docker container is running and stop it
if [ "$(docker ps -q -f name=neo4j-test)" ]; then
echo "Stopping the existing neo4j-test container"
docker stop neo4j-test > /dev/null
fi

# check if the neo4j-test docker container exists and remove it
if [ "$(docker ps -aq -f name=neo4j-test)" ]; then
echo "Removing the existing neo4j-test container"
docker rm neo4j-test > /dev/null
fi

# create a new neo4j-test docker container
echo "Creating a new neo4j-test container"
docker run -d \
--name neo4j-test \
-p 7474:7474 \
-p 7687:7687 \
-e NEO4J_AUTH=none \
-e NEO4JLABS_PLUGINS=\[\"apoc\"\] \
neo4j:5.20.0-ubi8

# Read values from config file and set them as environment variables
UBKG_SERVER=$(awk -F ' = ' '/UBKG_SERVER/ {print $2}' src/instance/app.cfg | tr -d '[:space:]' | sed "s/^'//;s/'$//")
UBKG_ENDPOINT_VALUESET=$(awk -F ' = ' '/UBKG_ENDPOINT_VALUESET/ {print $2}' src/instance/app.cfg | tr -d '[:space:]' | sed "s/^'//;s/'$//")
UBKG_CODES=$(awk -F ' = ' '/UBKG_CODES/ {print $2}' src/instance/app.cfg | tr -d '[:space:]' | sed "s/^'//;s/'$//")

# Set the test config file and backup the original config file
mv src/instance/app.cfg src/instance/app.cfg.bak
cp test/config/app.test.cfg src/instance/app.cfg

echo "Running tests"
UBKG_SERVER=$UBKG_SERVER \
UBKG_ENDPOINT_VALUESET=$UBKG_ENDPOINT_VALUESET \
UBKG_CODES=$UBKG_CODES \
pytest -W ignore::DeprecationWarning

# Restore the original config file
mv src/instance/app.cfg.bak src/instance/app.cfg

echo "Stopping and removing the neo4j-test container"
docker stop neo4j-test > /dev/null
docker rm --volumes neo4j-test > /dev/null
2 changes: 1 addition & 1 deletion src/instance/app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ UBKG_SERVER =
UBKG_ENDPOINT_VALUESET =
UBKG_CODES =

MULTIPLE_ALLOWED_ORGANS = ['LY', 'SK', 'BD', 'BM', 'AD', 'BX', 'MU']
MULTIPLE_ALLOWED_ORGANS = ['LY', 'SK', 'BD', 'BM', 'AD', 'BX', 'MU']
23 changes: 12 additions & 11 deletions test/config/app.cfg → test/config/app.test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ READ_ONLY_MODE = False
SCHEMA_YAML_FILE = './schema/provenance_schema.yaml'

# Globus App ID and secret
APP_CLIENT_ID = 'c4018852'
APP_CLIENT_SECRET = 'supersecret'
APP_CLIENT_ID = ''
APP_CLIENT_SECRET = ''

# Neo4j connection (default value used for docker localhost deployment)
# Point to remote neo4j for dev/test/stage/prod deployment
NEO4J_URI = 'bolt://hubmap-neo4j-localhost:7687'
NEO4J_URI = 'bolt://localhost:7687'
NEO4J_USERNAME = 'neo4j'
NEO4J_PASSWORD = '123'
NEO4J_PASSWORD = None

# Set MEMCACHED_MODE to False to disable the caching for local development
MEMCACHED_MODE = False
Expand Down Expand Up @@ -46,9 +46,9 @@ GLOBUS_APP_BASE_URL = 'https://app.globus.org'

# Below configurations are for DOI redirection
# UUIDs of the Globus endpoints
GLOBUS_PUBLIC_ENDPOINT_UUID = '6be4ac4f-7b63-4640-9a19-3eb6d6e779d6'
GLOBUS_CONSORTIUM_ENDPOINT_UUID = '4be0eae8-ce38-41f3-bede-86d364f72201'
GLOBUS_PROTECTED_ENDPOINT_UUID = '6be4ac4f-7b63-4640-9a19-3eb6d6e779d6'
GLOBUS_PUBLIC_ENDPOINT_UUID = ''
GLOBUS_CONSORTIUM_ENDPOINT_UUID = ''
GLOBUS_PROTECTED_ENDPOINT_UUID = ''

# Sub directories under the base data/globus directory where different access levels of data sits
PROTECTED_DATA_SUBDIR = 'private'
Expand All @@ -63,8 +63,9 @@ DOI_REDIRECT_URL = 'https://data.sennetconsortium.org/<entity_type>?uuid=<identi
#URL to tsv file that holds the redirect url information for DOI redirects
REDIRECTION_INFO_URL = 'https://raw.githubusercontent.com/hubmapconsortium/ccf-releases/main/reference-entity-ids.tsv'

UBKG_SERVER = 'http://ubkg:8080'
UBKG_ENDPOINT_VALUESET = ''
UBKG_CODES = ''
import os
UBKG_SERVER = os.getenv('UBKG_SERVER')
UBKG_ENDPOINT_VALUESET = os.getenv('UBKG_ENDPOINT_VALUESET')
UBKG_CODES = os.getenv('UBKG_CODES')

MULTIPLE_ALLOWED_ORGANS = ['LY', 'SK', 'BD', 'BM', 'AD', 'BX', 'MU']
MULTIPLE_ALLOWED_ORGANS = ['LY', 'SK', 'BD', 'BM', 'AD', 'BX', 'MU']
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest_plugins = ["test.helpers.auth", "test.helpers.database", "test.helpers.request"]
175 changes: 0 additions & 175 deletions test/data/create_entity_success_dataset.json

This file was deleted.

Loading

0 comments on commit 3ce746d

Please sign in to comment.