implement test to reproduce it

This commit is contained in:
gcarq 2017-09-30 17:01:12 +02:00
parent 6389778d49
commit 898ab5a370

View File

@ -1,6 +1,7 @@
import unittest import unittest
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock, call
import copy
from jsonschema import validate from jsonschema import validate
from freqtrade import exchange from freqtrade import exchange
@ -29,7 +30,10 @@ class TestMain(unittest.TestCase):
"key": "key", "key": "key",
"secret": "secret", "secret": "secret",
"pair_whitelist": [ "pair_whitelist": [
"BTC_ETH" "BTC_ETH",
"BTC_TKN",
"BTC_TRST",
"BTC_SWT",
] ]
}, },
"telegram": { "telegram": {
@ -50,19 +54,27 @@ class TestMain(unittest.TestCase):
'last': 0.07256061 'last': 0.07256061
}), }),
buy=MagicMock(return_value='mocked_order_id')): buy=MagicMock(return_value='mocked_order_id')):
# Save state of current whitelist
whitelist = copy.deepcopy(self.conf['bittrex']['pair_whitelist'])
init(self.conf, 'sqlite://') init(self.conf, 'sqlite://')
trade = create_trade(15.0, exchange.Exchange.BITTREX) for pair in ['BTC_ETH', 'BTC_TKN', 'BTC_TRST', 'BTC_SWT']:
Trade.session.add(trade) trade = create_trade(15.0, exchange.Exchange.BITTREX)
Trade.session.flush() Trade.session.add(trade)
self.assertIsNotNone(trade) Trade.session.flush()
self.assertEqual(trade.open_rate, 0.072661) self.assertIsNotNone(trade)
self.assertEqual(trade.pair, 'BTC_ETH') self.assertEqual(trade.open_rate, 0.072661)
self.assertEqual(trade.exchange, exchange.Exchange.BITTREX) self.assertEqual(trade.pair, pair)
self.assertEqual(trade.amount, 206.43811673387373) self.assertEqual(trade.exchange, exchange.Exchange.BITTREX)
self.assertEqual(trade.stake_amount, 15.0) self.assertEqual(trade.amount, 206.43811673387373)
self.assertEqual(trade.is_open, True) self.assertEqual(trade.stake_amount, 15.0)
self.assertIsNotNone(trade.open_date) self.assertEqual(trade.is_open, True)
buy_signal.assert_called_once_with('BTC_ETH') self.assertIsNotNone(trade.open_date)
self.assertEqual(whitelist, self.conf['bittrex']['pair_whitelist'])
buy_signal.assert_has_calls(
[call('BTC_ETH'), call('BTC_TKN'), call('BTC_TRST'), call('BTC_SWT')]
)
def test_2_handle_trade(self): def test_2_handle_trade(self):
with patch.dict('freqtrade.main._CONF', self.conf): with patch.dict('freqtrade.main._CONF', self.conf):