feat: add operation template models and preventive intervention logic with associated tests
This commit is contained in:
parent
3d55121fbc
commit
7b519f16bd
2 changed files with 22 additions and 0 deletions
|
|
@ -1355,6 +1355,7 @@ class OperationTemplate(models.Model):
|
|||
model_name = ct.model.lower()
|
||||
if model_name not in filters:
|
||||
filters[model_name] = set()
|
||||
filters[model_name].add(entry.asset_model_object_id)
|
||||
return filters if filters else None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,27 @@ class OperationTemplateTests(TestCase):
|
|||
self.assertEqual(operations[0].template_group, 'Equipment Check')
|
||||
self.assertEqual(operations[1].template_group, 'Generic Inspection')
|
||||
|
||||
def test_get_asset_model_filters(self):
|
||||
"""Test that get_asset_model_filters returns the correct dictionary with asset model IDs."""
|
||||
from interventions.models import OperationTemplateAssetModelFilter
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from common.models import Thematic
|
||||
|
||||
ct = ContentType.objects.get_for_model(Thematic)
|
||||
|
||||
# Create a filter entry
|
||||
filter_entry = OperationTemplateAssetModelFilter.objects.create(
|
||||
template=self.equipment_template,
|
||||
asset_model_content_type=ct,
|
||||
asset_model_object_id=999
|
||||
)
|
||||
|
||||
filters = self.equipment_template.get_asset_model_filters()
|
||||
self.assertIsNotNone(filters)
|
||||
self.assertIn('thematic', filters)
|
||||
self.assertIn(999, filters['thematic'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue