Coverage for CIResults/tests/test_template_filters.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-19 09:20 +0000

1from django.test import TestCase 

2from django.utils import timezone 

3from datetime import timedelta 

4from unittest.mock import patch 

5 

6from CIResults.templatetags.runconfig_diff import show_test 

7from CIResults.templatetags.helpers import howlongago, csl 

8 

9from CIResults.models import Test, RunConfig, Machine 

10 

11 

12class ShowTestTests(TestCase): 

13 def test_new_test(self): 

14 test = Test(name="test", first_runconfig=None, vetted_on=None) 

15 self.assertEqual(show_test(test), "{test} (NEW)") 

16 

17 def test_suppressed_test(self): 

18 test = Test(name="test", first_runconfig=RunConfig(), vetted_on=None) 

19 self.assertEqual(show_test(test), "{test}") 

20 

21 def test_active_test(self): 

22 test = Test(name="test", first_runconfig=RunConfig(), vetted_on=timezone.now()) 

23 self.assertEqual(show_test(test), "test") 

24 

25 

26class HowLongAgoTests(TestCase): 

27 def test_None(self): 

28 self.assertEqual(howlongago(None), "Never") 

29 

30 @patch('django.utils.timezone.now', return_value=timezone.now()) 

31 def test_valid_datetime(self, now_mock): 

32 date = now_mock.return_value - timedelta(days=1, hours=3, seconds=2) 

33 self.assertEqual(howlongago(date), "1 day, 3 hours ago") 

34 

35 

36class CslTests(TestCase): 

37 def test_empty_list(self): 

38 self.assertEqual(csl([], "machine:CIResults/basic/machine.html"), "") 

39 

40 def test_list_of_machines(self): 

41 machines = [] 

42 for m in range(3): 

43 machines.append(Machine.objects.create(name='machine{}'.format(m), public=True)) 

44 

45 result = csl(machines, "machine:CIResults/basic/machine.html") 

46 

47 for m in range(3): 

48 self.assertIn('machine{}'.format(m), result)