Coverage for tests/django_tests/db/accounts/test_space.py: 100%
31 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 django.db.utils import IntegrityError
3from django_napse.core.models import Bot, Controller, Credit, EmptyBotConfig, EmptyStrategy, Fleet, NapseSpace, SinglePairArchitecture
4from django_napse.utils.model_test_case import ModelTestCase
6"""
7python tests/test_app/manage.py test tests.django_tests.db.accounts.test_space -v2 --keepdb --parallel
8"""
11class NapseSpaceTestCase:
12 model = NapseSpace
14 def simple_create(self):
15 return NapseSpace.objects.create(name="Test Space", exchange_account=self.exchange_account, description="This is a test space")
17 def test_error_create_napse_space_with_same_name(self):
18 NapseSpace.objects.create(name="Test Space", exchange_account=self.exchange_account, description="This is a test space")
19 with self.assertRaises(IntegrityError):
20 NapseSpace.objects.create(name="Test Space", exchange_account=self.exchange_account, description="This is a test space")
22 def _build_fleet_context(self):
23 config = EmptyBotConfig.objects.create(space=self.space, settings={"empty": True})
24 controller = Controller.get(
25 exchange_account=self.exchange_account,
26 base="BTC",
27 quote="USDT",
28 interval="1m",
29 )
30 architecture = SinglePairArchitecture.objects.create(constants={"controller": controller})
31 strategy = EmptyStrategy.objects.create(config=config, architecture=architecture)
32 template_bot = Bot.objects.create(name="Test Bot", strategy=strategy)
33 fleet = Fleet.objects.create(
34 name="Test Fleet",
35 exchange_account=self.exchange_account,
36 clusters=[
37 {
38 "template_bot": template_bot,
39 "share": 0.7,
40 "breakpoint": 1000,
41 "autoscale": False,
42 },
43 {
44 "template_bot": template_bot,
45 "share": 0.3,
46 "breakpoint": 1000,
47 "autoscale": True,
48 },
49 ],
50 )
51 Credit.objects.create(wallet=self.space.wallet, amount=1000, ticker="USDT")
52 connections = fleet.invest(self.space, 1000, "USDT")
53 return fleet, connections
55 def test_value_property(self):
56 self._build_fleet_context()
57 self.assertEqual(self.space.value, 1000)
59 def test_fleets_property(self):
60 fleet, _ = self._build_fleet_context()
61 self.assertEqual(len(self.space.fleets), 1)
62 self.assertEqual(self.space.fleets[0].uuid, fleet.uuid)
65class NaspeSpaceBINANCETestCase(NapseSpaceTestCase, ModelTestCase):
66 exchange = "BINANCE"