Commit 376d2eee authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Merge branch 'tests' into cli_patch

Conflicts:
	transfer_client/setup.py
parents 599ce8b2 68a90907
......@@ -6,7 +6,7 @@ Overview
A transfer consists of a collection of (large) files that belong together
that should be transferred (moved) from one location to another. We
consider a transfer to be successful iff all associated files have been
copied and checked for consistancy successfully. A user is associated as
copied and checked for consistency successfully. A user is associated as
owner of a transfer. Only registered users can initiate transfers. Only
one transfer can be active for a given user at any time.
A global overview of a transfer is as follows:
......
.cache/
dist/
transfer_client.egg-info/
*.pyc
transfer_client.egg-info
dist
......@@ -11,7 +11,8 @@ documentation = 'README.md'
license = 'MIT License'
keywords = []
dependencies = ['jsonschema', 'pyyaml', 'requests']
dependencies = ['jsonschema', 'pyyaml', 'requests', 'urllib3']
develop_dependencies = ['fake-open', 'pytest', 'tox']
supported = [(2, 7), (3, 3), (3, 4)]
classifiers = [
'Development Status :: 3 - Alpha',
......@@ -71,6 +72,7 @@ setup(
platforms=['any'],
packages=[package],
install_requires=dependencies,
tests_require=develop_dependencies,
entry_points={
'console_scripts': ['{0} = {0}.cli:main'.format(package)]
},
......
"""
Tests for the transfer_client CLI.
"""
from __future__ import unicode_literals
import json
from io import StringIO
from fake_open import FakeOpen, make_fake_file, md5_check
from transfer_client import cli, TransferClient
class TestCLI(object):
def setup(self):
opener = FakeOpen()
self._handles = opener.handles
cli.open = opener.open
self._fake_reply = None
self._file_handle = StringIO()
self._file_handles = [
make_fake_file('a', 'a\n'), make_fake_file('b', 'b\n')]
self._metadata_handle = StringIO('null\n')
self._output_handle = StringIO()
TransferClient._request = lambda *args, **kwargs: self._fake_reply
def test_users(self):
cli.users(self._output_handle, '127.0.0.1', '123', False)
assert self._output_handle.getvalue() == 'null\n'
def test_schema(self):
cli.schema(self._output_handle, '127.0.0.1', '123', False)
assert self._output_handle.getvalue() == 'null\n'
def test_transfers(self):
cli.transfers(
self._output_handle, self._metadata_handle,
'127.0.0.1', '123', False)
assert self._output_handle.getvalue() == 'null\n'
def test_status(self):
cli.status(self._output_handle, '127.0.0.1', '123', '456', False)
assert self._output_handle.getvalue() == 'null\n'
def test_update(self):
cli.update(
self._output_handle, '127.0.0.1', '123', '456', 'cancelled', False)
assert self._output_handle.getvalue() == 'null\n'
def test_uploads(self):
cli.uploads(
self._output_handle, self._file_handle,
'127.0.0.1', '123', '456', False)
assert self._output_handle.getvalue() == 'null\n'
def test_completed(self):
cli.completed(self._output_handle, '127.0.0.1', '789', False)
assert self._output_handle.getvalue() == 'null\n'
def test_make_metadata_1(self):
metadata = cli._make_metadata(self._file_handles, 'test')
assert metadata['title'] == 'test'
assert metadata['files'][0]['filename'] == 'a'
assert (
metadata['files'][1]['md5'] == '3b5d5c3712955042212316173ccf37be')
def test_make_metadata_2(self):
cli.make_metadata(self._output_handle, self._file_handles, 'test')
assert md5_check(
self._output_handle.getvalue(), 'ee7ca88f46ca4c7f58375279a2fbd62a')
def test_transfer(self):
self._fake_reply = {'id': 0}
cli.transfer(
self._output_handle, self._file_handles,
'127.0.0.1', '123', 'test', False)
assert md5_check(
self._output_handle.getvalue(), 'c69a4efc89677f66e67b296b5e9ced66')
def test_interrupted_transfer_1(self):
self._fake_reply = {'transfers': []}
try:
cli._interrupted_transfer(
self._output_handle, TransferClient('127.0.0.1', False), '123')
except ValueError as error:
assert error.message == 'no interrupted transfers found'
else:
assert False
def test_interrupted_transfer_2(self):
self._fake_reply = {'transfers': [{'id': 0, 'status': 'initiated'}]}
cli._interrupted_transfer(
self._output_handle, TransferClient('127.0.0.1', False), '123')
assert md5_check(
self._output_handle.getvalue(), 'b6a19671cc29806d6468b84695121344')
def test_resume(self):
self._fake_reply = {
'transfers': [
{
'id': 0,
'status': 'initiated',
'files': [
{
'status': 'pending',
'filename': 'a'
}
]
}
]
}
cli.resume(self._output_handle, '127.0.0.1', '123', False)
assert md5_check(
self._output_handle.getvalue(), '641eeda3b448cc99a9c5f74c8343d589')
def test_cancel(self):
self._fake_reply = {
'transfers': [
{
'id': 0,
'status': 'initiated'
}
]
}
cli.cancel(
self._output_handle, '127.0.0.1', '123', False)
assert md5_check(
self._output_handle.getvalue(), 'b6a19671cc29806d6468b84695121344')
"""
Tests for the transfer_client library.
"""
from io import StringIO
from transfer_client import TransferClient
class TestLibrary(object):
def setup(self):
TransferClient._request = lambda *args, **kwargs: None
self._transfer_client = TransferClient('127.0.0.1', False)
self._input_handle = StringIO()
def test_users(self):
assert self._transfer_client.users('123') == None
def test_schema(self):
assert self._transfer_client.schema('123') == None
def test_transfers(self):
assert self._transfer_client.transfers('123', {}) == None
def test_status(self):
assert self._transfer_client.status('123', '456') == None
def test_update(self):
assert self._transfer_client.update('123', '456', 'cancelled') == None
def test_uploads(self):
assert self._transfer_client.uploads(
'123', '456', self._input_handle) == None
def test_completed(self):
assert self._transfer_client.completed('789') == None
......@@ -7,20 +7,23 @@ Copyright (c) 2016 Jeroen F.J. Laros <J.F.J.Laros@lumc.nl>
Licensed under the MIT license, see the LICENSE file.
"""
from .transfer_client import TransferClient
__version_info__ = ('0', '0', '3')
__version_info__ = ('0', '0', '5')
__version__ = '.'.join(__version_info__)
__author__ = 'LUMC, Jeroen F.J. Laros'
__contact__ = 'J.F.J.Laros@lumc.nl'
__homepage__ = 'https://git.lumc.nl/j.k.vis/transfer'
usage = __doc__.split("\n\n\n")
usage = __doc__.split('\n\n\n')
def doc_split(func):
return func.__doc__.split("\n\n")[0]
return func.__doc__.split('\n\n')[0]
def version(name):
return "%s version %s\n\nAuthor : %s <%s>\nHomepage : %s" % (name,
__version__, __author__, __contact__, __homepage__)
return '{} version {}\n\nAuthor : {} <{}>\nHomepage : {}'.format(
name, __version__, __author__, __contact__, __homepage__)
from __future__ import unicode_literals
import argparse
import datetime
import getpass
......
......@@ -23,7 +23,6 @@ class TransferClient(object):
except AttributeError:
sys.stderr = open('/dev/null')
def _request(self, method, endpoint, headers=None, files=None, json=None):
"""
Handle a request.
......
Markdown is supported
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