1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from django.test import TestCase
12 from django.urls import reverse
14 from dashboard.models import Resource
15 from jenkins.models import JenkinsSlave
18 class DashboardViewTestCase(TestCase):
20 self.slave_active = JenkinsSlave.objects.create(name='slave_active', url='x', active=True)
21 self.slave_inactive = JenkinsSlave.objects.create(name='slave_inactive', url='x',
23 self.res_active = Resource.objects.create(name='res_active', slave=self.slave_active,
24 description='x', url='x')
25 self.res_inactive = Resource.objects.create(name='res_inactive', slave=self.slave_inactive,
26 description='x', url='x')
28 def test_booking_utilization_json(self):
29 url = reverse('dashboard:booking_utilization', kwargs={'resource_id': 0, 'weeks': 0})
30 self.assertEqual(self.client.get(url).status_code, 404)
32 url = reverse('dashboard:booking_utilization', kwargs={'resource_id': self.res_active.id,
34 response = self.client.get(url)
35 self.assertEqual(response.status_code, 200)
36 self.assertContains(response, 'data')
38 def test_jenkins_utilization_json(self):
39 url = reverse('dashboard:jenkins_utilization', kwargs={'resource_id': 0, 'weeks': 0})
40 self.assertEqual(self.client.get(url).status_code, 404)
42 url = reverse('dashboard:jenkins_utilization', kwargs={'resource_id': self.res_active.id,
44 response = self.client.get(url)
45 self.assertEqual(response.status_code, 200)
46 self.assertContains(response, 'data')
48 def test_jenkins_slaves_view(self):
49 url = reverse('dashboard:jenkins_slaves')
50 response = self.client.get(url)
51 self.assertEqual(response.status_code, 200)
52 self.assertIn(self.slave_active, response.context['slaves'])
53 self.assertNotIn(self.slave_inactive, response.context['slaves'])
55 def test_ci_pods_view(self):
56 url = reverse('dashboard:ci_pods')
57 response = self.client.get(url)
58 self.assertEqual(response.status_code, 200)
59 self.assertEqual(len(response.context['ci_pods']), 0)
61 self.slave_active.ci_slave = True
62 self.slave_inactive.ci_slave = True
63 self.slave_active.save()
64 self.slave_inactive.save()
66 response = self.client.get(url)
67 self.assertIn(self.res_active, response.context['ci_pods'])
68 self.assertNotIn(self.res_inactive, response.context['ci_pods'])
70 def test_dev_pods_view(self):
71 url = reverse('dashboard:dev_pods')
72 response = self.client.get(url)
73 self.assertEqual(response.status_code, 200)
74 self.assertEqual(len(response.context['dev_pods']), 0)