|
1 | 1 | import pytest |
2 | 2 | import urllib2 |
3 | 3 |
|
| 4 | +from mock import Mock |
| 5 | + |
4 | 6 | from Cryptsy import Api |
5 | 7 |
|
6 | 8 |
|
@@ -45,24 +47,68 @@ def test_marketid_should_be_added_as_get_parameter(self, mock_urlopen, |
45 | 47 |
|
46 | 48 |
|
47 | 49 | @pytest.fixture |
48 | | -def mock_create_order(monkeypatch): |
| 50 | +def mock_create_order(api): |
49 | 51 | """ Mock the create order so we can check if the correct ordertype is |
50 | 52 | used. """ |
51 | | - def _mock_create_order(self, marketid, ordertype, quantity, price): |
52 | | - return ordertype |
53 | | - |
54 | | - monkeypatch.setattr(Api, '_create_order', _mock_create_order) |
| 53 | + api._create_order = Mock() |
55 | 54 |
|
56 | 55 |
|
57 | 56 | def test_buy(mock_create_order, api): |
58 | 57 | """ The buy method should call the _create_order method with the ordertyp |
59 | 58 | as 'Buy'. """ |
60 | | - rv = api.buy(26, 10, 0.0000001) |
61 | | - assert rv == 'Buy' |
| 59 | + api.buy(26, 10, 0.0000001) |
| 60 | + api._create_order.assert_called_with(26, 'Buy', 10, 0.0000001) |
62 | 61 |
|
63 | 62 |
|
64 | 63 | def test_sell(mock_create_order, api): |
65 | 64 | """ The sell method should call the _create_order method with the ordertyp |
66 | 65 | as 'Sell'. """ |
67 | 66 | rv = api.sell(26, 10, 0.0000001) |
68 | | - assert rv == 'Sell' |
| 67 | + api._create_order.assert_called_with(26, 'Sell', 10, 0.0000001) |
| 68 | + |
| 69 | + |
| 70 | +def test_generate_new_address_without_parameters(api): |
| 71 | + """ generate_new_address should raise a ValueError when no parameters are |
| 72 | + provided. """ |
| 73 | + with pytest.raises(ValueError): |
| 74 | + api.generate_new_address() |
| 75 | + |
| 76 | + |
| 77 | +@pytest.fixture |
| 78 | +def api_query_mock(api): |
| 79 | + api._api_query = Mock() |
| 80 | + return api._api_query |
| 81 | + |
| 82 | + |
| 83 | +@pytest.fixture |
| 84 | +def public_api_query_mock(api): |
| 85 | + api._public_api_query = Mock() |
| 86 | + return api._public_api_query |
| 87 | + |
| 88 | + |
| 89 | +def test_generate_new_address_currencycode(api, api_query_mock): |
| 90 | + """ Should add currencycode as request data if provided. """ |
| 91 | + api.generate_new_address(currencycode=10) |
| 92 | + api_query_mock.assert_called_with('generatenewaddress', request_data={ |
| 93 | + 'currencycode': 10 |
| 94 | + }) |
| 95 | + |
| 96 | + |
| 97 | +def test_generate_new_address_currencyid(api, api_query_mock): |
| 98 | + """ Should add currencyid as request data if provided. """ |
| 99 | + api.generate_new_address(currencyid=10) |
| 100 | + api_query_mock.assert_called_with('generatenewaddress', request_data={ |
| 101 | + 'currencyid': 10 |
| 102 | + }) |
| 103 | + |
| 104 | + |
| 105 | +def test_market_data_old(api, public_api_query_mock): |
| 106 | + """ Should use the old marketdata method if v2 is not set to True. """ |
| 107 | + api.market_data() |
| 108 | + public_api_query_mock.assert_called_with('marketdata') |
| 109 | + |
| 110 | + |
| 111 | +def test_market_data_v2(api, public_api_query_mock): |
| 112 | + """ Should use the old marketdata method if v2 is not set to True. """ |
| 113 | + api.market_data(v2=True) |
| 114 | + public_api_query_mock.assert_called_with('marketdatav2') |
0 commit comments