-
Notifications
You must be signed in to change notification settings - Fork 2
/
mamaster_test.py
56 lines (40 loc) · 1.59 KB
/
mamaster_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import unittest
import datetime
from unittest.mock import patch
import mamaster
class MamasterTest(unittest.TestCase):
@patch('ccxt.bitmex')
def test_get_current_price(self, mock_bitmex):
mamaster.CONF = self.create_default_conf()
mamaster.EXCHANGE = mock_bitmex
mamaster.get_current_price()
mock_bitmex.fetch_ticker.assert_called()
@patch('mamaster.logging')
def test_get_current_price_too_may_times(self, mock_logging):
mamaster.LOG = mock_logging
mamaster.get_current_price(7)
mock_logging.error.assert_called()
@patch('mamaster.logging')
@patch('mamaster.delete_rates_older_than')
def test_cleanup(self, mock_delete_rates_older_than, mock_logging):
mamaster.CONF = self.create_default_conf()
mamaster.LOG = mock_logging
mamaster.NOW = datetime.datetime(2020, 5, 1, 1, 2)
mamaster.cleanup()
mock_delete_rates_older_than.assert_called_with(datetime.datetime(2019, 5, 3, 1, 2))
@patch('mamaster.logging')
@patch('mamaster.delete_rates_older_than')
def test_cleanup_wrong_time(self, mock_delete_rates_older_than, mock_logging):
mamaster.CONF = self.create_default_conf()
mamaster.LOG = mock_logging
mamaster.NOW = datetime.datetime(2020, 5, 1, 2, 2)
mamaster.cleanup()
mock_delete_rates_older_than.assert_not_called()
@staticmethod
def create_default_conf():
conf = mamaster.ExchangeConfig
conf.exchange = 'bitmex'
conf.max_weeks = 52
return conf
if __name__ == '__main__':
unittest.main()