-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use of mock api client for ping, workflows and file command tests. Closes #186 Signed-off-by: Rokas Maciulaitis <rokas.maciulaitis@cern.ch> Co-authored-by: Diego Rodriguez diego.rodriguez@cern.ch
- Loading branch information
Rokas Maciulaitis
committed
Nov 6, 2018
1 parent
4422c17
commit 2a3f6a0
Showing
9 changed files
with
432 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2017, 2018 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""REANA client files tests.""" | ||
|
||
import hashlib | ||
import json | ||
import os | ||
|
||
from click.testing import CliRunner | ||
|
||
from reana_client.cli import Config, cli | ||
|
||
|
||
def test_list_files_server_not_reachable(): | ||
"""Test list workflow workspace files when not connected to any cluster.""" | ||
message = 'REANA client is not connected to any REANA cluster.' | ||
runner = CliRunner() | ||
result = runner.invoke(cli, ['list']) | ||
assert result.exit_code == 1 | ||
assert message in result.output | ||
|
||
|
||
def test_list_files_server_no_token(): | ||
"""Test list workflow workspace files when access token is not set.""" | ||
message = 'Please provide your access token' | ||
env = {'REANA_SERVER_URL': 'localhost'} | ||
runner = CliRunner(env=env) | ||
result = runner.invoke(cli, ['list']) | ||
assert result.exit_code == 1 | ||
assert message in result.output | ||
|
||
|
||
def test_list_files_ok(mock_base_api_client): | ||
"""Test list workflow workspace files successfull.""" | ||
status_code = 200 | ||
response = [ | ||
{ | ||
"last-modified": "string", | ||
"name": "string", | ||
"size": 0 | ||
} | ||
] | ||
reana_token = '000000' | ||
env = {'REANA_SERVER_URL': 'localhost'} | ||
mocked_api_client = mock_base_api_client(status_code, | ||
response, | ||
'reana-server') | ||
config = Config(mocked_api_client) | ||
runner = CliRunner(env=env) | ||
result = runner.invoke( | ||
cli, | ||
['list', '-at', reana_token, '--workflow', 'mytest.1', '--json'], | ||
obj=config | ||
) | ||
json_response = json.loads(result.output) | ||
assert result.exit_code == 0 | ||
assert isinstance(json_response, list) | ||
assert len(json_response) == 1 | ||
assert json_response[0]['name'] in response[0]['name'] | ||
|
||
|
||
def test_download_file(mock_base_api_client): | ||
"""Test file downloading.""" | ||
status_code = 200 | ||
reana_token = '000000' | ||
env = {'REANA_SERVER_URL': 'localhost'} | ||
response = 'Content of file to download' | ||
response_md5 = hashlib.md5(response.encode('utf-8')).hexdigest() | ||
file = 'dummy_file.txt' | ||
message = 'File {0} downloaded to'.format(file) | ||
mocked_api_client = mock_base_api_client(status_code, | ||
response, | ||
'reana-server') | ||
config = Config(mocked_api_client) | ||
runner = CliRunner(env=env) | ||
result = runner.invoke( | ||
cli, | ||
['download', '-at', reana_token, '--workflow', 'mytest.1', file], | ||
obj=config | ||
) | ||
assert result.exit_code == 0 | ||
assert os.path.isfile(file) is True | ||
file_md5 = hashlib.md5(open(file, 'rb').read()).hexdigest() | ||
assert file_md5 == response_md5 | ||
assert message in result.output | ||
|
||
|
||
def test_upload_file(mock_base_api_client, create_yaml_workflow_schema): | ||
"""Test upload file.""" | ||
status_code = 200 | ||
reana_token = '000000' | ||
env = {'REANA_SERVER_URL': 'localhost'} | ||
file = 'file.txt' | ||
response = [file] | ||
message = 'was successfully uploaded.' | ||
mocked_api_client = mock_base_api_client(status_code, | ||
response, | ||
'reana-server') | ||
config = Config(mocked_api_client) | ||
runner = CliRunner(env=env) | ||
with runner.isolated_filesystem(): | ||
with open(file, 'w') as f: | ||
f.write('test') | ||
with open('reana.yaml', 'w') as reana_schema: | ||
reana_schema.write(create_yaml_workflow_schema) | ||
result = runner.invoke( | ||
cli, | ||
['upload', '-at', reana_token, '--workflow', 'mytest.1', file], | ||
obj=config | ||
) | ||
assert result.exit_code == 0 | ||
assert message in result.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.