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
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from datetime import datetime
3from pytz import UTC
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
10"""
11python tests/test_app/manage.py test tests.django_tests.datasets.test_dataset -v2 --keepdb --parallel
12"""
15class DataSetTestCase:
16 model = DataSet
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 )
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 )
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)
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()
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()
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()
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()
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()
85 def test_is_finished(self):
86 dataset = self.simple_create()
87 self.assertTrue(dataset.is_finished())
89 dataset.status = "DOWNLOADING"
90 dataset.completion = 50
91 dataset.save()
92 self.assertFalse(dataset.is_finished())
94 dataset.status = "DOWNLOADING"
95 dataset.completion = 100
96 dataset.save()
97 self.assertFalse(dataset.is_finished())
99 dataset.status = "IDLE"
100 dataset.completion = 50
101 dataset.save()
102 self.assertFalse(dataset.is_finished())
105class DataSetBINANCETestCase(DataSetTestCase, ModelTestCase):
106 exchange = "BINANCE"