Coverage for tests/django_tests/db/histories/test_history.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-12 13:49 +0000

1from django_napse.core.models import History, HistoryDataPoint, HistoryDataPointField 

2from django_napse.utils.constants import HISTORY_DATAPOINT_FIELDS 

3from django_napse.utils.errors import HistoryError 

4from django_napse.utils.model_test_case import ModelTestCase 

5 

6""" 

7python tests/test_app/manage.py test tests.django_tests.db.histories -v2 --keepdb --parallel 

8""" 

9 

10 

11class HistoryTestCase: 

12 model = History 

13 

14 def simple_create(self): 

15 return self.model.objects.create() 

16 

17 def test_data_points(self): 

18 info = [ 

19 [ 

20 {"key": HISTORY_DATAPOINT_FIELDS.AMOUNT, "value": "1", "target_type": "float"}, 

21 {"key": HISTORY_DATAPOINT_FIELDS.ASSET, "value": "BTC", "target_type": "str"}, 

22 {"key": HISTORY_DATAPOINT_FIELDS.PRICE, "value": "123", "target_type": "float"}, 

23 {"key": HISTORY_DATAPOINT_FIELDS.MBP, "value": "100", "target_type": "float"}, 

24 {"key": HISTORY_DATAPOINT_FIELDS.LBO, "value": "7", "target_type": "float"}, 

25 ] 

26 for _ in range(100) 

27 ] 

28 history = self.simple_create() 

29 for data_point_info in info: 

30 data_point = HistoryDataPoint.objects.create(history=history) 

31 for field_info in data_point_info: 

32 HistoryDataPointField.objects.create(history_data_point=data_point, **field_info) 

33 self.assertEqual(history.data_points.count(), len(info)) 

34 

35 def test_invalid_data_point(self): 

36 history = self.simple_create() 

37 data_point = HistoryDataPoint.objects.create(history=history) 

38 

39 with self.assertRaises(HistoryError.InvalidDataPointFieldKey): 

40 HistoryDataPointField.objects.create(history_data_point=data_point, key="INVALID", value="1", target_type="float") 

41 

42 

43class HistoryBINANCETestCase(HistoryTestCase, ModelTestCase): 

44 exchange = "BINANCE"