|
1 | | -import pytest |
2 | | -import gdax |
3 | | -import gdax.orderbook |
4 | 1 | import json |
5 | | -import asyncio |
6 | | -from asynctest import MagicMock, patch, CoroutineMock, call |
7 | 2 | import uuid |
| 3 | +import base64 |
8 | 4 | from decimal import Decimal |
9 | 5 |
|
| 6 | +import asyncio |
| 7 | +import pytest |
| 8 | +from asynctest import MagicMock, patch, CoroutineMock, call |
| 9 | + |
| 10 | +import gdax |
| 11 | +import gdax.orderbook |
| 12 | + |
10 | 13 |
|
11 | 14 | class AsyncContextManagerMock(MagicMock): |
12 | 15 | async def __aenter__(self): |
@@ -204,3 +207,27 @@ async def test_heartbeat(self, mock_book, mock_connect): |
204 | 207 | heartbeat_msg = {'type': 'heartbeat', 'on': True} |
205 | 208 | calls = [call(subscribe_msg), call(heartbeat_msg)] |
206 | 209 | mock_connect.return_value.aenter.send_json.assert_has_calls(calls) |
| 210 | + |
| 211 | + @patch('gdax.trader.Trader.get_product_order_book') |
| 212 | + async def test_authentication(self, mock_book, mock_connect, mocker): |
| 213 | + mock_connect.return_value.aenter.send_json = CoroutineMock() |
| 214 | + mock_book.return_value = {'bids': [], 'asks': [], 'sequence': 1} |
| 215 | + timestamp = '1493343391.076892' |
| 216 | + mocker.patch('time.time', return_value=timestamp) |
| 217 | + product_ids = ['ETH-USD'] |
| 218 | + async with gdax.orderbook.OrderBook( |
| 219 | + product_ids, |
| 220 | + api_key='a', |
| 221 | + api_secret=base64.b64encode(b'a' * 64), |
| 222 | + passphrase='b', |
| 223 | + ) as orderbook: |
| 224 | + msg = { |
| 225 | + 'type': 'subscribe', |
| 226 | + 'product_ids': product_ids, |
| 227 | + 'signature': '5qne58tAXSW3OJlU/GoC+/mTLF1xgT8vucjJWFZzhsU=', |
| 228 | + 'timestamp': timestamp, |
| 229 | + 'key': 'a', |
| 230 | + 'passphrase': 'b', |
| 231 | + } |
| 232 | + assert orderbook._authenticated |
| 233 | + mock_connect.return_value.aenter.send_json.assert_called_with(msg) |
0 commit comments