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

Added repo endpoint. Fixed search test fixtures.

parent 85e448dd
......@@ -5,7 +5,7 @@ import mongoengine.errors
from flask_cors import CORS
import logging
from nomad import users, files
from nomad import users, files, search
from nomad.processing import UploadProc
from nomad.utils import get_logger
......@@ -75,6 +75,17 @@ class Upload(Resource):
return Uploads._render(upload), 200
class Repo(Resource):
def get(self, upload_hash, calc_hash):
try:
data = search.Calc.get(id='%s/%s' % (upload_hash, calc_hash))
except Exception as e:
# TODO
abort(404, message=str(e))
return data, 200
@app.route('/archive/<string:upload_hash>/<string:calc_hash>', methods=['GET'])
def get_calc(upload_hash, calc_hash):
archive_id = '%s/%s' % (upload_hash, calc_hash)
......@@ -91,6 +102,7 @@ def get_calc(upload_hash, calc_hash):
api.add_resource(Uploads, '/uploads')
api.add_resource(Upload, '/uploads/<string:upload_id>')
api.add_resource(Repo, '/repo/<string:upload_hash>/<string:calc_hash>')
if __name__ == '__main__':
......
......@@ -13,8 +13,7 @@
# limitations under the License.
import pytest
from elasticsearch_dsl import Index
from elasticsearch.exceptions import NotFoundError
from typing import Generator
from datetime import datetime
from nomad.parsing import LocalBackend
......@@ -24,26 +23,20 @@ from tests.test_normalizing import normalized_vasp_example # pylint: disable=un
from tests.test_parsing import parsed_vasp_example # pylint: disable=unused-import
@pytest.fixture(scope='function', autouse=True)
def index():
""" Fixture that ensures Calc index creation before and deletion after each test. """
Calc.init()
yield
try:
Index('calcs').delete()
except NotFoundError:
pass
def test_add(normalized_vasp_example: LocalBackend):
Calc.add_from_backend(
@pytest.fixture(scope='function')
def example_entry(normalized_vasp_example: LocalBackend) -> Generator[Calc, None, None]:
entry = Calc.add_from_backend(
normalized_vasp_example,
upload_hash='test_upload_hash',
calc_hash='test_calc_hash',
mainfile='/test/mainfile',
upload_time=datetime.now())
yield entry
entry.delete()
result = Calc.get(id='%s/%s' % ('test_upload_hash', 'test_calc_hash'))
def test_add(example_entry: Calc):
result = Calc.get(id='%s/%s' % (example_entry.upload_hash, example_entry.calc_hash))
assert result is not None
for property in Calc._doc_type.mapping:
......
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