Coverage for django_napse/core/models/bots/managers/strategy.py: 75%
16 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 import models
4class StrategyManager(models.Manager):
5 def create(self, **kwargs):
6 architecture = kwargs["architecture"]
7 config = kwargs["config"]
8 if architecture.__class__ != self.model.architecture_class():
9 error_msg = f"architecture must be of type {self.model.architecture_class().__name__}"
10 raise TypeError(error_msg)
11 if config.__class__ != self.model.config_class():
12 error_msg = f"config must be of type {self.model.config_class().__name__}"
13 raise TypeError(error_msg)
14 strategy = self.model(**kwargs)
15 strategy.save()
16 for plugin in self.model.plugin_classes():
17 plugin.objects.create(strategy=strategy)
18 return strategy