Coverage for CIResults/forms.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 09:20 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 09:20 +0000
1from django import forms
2from django.db import transaction
3from django.utils.functional import cached_property
5from collections import OrderedDict
7from .models import Test
10class TestMassRenameForm(forms.Form):
11 substring_from = forms.CharField()
12 substring_to = forms.CharField()
14 @cached_property
15 def affected_tests(self):
16 tests = OrderedDict()
18 if self.is_valid():
19 substring_from = self.cleaned_data.get('substring_from')
20 substring_to = self.cleaned_data.get('substring_to')
22 if substring_from is not None and substring_to is not None:
23 tmp = Test.objects.order_by('testsuite__name', 'name').prefetch_related('testsuite')
24 for test in tmp.filter(name__contains=substring_from):
25 new_name = test.name.replace(substring_from, substring_to)
26 tests[test] = new_name
28 return tests
30 @transaction.atomic
31 def do_renaming(self):
32 if self.is_valid():
33 for test, new_name in self.affected_tests.items():
34 test.rename(new_name)