Commit 2674de0e authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added minimal integration tests.

parent 14600b0b
......@@ -46,7 +46,7 @@ def create_client(
host: str = config.services.api_host,
port: int = config.services.api_port,
base_path: str = config.services.api_base_path,
user: str = user, password: str = None):
user: str = user, password: str = pw):
""" A factory method to create the client. """
if user is not None:
......@@ -74,7 +74,7 @@ def handle_common_errors(func):
return wrapper
def upload_file(file_path: str, name: str = None, offline: bool = False, unstage: bool = False):
def upload_file(file_path: str, name: str = None, offline: bool = False, unstage: bool = False, client = None):
"""
Upload a file to nomad.
......@@ -83,8 +83,11 @@ def upload_file(file_path: str, name: str = None, offline: bool = False, unstage
name: optional name, default is the file_path's basename
offline: allows to process data without upload, requires client to be run on the server
unstage: automatically unstage after successful processing
Returns: The upload_id
"""
client = _cli_client()
if client is None:
client = _cli_client()
if offline:
upload = client.uploads.upload(
local_path=os.path.abspath(file_path), name=name).reponse().result
......@@ -117,6 +120,8 @@ def upload_file(file_path: str, name: str = None, offline: bool = False, unstage
elif unstage:
client.uploads.exec(upload_id=upload.upload_id, operation='unstage').reponse()
return upload.upload_id
class CalcProcReproduction:
"""
......
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from nomad.client import create_client, upload_file
from tests.test_files import example_file
@pytest.fixture(scope='session')
def client():
return create_client()
def test_client(client):
client.repo.get_calcs().response()
def test_upload(client):
upload_id = upload_file(example_file, client=client)
client.uploads.delete(upload_id=upload_id).response()
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from nomad.client import create_client, upload_file
from tests.test_files import example_file
@pytest.fixture(scope='session')
def client():
return create_client()
def test_client(client):
client.repo.get_calcs().response()
def test_upload(client):
upload_file(example_file, client=client)
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