Skip to content
Merged
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
8 changes: 0 additions & 8 deletions importers/test/test_djornl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,3 @@ def test_duplicate_cluster_data(self):
cluster_data,
self.json_data["load_clusters"]
)

def test_the_full_shebang(self):

RES_ROOT_DATA_PATH = os.path.join(_TEST_DIR, 'djornl', 'test_data')
parser = self.init_parser_with_path(RES_ROOT_DATA_PATH)

parser.load_data()
self.assertEqual(True, parser.load_data())
27 changes: 27 additions & 0 deletions importers/test/test_djornl_parser_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Tests for the DJORNL Parser

At the present time, this just ensures that the files are parsed correctly;
it does not check data loading into the db.
"""
import unittest
import os

from importers.djornl.parser import DJORNL_Parser
from spec.test.helpers import modified_environ, check_spec_test_env

_TEST_DIR = '/app/spec/test'


class Test_DJORNL_Parser_Integration(unittest.TestCase):

@classmethod
def setUpClass(cls):
check_spec_test_env()

def test_the_full_shebang(self):

with modified_environ(RES_ROOT_DATA_PATH=os.path.join(_TEST_DIR, 'djornl', 'test_data')):
parser = DJORNL_Parser()
parser.load_data()
self.assertEqual(True, parser.load_data())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be assertTrue(parser.load_data())

6 changes: 5 additions & 1 deletion relation_engine_server/test/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ def test_update_specs(self):
resp_json = resp.json()
self.assertEqual(resp.status_code, 200)
self.assertTrue(len(resp_json['status']))

# delete the SPEC_TEST_READY env var as it is no longer true
os.environ.pop('SPEC_TEST_READY', None)

# Test that the indexes get created and not duplicated
url = _CONF['db_url'] + '/_api/index'
auth = (_CONF['db_user'], _CONF['db_pass'])
Expand Down Expand Up @@ -161,7 +165,7 @@ def test_list_data_sources(self):
# /data_sources is used by the UI and requires slightly different response formatting
# /specs/data_sources is in the standard /specs format used by collections and stored_queries

data_sources = ['djornl', 'envo_ontology', 'go_ontology', 'gtdb', 'ncbi_taxonomy', 'rdp_taxonomy']
data_sources = ['ncbi_taxonomy']

# /spec/data_sources endpoint
def check_resp_json_spec_endpoint(self, resp):
Expand Down
19 changes: 19 additions & 0 deletions spec/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import os
import requests
import sys
import shutil
from relation_engine_server.utils.wait_for import wait_for_api
from relation_engine_server.utils.pull_spec import download_specs
from relation_engine_server.utils.config import get_config as get_re_config


@functools.lru_cache(maxsize=1)
Expand Down Expand Up @@ -62,6 +66,21 @@ def create_test_docs(coll_name, docs, update_on_dupe=False):
return resp


def check_spec_test_env():
""" ensure that the environment is prepared for running the spec tests """
if os.environ.get('SPEC_TEST_READY', None) is None:
wait_for_api()
_CONF = get_re_config()
# Remove the spec directory, ignoring if it is already missing
shutil.rmtree(_CONF['spec_paths']['root'], ignore_errors=True)
# Recreate the spec directory so we have a clean slate, avoiding name conflicts
os.makedirs(_CONF['spec_paths']['root'])
# copy the contents of /app/spec into /spec/repo
shutil.copytree('/app/spec', _CONF['spec_paths']['repo'])
download_specs()
os.environ.update({'SPEC_TEST_READY': "Done"})


def capture_stdout(function, *args, **kwargs):
"""capture and return the standard output from a function"""
io_stdout = io.StringIO()
Expand Down
5 changes: 2 additions & 3 deletions spec/test/stored_queries/test_djornl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import unittest
import os

from spec.test.helpers import get_config, modified_environ, create_test_docs, run_query
from spec.test.helpers import get_config, modified_environ, create_test_docs, run_query, check_spec_test_env
from importers.djornl.parser import DJORNL_Parser
from relation_engine_server.utils.wait_for import wait_for_api

_CONF = get_config()
_TEST_DIR = '/app/spec/test'
Expand All @@ -27,7 +26,7 @@ class Test_DJORNL_Stored_Queries(unittest.TestCase):
@classmethod
def setUpClass(cls):

wait_for_api()
check_spec_test_env()
# import the results file
results_file = os.path.join(_TEST_DIR, 'djornl', 'results.json')
with open(results_file) as fh:
Expand Down
6 changes: 2 additions & 4 deletions spec/test/stored_queries/test_list_test_vertices.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import unittest
import requests

from spec.test.helpers import create_test_docs, get_config
from relation_engine_server.utils.wait_for import wait_for_api
from spec.test.helpers import create_test_docs, get_config, check_spec_test_env

_CONF = get_config()
_QUERY_URL = _CONF['re_api_url'] + '/api/v1/query_results?view=list_test_vertices'
Expand All @@ -12,8 +11,7 @@ class TestListTestVertices(unittest.TestCase):

@classmethod
def setUpClass(cls):
# Wait for the API to come online
wait_for_api()
check_spec_test_env()

def test_valid(self):
"""Test a valid query."""
Expand Down
5 changes: 2 additions & 3 deletions spec/test/stored_queries/test_ncbi_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import unittest
import requests

from spec.test.helpers import get_config, assert_subset, create_test_docs
from relation_engine_server.utils.wait_for import wait_for_api
from spec.test.helpers import get_config, assert_subset, create_test_docs, check_spec_test_env

_CONF = get_config()
_NOW = int(time.time() * 1000)
Expand All @@ -19,7 +18,7 @@ class TestNcbiTax(unittest.TestCase):
def setUpClass(cls):
"""Create test documents"""

wait_for_api()
check_spec_test_env()

taxon_docs = [
{'_key': '1', 'scientific_name': 'Bacteria', 'rank': 'Domain', 'strain': False},
Expand Down
5 changes: 2 additions & 3 deletions spec/test/stored_queries/test_taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import unittest
import requests

from spec.test.helpers import get_config, assert_subset, create_test_docs
from relation_engine_server.utils.wait_for import wait_for_api
from spec.test.helpers import get_config, assert_subset, create_test_docs, check_spec_test_env

_CONF = get_config()
_NOW = int(time.time() * 1000)
Expand All @@ -19,7 +18,7 @@ class TestTaxonomy(unittest.TestCase):
def setUpClass(cls):
"""Create test documents"""

wait_for_api()
check_spec_test_env()
taxon_docs = [
{'_key': '1', 'scientific_name': 'Bacteria', 'rank': 'Domain', 'strain': False},
{'_key': '2', 'scientific_name': 'Firmicutes', 'rank': 'Phylum', 'strain': False},
Expand Down
5 changes: 2 additions & 3 deletions spec/test/stored_queries/test_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import unittest
import json
import requests
from spec.test.helpers import get_config, create_test_docs
from relation_engine_server.utils.wait_for import wait_for_api
from spec.test.helpers import get_config, create_test_docs, check_spec_test_env

_CONF = get_config()

Expand Down Expand Up @@ -34,7 +33,7 @@ def setUpClass(cls):
Create all test data.
"""

wait_for_api()
check_spec_test_env()

ws_object_version = [
_ws_obj(1, 1, 1), # root/origin object
Expand Down