Commit 68a90907 authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Added unit tests for CLI.

parent 161ccf03
.cache/
dist/
transfer_client.egg-info/
*.pyc
transfer_client.egg-info
dist
......@@ -12,7 +12,7 @@ license = 'MIT License'
keywords = []
dependencies = ['requests', 'urllib3']
develop_dependencies = ['pytest', 'tox']
develop_dependencies = ['fake-open', 'pytest', 'tox']
supported = [(2, 7), (3, 3), (3, 4)]
classifiers = [
'Development Status :: 3 - Alpha',
......
"""
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')
from __future__ import unicode_literals
import argparse
import getpass
import hashlib
......
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