|
1
|
|
|
from unittest import TestCase |
|
2
|
|
|
from mock import patch |
|
3
|
|
|
import btcde |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class TestBtcdeApi(TestCase): |
|
7
|
|
|
"""Test Api Functions.""" |
|
8
|
|
|
|
|
9
|
|
|
def setUp(self): |
|
10
|
|
|
self.patcher = patch('btcde.APIConnect') |
|
11
|
|
|
self.mock_APIConnect = self.patcher.start() |
|
12
|
|
|
|
|
13
|
|
|
def tearDown(self): |
|
14
|
|
|
self.patcher.stop() |
|
15
|
|
|
|
|
16
|
|
|
def assertArguments(expected_arguments, mock_APIConnect): |
|
17
|
|
|
for idx, expected in enumerate(expected_arguments): |
|
18
|
|
|
actual = mock_APIConnect.call_args[0][idx] |
|
19
|
|
|
self.assertEqual(actual, expected, |
|
20
|
|
|
'Argument {} with value {} ' |
|
21
|
|
|
'does not match expected {}'.format(idx, |
|
22
|
|
|
actual, |
|
23
|
|
|
expected)) |
|
24
|
|
|
|
|
25
|
|
|
def test_showOrderbook_buy_and_sell(self): |
|
26
|
|
|
methods = 'buy', 'sell' |
|
27
|
|
|
for method in method: |
|
28
|
|
|
result = btcde.showOrderbook('mock', method) |
|
29
|
|
|
expected_arguments = ['mock', 'GET', {'type': method}, btcde.orderuri] |
|
30
|
|
|
assertArguments(expected_arguments, self.mock_APIConnect) |
|
31
|
|
|
|
|
32
|
|
|
def test_createOrder(self): |
|
33
|
|
|
OrderType = 'now' |
|
34
|
|
|
max_amount = 5 |
|
35
|
|
|
price = 10 |
|
36
|
|
|
result = btcde.createOrder('mock', OrderType, max_amount, price) |
|
37
|
|
|
params = {'type': OrderType, 'max_amount': max_amount, 'price': price} |
|
38
|
|
|
expected_arguments = ['mock', 'POST', params, btcde.orderuri] |
|
39
|
|
|
assertArguments(expected_arguments, self.mock_APIConnect) |
|
40
|
|
|
|
|
41
|
|
|
def test_deleteOrder(self): |
|
42
|
|
|
order_id = 42 |
|
43
|
|
|
result = btcde.deleteOrder('mock', order_id) |
|
44
|
|
|
params = {'order_id': order_id} |
|
45
|
|
|
expected_arguments = ['mock', 'DELETE', params, btcde.orderuri + "/" + order_id] |
|
46
|
|
|
assertArguments(expected_arguments, self.mock_APIConnect) |
|
47
|
|
|
|
|
48
|
|
|
def test_showMyOrders(self): |
|
49
|
|
|
result = btcde.showMyOrders('mock') |
|
50
|
|
|
expected_arguments = ['mock', 'GET', btcde.orderuri + '/my_own'] |
|
51
|
|
|
assertArguments(expected_arguments, self.mock_APIConnect) |
|
52
|
|
|
|
|
53
|
|
|
def test_showMyOrderDetails(self): |
|
54
|
|
|
order_id = 42 |
|
55
|
|
|
result = btcde.showMyOrderDetails('mock', order_id) |
|
56
|
|
|
params = {'order_id': order_id} |
|
57
|
|
|
expected_arguments = ['mock', 'GET', btcde.orderuri + '/' + order_id] |
|
58
|
|
|
assertArguments(expected_arguments, self.mock_APIConnect) |
|
59
|
|
|
|
|
60
|
|
|
|