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

43 statements  

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

1from datetime import timedelta 

2 

3from django.conf import settings 

4from django.test import TestCase 

5from django.utils import timezone 

6from django.urls import reverse 

7 

8from CIResults.tests.test_views import UserFiltrableViewMixin 

9from CIResults.models import BugTracker, Issue 

10 

11 

12# HACK: Massively speed up the login primitive. We don't care about security in tests 

13settings.PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher', ) 

14 

15 

16class ApiMetricsTests(TestCase): 

17 # TODO: Re-visit this test when we have a good fixture! 

18 fixtures = ['CIResults/fixtures/RunConfigResults_commit_to_db'] 

19 

20 def test_get(self): 

21 response = self.client.get("/api/metrics") 

22 self.assertEqual(response.status_code, 200) 

23 self.assertContains(response, 

24 '{"issues": 0, "machine": 1, "suppressed_tests": 1, ' 

25 '"suppressed_machines": 1, "tests": 1, "unknown_failures": 0, "version": 1}') 

26 

27 

28class MetricsIssuesTests(UserFiltrableViewMixin, TestCase): 

29 reverse_name = "CIResults-metrics-issues" 

30 query = "expected = FALSE" 

31 

32 def setUp(self): 

33 Issue.objects.create(expected=False) 

34 # TODO: add a fixture with more variety 

35 

36 

37class MetricsBugsTests(UserFiltrableViewMixin, TestCase): 

38 reverse_name = "CIResults-metrics-bugs" 

39 query = "status = 'open'" 

40 

41 def setUp(self): 

42 # Create a bugtracker with components_followed_since set in order to 

43 # enable the testing of the view 

44 BugTracker.objects.create(name='bt', public=True, 

45 components_followed_since=timezone.now()-timedelta(days=180)) 

46 

47 # TODO: add a fixture for bugs and comments 

48 

49 

50class MetricsCommentsTests(UserFiltrableViewMixin, TestCase): 

51 reverse_name = "CIResults-metrics-comments" 

52 query = "creator_is_developer = TRUE" 

53 

54 def setUp(self): 

55 MetricsBugsTests().setUp() 

56 

57 

58class MetricsOpenBugsTests(TestCase): 

59 def test_view_is_redirecting(self): 

60 response = self.client.get(reverse('CIResults-metrics-open-bugs')) 

61 self.assertEqual(response.status_code, 302) 

62 self.assertEqual(response.url, reverse('CIResults-bug-open-list')) 

63 

64 

65class MetricsPassratePerRunconfigTests(UserFiltrableViewMixin, TestCase): 

66 reverse_name = "CIResults-metrics-passrate-per-runconfig" 

67 query = "test_name = 'test'" 

68 

69 

70class MetricsPassratePerTestTests(UserFiltrableViewMixin, TestCase): 

71 reverse_name = "CIResults-metrics-passrate-per-test" 

72 query = "test_name = 'test'" 

73 

74 

75class MetricsRunTimeTests(UserFiltrableViewMixin, TestCase): 

76 reverse_name = "CIResults-metrics-runtime" 

77 query = "machine_name = 'machine'"