예제 #1
0
def _find_indexer(type_module, type_name, type_version):
    """
    Find the indexer function for the given object type within the indexer_directory list.
    Returns:
        Pair of indexer function and extra configuration data to pass as the last arg
    """
    try:
        return get_es_module(type_module, type_name, type_version)
    except ModuleNotFound:
        pass
    # No indexer found for this type, check if there is a sdk indexer app
    if type_module + '.' + type_name in config()['global']['sdk_indexer_apps']:
        return (index_from_sdk, {})
    return (generic_indexer(), {})
예제 #2
0
import os
import json

from src.utils.get_es_module import get_es_module

# Load test data
with open(os.path.join(os.path.dirname(__file__), 'data/taxon.json')) as fd:
    data = json.load(fd)
(indexer, conf) = get_es_module('KBaseGenomeAnnotations', 'Taxon')


def test_taxon_indexer():
    """Valid indexing test"""
    # Mock the request against the sample service
    results = indexer(data['obj1'], data['ws_info1'], data['obj1'], conf)
    for (idx, result) in enumerate(list(results)):
        assert result == data['expected_result1'][idx]
예제 #3
0
import json
import tempfile
import shutil

from src.index_runner.es_indexers.annotated_metagenome_assembly import _index_ama
from src.utils.get_es_module import get_es_module

_DIR = os.path.dirname(os.path.realpath(__file__))

# Load test data
with open(os.path.join(_DIR, 'data/ama.json')) as fd:
    data = json.load(fd)
with open(os.path.join(_DIR, 'data/ama_check_against.json')) as fd:
    check_against = json.load(fd)
# Load module config
(indexer, conf) = get_es_module('KBaseMetagenomes', 'AnnotatedMetagenomeAssembly')


def test_annotated_metagenome_assembly_indexer():
    # the annotated_metagenome_assembly 'check_against' data is really big, so we keep it in an external file
    features_test_file = os.path.join(_DIR, "data", "features.json.gz")
    info = data['obj']['info']
    workspace_id = info[6]
    object_id = info[0]
    version = info[4]
    ama_index = f"WS::{workspace_id}:{object_id}"
    ver_ama_index = f"WSVER::{workspace_id}:{object_id}:{version}"

    try:
        tmp_dir = tempfile.mkdtemp()
        features_path = os.path.join(tmp_dir, "features.json.gz")
예제 #4
0
import os
import json

from src.utils.get_es_module import get_es_module

_DIR = os.path.dirname(__file__)

# Load test data
with open(os.path.join(_DIR, 'data/genome.json')) as fd:
    data = json.load(fd)
with open(os.path.join(_DIR, 'data/genome_check_against.json')) as fd:
    check_against = json.load(fd)
# Load module config
(indexer, conf) = get_es_module('KBaseGenomes', 'Genome')


def test_genome_valid1():
    """Valid indexing test"""
    results = indexer(data['obj1'], data['ws_info1'], data['obj1'], conf)
    for (idx, result) in enumerate(list(results)):
        assert result == check_against[idx]
예제 #5
0
import os
import json

from src.utils.get_es_module import get_es_module

# Load test data
with open(os.path.join(os.path.dirname(__file__), 'data/tree.json')) as fd:
    data = json.load(fd)
(indexer, conf) = get_es_module('KBaseTrees', 'Tree')


def test_tree_indexer():
    """Valid indexing test"""
    # Mock the request against the sample service
    results = indexer(data['obj1'], data['ws_info1'], data['obj1'], conf)
    for (idx, result) in enumerate(list(results)):
        assert result == data['expected_result1'][idx]
예제 #6
0
"""
import json
import os
import pytest
import responses

from src.utils.config import config
from src.utils.get_es_module import get_es_module

_DIR = os.path.dirname(os.path.realpath(__file__))

# Load test data
with open(os.path.join(_DIR, 'data', 'narrative.json')) as fd:
    data = json.load(fd)
# Load module config
(indexer, conf) = get_es_module('KBaseNarrative', 'Narrative')


def test_basic_valid():
    """Test the happy case."""
    narr_obj = data['obj_valid']
    ws_info = data['wsinfo_valid']
    results = list(indexer(narr_obj, ws_info, {}, conf))
    assert len(results) == 1
    result = results[0]
    assert result['_action'] == 'index'
    assert result['index'] == 'narrative_2'
    assert result['id'] == 'WS::33192:1'
    doc = result['doc']
    assert doc['narrative_title'] == 'Test fiesta'
    assert not doc['is_narratorial']
예제 #7
0
import os
import json

from src.utils.get_es_module import get_es_module

# Load test data
with open(os.path.join(os.path.dirname(__file__), 'data/assembly.json')) as fd:
    data = json.load(fd)
# Load module config
(indexer, conf) = get_es_module('KBaseGenomeAnnotations', 'Assembly')


def test_assembly_indexer():
    """Valid indexing test"""
    # Mock the request against the sample service
    results = indexer(data['obj1'], data['ws_info1'], data['obj1'], conf)
    for (idx, result) in enumerate(list(results)):
        assert result == data['expected_result1'][idx]
예제 #8
0
import os
import json

from src.utils.get_es_module import get_es_module

# Load test data
with open(os.path.join(os.path.dirname(__file__), 'data/reads.json')) as fd:
    data = json.load(fd)
(indexer, conf) = get_es_module('KBaseFile', 'PairedEndLibrary')


def test_reads_valid1():
    """Valid reads indexing test"""
    results = indexer(data['obj1'], data['ws_info1'], data['obj1'], conf)
    for (idx, result) in enumerate(list(results)):
        assert result == data['expected_result1'][idx]
예제 #9
0
import json
import os
import responses

from src.utils.config import config
from src.utils.get_es_module import get_es_module

# Load test data
with open(os.path.join(os.path.dirname(__file__), 'data/sample_set.json')) as fd:
    data = json.load(fd)
(indexer, conf) = get_es_module('KBaseSets', 'SampleSet')


@responses.activate
def test_sample_set_indexer1():
    # Mock the request that checks for an existing sample
    url = config()['elasticsearch_url'] + '/search2.sample/_doc/SMP::1:1'
    responses.add(responses.GET, url, json={'found': False})
    # Mock the request against the sample service
    responses.add(responses.POST, config()['sample_service_url'], json=data['sample_service_resp1'])
    results = indexer(data['obj1'], data['ws_info1'], data['obj1'], conf)
    for (idx, result) in enumerate(list(results)):
        assert result == data['expected_result1'][idx]