Coverage for tests/django_tests/db/bots/test_strategy.py: 90%

30 statements  

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

1from datetime import datetime 

2 

3from django.test import TestCase 

4from pytz import UTC 

5 

6from django_napse.core.models import Bot, Strategy 

7from django_napse.simulations.models import SimulationQueue 

8 

9""" 

10python tests/test_app/manage.py test tests.django_tests.bots.test_bot -v2 --keepdb --parallel 

11""" 

12 

13 

14class StrategyDefaultTestCase: 

15 def simple_create(self): 

16 return self.model.objects.create(config=self.config, architecture=self.architecture) 

17 

18 @property 

19 def config(self): 

20 return self.model.config_class().objects.create(space=self.space, settings=self.config_settings) 

21 

22 @property 

23 def architecture(self): 

24 return self.model.architecture_class().objects.create(constants=self.architecture_constants) 

25 

26 def test_simulation(self): 

27 bot = Bot.objects.create(name="Test Bot", strategy=self.simple_create()) 

28 simulation_queue = SimulationQueue.objects.create( 

29 space=self.space, 

30 bot=bot, 

31 start_date=datetime(2022, 1, 1, tzinfo=UTC), 

32 end_date=datetime(2022, 1, 5, tzinfo=UTC), 

33 investments={"USDT": 10000}, 

34 ) 

35 

36 simulation_queue.run_quick_simulation(verbose=False) 

37 

38 

39class BotTypeCkeck(TestCase): 

40 def test_bot_type(self): 

41 subclasses = [] 

42 for subclass_level in StrategyDefaultTestCase.__subclasses__(): 

43 subclasses += subclass_level.__subclasses__() 

44 tested_strategies = {*[subclass.model for subclass in subclasses]} 

45 strategies = {*Strategy.__subclasses__()} 

46 if tested_strategies != strategies: 

47 error_msg = "You have untested Strategies. Check out the documentation to see how to test them (spoiler, it's really easy!)." 

48 error_msg += str(tested_strategies) + str(strategies) 

49 raise ValueError(error_msg)