Coverage for tests/django_tests/db/datasets/test_dataset.py: 100%

63 statements  

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

1from datetime import datetime 

2 

3from pytz import UTC 

4 

5from django_napse.core.models import Controller 

6from django_napse.simulations.models import DataSet 

7from django_napse.utils.errors import DataSetError 

8from django_napse.utils.model_test_case import ModelTestCase 

9 

10""" 

11python tests/test_app/manage.py test tests.django_tests.datasets.test_dataset -v2 --keepdb --parallel 

12""" 

13 

14 

15class DataSetTestCase: 

16 model = DataSet 

17 

18 def simple_create(self): 

19 controller = Controller.get( 

20 exchange_account=self.exchange_account, 

21 base="BTC", 

22 quote="USDT", 

23 interval="1d", 

24 ) 

25 return DataSet.objects.create( 

26 controller=controller, 

27 start_date=datetime(2021, 1, 1, tzinfo=UTC), 

28 end_date=datetime(2021, 4, 1, tzinfo=UTC), 

29 ) 

30 

31 def test_download_on_top(self): 

32 dataset = self.simple_create() 

33 DataSet.objects.create( 

34 controller=dataset.controller, 

35 start_date=datetime(2021, 1, 1, tzinfo=UTC), 

36 end_date=datetime(2021, 5, 1, tzinfo=UTC), 

37 ) 

38 

39 def test_info_small(self): 

40 controller = Controller.get( 

41 exchange_account=self.exchange_account, 

42 base="BTC", 

43 quote="USDT", 

44 interval="1d", 

45 ) 

46 dataset = DataSet.objects.create( 

47 controller=controller, 

48 start_date=datetime(2021, 1, 1, tzinfo=UTC), 

49 end_date=datetime(2021, 1, 3, tzinfo=UTC), 

50 ) 

51 dataset.info(verbose=False) 

52 

53 def test_error_save_completion_lt_0(self): 

54 dataset = self.simple_create() 

55 dataset.completion = -1 

56 with self.assertRaises(DataSetError.InvalidSettings): 

57 dataset.save() 

58 

59 def test_error_save_completion_gt_100(self): 

60 dataset = self.simple_create() 

61 dataset.completion = 101 

62 with self.assertRaises(DataSetError.InvalidSettings): 

63 dataset.save() 

64 

65 def test_error_save_status_not_in_download_status(self): 

66 dataset = self.simple_create() 

67 dataset.status = "random status" 

68 with self.assertRaises(DataSetError.InvalidSettings): 

69 dataset.save() 

70 

71 def test_error_already_downloading(self): 

72 dataset = self.simple_create() 

73 dataset.status = "DOWNLOADING" 

74 dataset.save() 

75 with self.assertRaises(DataSetError.InvalidSettings): 

76 dataset.set_downloading() 

77 

78 def test_error_already_idle(self): 

79 dataset = self.simple_create() 

80 dataset.status = "IDLE" 

81 dataset.save() 

82 with self.assertRaises(DataSetError.InvalidSettings): 

83 dataset.set_idle() 

84 

85 def test_is_finished(self): 

86 dataset = self.simple_create() 

87 self.assertTrue(dataset.is_finished()) 

88 

89 dataset.status = "DOWNLOADING" 

90 dataset.completion = 50 

91 dataset.save() 

92 self.assertFalse(dataset.is_finished()) 

93 

94 dataset.status = "DOWNLOADING" 

95 dataset.completion = 100 

96 dataset.save() 

97 self.assertFalse(dataset.is_finished()) 

98 

99 dataset.status = "IDLE" 

100 dataset.completion = 50 

101 dataset.save() 

102 self.assertFalse(dataset.is_finished()) 

103 

104 

105class DataSetBINANCETestCase(DataSetTestCase, ModelTestCase): 

106 exchange = "BINANCE"