Commit f76a1ebb authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed test cases.

parent 873c4856
......@@ -17,7 +17,8 @@ from ..decorators import json
from ..decorators.paginate import paginate_queryparams, paginate
from ..dmss import diagram_data_types
from ..errors import InvalidEncRequest
from ..utils import generate_auth_token, verify_auth_token, flag_to_gitlab, reformat_user_formula, hill_decomposition
from ..utils import generate_auth_token, verify_auth_token, flag_to_gitlab, reformat_user_formula, hill_decomposition, \
get_atom_symbol
LOGGER = logging.getLogger(__name__)
......@@ -152,7 +153,10 @@ def get_materials(page, per_page):
elements = reformat_user_formula(user_formula)
elif user_elements is not None:
elements, _ = hill_decomposition(user_elements.split(","))
try:
elements, _ = hill_decomposition(user_elements.split(","))
except Exception:
raise InvalidEncRequest("Could not parse given elements %s." % user_elements, 400)
if elements is not None:
if exclusive:
......@@ -252,8 +256,6 @@ def get_materials(page, per_page):
}
}
print(es_request_body)
es_search_results = es.search(index=es_config['index'], doc_type='material', body=es_request_body)
total_es_search_results = es_search_results['hits']['total']
materials_found_list = [render_es_result(hit['_source']) for hit in es_search_results['hits']['hits']]
......
......@@ -12,7 +12,7 @@ _default_dmss_db = os.environ.get('ENC_API_DMSS_DB', 'nomad_dmss')
_default_es_host = os.environ.get('ENC_API_ES_HOST', 'localhost')
_default_es_port = int(os.environ.get('ENC_API_ES_PORT', '9200'))
_default_es_index = os.environ.get('ENC_API_ES_INDEX', 'aggregated')
_default_es_index = os.environ.get('ENC_API_ES_INDEX', 'nomad_aggregated')
parser = argparse.ArgumentParser(description='The encyclopedia API.')
parser.add_argument('--dmss-host', help='the mongo dmss host name or ip address', default=_default_dmss_host)
......
......@@ -7,6 +7,14 @@ services with ingested data from ./data.
The given data belongs to one material and this material needs to
have the id "1".
To process/ingest data for test use:
```
enc process ./data --set-label api-test --update
enc ingest --mongo --reset-mongo-dmss --label api-test
enc search --mongo-ids --reset-search
```
The test for mongodb data use a mongodb mockup based
on the mongodb export in `.mockup_data.json`. This export is
created from an actual mongo dmss that contains the fully ingested data
......
......@@ -31,7 +31,7 @@ calc_keys = [
# "band_gap_direct",
# "basis_set_short_name",
"basis_set_type",
"brillouin_zone_json",
# "brillouin_zone_json",
# "calculation_pid",
"cell_volume",
"code_name",
......@@ -173,7 +173,7 @@ class ApiTest(unittest.TestCase):
data = self.get_first('/materials/%s/calculations' % material_id)
for key in calc_keys:
assert key in data
self.assertIn(key, data)
def test_calc_properties(self):
calc = self.get_first('/materials/%s/calculations' % material_id)
......@@ -219,11 +219,11 @@ class ApiTest(unittest.TestCase):
query = dict(filter)
query['search_by'] = match
data = self.post("/materials", query)
assert 'results' in data
self.assertIn('results', data)
if has_results:
assert len(data['results']) > 0
self.assertTrue(data['results'])
else:
assert len(data['results']) == 0
self.assertFalse(data['results'])
def test_search_all(self):
self.perform_search_test({}, {}, True)
......@@ -233,17 +233,19 @@ class ApiTest(unittest.TestCase):
self.perform_search_test(dict(page=2), {}, False)
def test_formula_search(self):
self.perform_search_test(dict(formula='CrBr', exclusive='0'), {}, True)
self.perform_search_test(dict(formula='Cr', exclusive='1'), {}, True)
self.perform_search_test(dict(formula='Cr', exclusive='0'), {}, True)
self.perform_search_test(dict(formula='CrBr', exclusive='0'), {}, False)
self.perform_search_test(dict(formula='CrBr', exclusive='1'), {}, False)
self.perform_search_test(dict(formula='Cr', exclusive='1'), {}, True)
def test_elements_search(self):
def elements(atoms):
return ",".join(["e%d" % get_atom_number(atom) for atom in atoms])
return ",".join(atoms)
self.perform_search_test(dict(elements=elements(['Cr', 'Br']), exclusive='0'), {}, True)
self.perform_search_test(dict(elements=elements(['Cr', 'Br'])), {}, False)
self.perform_search_test(dict(elements=elements(['Cr'])), {}, True)
self.perform_search_test(dict(element=elements(['Cr', 'Br']), exclusive='1'), {}, False)
self.perform_search_test(dict(element=elements(['Cr', 'Br'])), {}, False)
self.perform_search_test(dict(element=elements(['Cr']), exclusive='1'), {}, True)
self.perform_search_test(dict(element=elements(['Cr'])), {}, True)
def test_search_filters(self):
self.perform_search_test(dict(formula='Cr'), dict(has_dos=False), True)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment