Code Duplication    Length = 14-24 lines in 8 locations

tests/test_btcde_func.py 8 locations

@@ 205-228 (lines=24) @@
202
        self.assertEqual(history[0].url, base_url + url_args)
203
        self.assertTrue(mock_logger.debug.called)
204
205
    def test_executeTrade(self, mock_logger, m):
206
        '''Test function executeTrade.'''
207
        params = {'type': 'buy',
208
                  'trading_pair': 'btceur',
209
                  'amount': '10',
210
                  'order_id': '1337'}
211
        base_url = 'https://api.bitcoin.de/v2/trades/{}'\
212
                   .format(params.get('order_id'))
213
        url_args = '?amount={}&order_id={}&trading_pair={}&type={}'\
214
                   .format(params.get('amount'),
215
                           params.get('order_id'),
216
                           params.get('trading_pair'),
217
                           params.get('type'))
218
        response = self.sampleData('executeTrade')
219
        m.get(requests_mock.ANY, json=response, status_code=200)
220
        m.post(requests_mock.ANY, json=response, status_code=201)
221
        self.conn.executeTrade(params.get('order_id'),
222
                               params.get('type'),
223
                               params.get('trading_pair'),
224
                               params.get('amount'))
225
        history = m.request_history
226
        self.assertEqual(history[0].method, "POST")
227
        self.assertEqual(history[0].url, base_url + url_args)
228
        self.assertTrue(mock_logger.debug.called)
229
230
    def test_showMyTrades(self, mock_logger, m):
231
        '''Test function showMyTrades.'''
@@ 135-156 (lines=22) @@
132
        self.assertEqual(history[0].url, base_url + url_args)
133
        self.assertTrue(mock_logger.debug.called)
134
135
    def test_createOrder(self, mock_logger, m):
136
        '''Test function createOrder.'''
137
        params = {'type': 'buy',
138
                  'trading_pair': 'btceur',
139
                  'max_amount': '10',
140
                  'price': '10'}
141
        base_url = 'https://api.bitcoin.de/v2/orders'
142
        url_args = '?max_amount={}&price={}&trading_pair={}&type={}'\
143
                   .format(params.get('max_amount'),
144
                           params.get('price'),
145
                           params.get('trading_pair'),
146
                           params.get('type'))
147
        response = self.sampleData('createOrder')
148
        m.post(requests_mock.ANY, json=response, status_code=201)
149
        self.conn.createOrder(params.get('type'),
150
                              params.get('trading_pair'),
151
                              params.get('max_amount'),
152
                              params.get('price'))
153
        history = m.request_history
154
        self.assertEqual(history[0].method, "POST")
155
        self.assertEqual(history[0].url, base_url + url_args)
156
        self.assertTrue(mock_logger.debug.called)
157
158
    def test_deleteOrder(self, mock_logger, m):
159
        '''Test function deleteOrder.'''
@@ 372-392 (lines=21) @@
369
        del self.XAPISECRET
370
        del self.conn
371
372
    @requests_mock.Mocker()
373
    def test_APIException(self, m):
374
        '''Test API Exception.'''
375
        params = {'type': 'buy',
376
                  'trading_pair': 'btceur',
377
                  'max_amount': 10,
378
                  'price': 13}
379
        base_url = 'https://api.bitcoin.de/v2/orders'
380
        url_args = '?max_amount={}&price={}&trading_pair={}&type={}'\
381
                   .format(params.get('max_amount'),
382
                           params.get('price'),
383
                           params.get('trading_pair'),
384
                           params.get('type'))
385
        response = self.sampleData('error')
386
        m.post(requests_mock.ANY, json=response, status_code=400)
387
        self.conn.createOrder(params.get('type'),
388
                              params.get('trading_pair'), params.get('max_amount'),
389
                              price=params.get('price'))
390
        history = m.request_history
391
        self.assertEqual(history[0].method, "POST")
392
        self.assertEqual(history[0].url, base_url + url_args)
393
        
394
    @patch('btcde.log')
395
    def test_RequestException(self, mock_logger):
@@ 114-133 (lines=20) @@
111
        self.assertEqual(request_signature, verified_signature)
112
        self.assertTrue(mock_logger.debug.called)
113
114
    def test_show_orderbook(self, mock_logger, m):
115
        '''Test function showOrderbook.'''
116
        params = {'type': 'buy',
117
                  'trading_pair': 'btceur',
118
                  'max_amount': 10,
119
                  'price': 1337}
120
        base_url = 'https://api.bitcoin.de/v2/orders'
121
        url_args = '?price={}&trading_pair={}&type={}'\
122
                   .format(params.get('price'),
123
                           params.get('trading_pair'),
124
                           params.get('type'))
125
        response = self.sampleData('showOrderbook_buy')
126
        m.get(requests_mock.ANY, json=response, status_code=200)
127
        self.conn.showOrderbook(params.get('type'),
128
                                params.get('trading_pair'),
129
                                price=params.get('price'))
130
        history = m.request_history
131
        self.assertEqual(history[0].method, "GET")
132
        self.assertEqual(history[0].url, base_url + url_args)
133
        self.assertTrue(mock_logger.debug.called)
134
135
    def test_createOrder(self, mock_logger, m):
136
        '''Test function createOrder.'''
@@ 242-257 (lines=16) @@
239
        self.assertEqual(history[0].url, base_url + url_args)
240
        self.assertTrue(mock_logger.debug.called)
241
242
    def test_showMyTrades_with_params(self, mock_logger, m):
243
        '''Test function showMyTrades with parameters.'''
244
        params = {'type': 'buy',
245
                  'trading_pair': 'btceur'}
246
        base_url = 'https://api.bitcoin.de/v2/trades'
247
        url_args = '?trading_pair={}&type={}'\
248
                   .format(params.get('trading_pair'),
249
                           params.get('type'))
250
        response = self.sampleData('showMyTrades')
251
        m.get(requests_mock.ANY, json=response, status_code=200)
252
        self.conn.showMyTrades(type=params.get('type'),
253
                               trading_pair=params.get('trading_pair'))
254
        history = m.request_history
255
        self.assertEqual(history[0].method, "GET")
256
        self.assertEqual(history[0].url, base_url + url_args)
257
        self.assertTrue(mock_logger.debug.called)
258
259
    def test_showMyTradeDetails(self, mock_logger, m):
260
        '''Test function showMyTradeDetails.'''
@@ 174-189 (lines=16) @@
171
        self.assertEqual(history[0].url, base_url + url_args)
172
        self.assertTrue(mock_logger.debug.called)
173
174
    def test_showMyOrders(self, mock_logger, m):
175
        '''Test function showMyOrders.'''
176
        params = {'type': 'buy',
177
                  'trading_pair': 'btceur'}
178
        base_url = 'https://api.bitcoin.de/v2/orders/my_own'
179
        url_args = '?trading_pair={}&type={}'\
180
                   .format(params.get('trading_pair'),
181
                           params.get('type'))
182
        response = self.sampleData('showMyOrders')
183
        m.get(requests_mock.ANY, json=response, status_code=200)
184
        self.conn.showMyOrders(type=params.get('type'),
185
                               trading_pair=params.get('trading_pair'))
186
        history = m.request_history
187
        self.assertEqual(history[0].method, "GET")
188
        self.assertEqual(history[0].url, base_url + url_args)
189
        self.assertTrue(mock_logger.debug.called)
190
191
    def test_showMyOrderDetails(self, mock_logger, m):
192
        '''Test function showMyOrderDetails.'''
@@ 158-172 (lines=15) @@
155
        self.assertEqual(history[0].url, base_url + url_args)
156
        self.assertTrue(mock_logger.debug.called)
157
158
    def test_deleteOrder(self, mock_logger, m):
159
        '''Test function deleteOrder.'''
160
        params = {'trading_pair': 'btceur',
161
                  'order_id': '1337'}
162
        base_url = 'https://api.bitcoin.de/v2/orders'
163
        url_args = '/{}/{}'.format(params.get('order_id'),
164
                                   params.get('trading_pair'))
165
        response = self.sampleData('deleteOrder')
166
        m.delete(requests_mock.ANY, json=response, status_code=200)
167
        self.conn.deleteOrder(params.get('order_id'),
168
                              params.get('trading_pair'))
169
        history = m.request_history
170
        self.assertEqual(history[0].method, "DELETE")
171
        self.assertEqual(history[0].url, base_url + url_args)
172
        self.assertTrue(mock_logger.debug.called)
173
174
    def test_showMyOrders(self, mock_logger, m):
175
        '''Test function showMyOrders.'''
@@ 310-323 (lines=14) @@
307
        self.assertEqual(history[0].url, base_url + url_args)
308
        self.assertTrue(mock_logger.debug.called)
309
310
    def test_showPublicTradeHistory_since(self, mock_logger, m):
311
        '''Test function showPublicTradeHistory with since_tid.'''
312
        params = {'trading_pair': 'btceur', 'since_tid': '123'}
313
        base_url = 'https://api.bitcoin.de/v2/trades/history'
314
        url_args = '?since_tid={}&trading_pair={}'.format(params.get('since_tid'),
315
                                                          params.get('trading_pair'))
316
        response = self.sampleData('showPublicTradeHistory')
317
        m.get(requests_mock.ANY, json=response, status_code=200)
318
        self.conn.showPublicTradeHistory(params.get('trading_pair'),
319
                                         since_tid=params.get('since_tid'))
320
        history = m.request_history
321
        self.assertEqual(history[0].method, "GET")
322
        self.assertEqual(history[0].url, base_url + url_args)
323
        self.assertTrue(mock_logger.debug.called)
324
325
    def test_showRates(self, mock_logger, m):
326
        '''Test function showRates.'''