blob: e4223f482a2c2d004133240e521729dd6fc4cb11 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001#! /usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# BitBake Toaster Implementation
6#
7# Copyright (C) 2013-2016 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22import re
23
24from django.core.urlresolvers import reverse
25from django.utils import timezone
26from tests.browser.selenium_helpers import SeleniumTestCase
27
28from orm.models import BitbakeVersion, Release, Project, Build, Target
29
30class TestAllBuildsPage(SeleniumTestCase):
31 """ Tests for all builds page /builds/ """
32
33 PROJECT_NAME = 'test project'
34 CLI_BUILDS_PROJECT_NAME = 'command line builds'
35
36 def setUp(self):
37 bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/',
38 branch='master', dirpath='')
39 release = Release.objects.create(name='release1',
40 bitbake_version=bbv)
41 self.project1 = Project.objects.create_project(name=self.PROJECT_NAME,
42 release=release)
43 self.default_project = Project.objects.create_project(
44 name=self.CLI_BUILDS_PROJECT_NAME,
45 release=release
46 )
47 self.default_project.is_default = True
48 self.default_project.save()
49
50 # parameters for builds to associate with the projects
51 now = timezone.now()
52
53 self.project1_build_success = {
54 'project': self.project1,
55 'started_on': now,
56 'completed_on': now,
57 'outcome': Build.SUCCEEDED
58 }
59
60 self.default_project_build_success = {
61 'project': self.default_project,
62 'started_on': now,
63 'completed_on': now,
64 'outcome': Build.SUCCEEDED
65 }
66
67 def test_show_tasks_with_suffix(self):
68 """ Task should be shown as suffix on build name """
69 build = Build.objects.create(**self.project1_build_success)
70 target = 'bash'
71 task = 'clean'
72 Target.objects.create(build=build, target=target, task=task)
73
74 url = reverse('all-builds')
75 self.get(url)
76 self.wait_until_present('td[class="target"]')
77
78 cell = self.find('td[class="target"]')
79 content = cell.get_attribute('innerHTML')
80 expected_text = '%s:%s' % (target, task)
81
82 self.assertTrue(re.search(expected_text, content),
83 '"target" cell should contain text %s' % expected_text)
84
85 def test_rebuild_buttons(self):
86 """
87 Test 'Rebuild' buttons in recent builds section
88
89 'Rebuild' button should not be shown for command-line builds,
90 but should be shown for other builds
91 """
92 build1 = Build.objects.create(**self.project1_build_success)
93 default_build = Build.objects.create(**self.default_project_build_success)
94
95 url = reverse('all-builds')
96 self.get(url)
97
98 # shouldn't see a run again button for command-line builds
99 selector = 'div[data-latest-build-result="%s"] button' % default_build.id
100 run_again_button = self.find_all(selector)
101 self.assertEqual(len(run_again_button), 0,
102 'should not see a run again button for cli builds')
103
104 # should see a run again button for non-command-line builds
105 selector = 'div[data-latest-build-result="%s"] button' % build1.id
106 run_again_button = self.find_all(selector)
107 self.assertEqual(len(run_again_button), 1,
108 'should see a run again button for non-cli builds')
109
110 def test_tooltips_on_project_name(self):
111 """
112 Test tooltips shown next to project name in the main table
113
114 A tooltip should be present next to the command line
115 builds project name in the all builds page, but not for
116 other projects
117 """
118 Build.objects.create(**self.project1_build_success)
119 Build.objects.create(**self.default_project_build_success)
120
121 url = reverse('all-builds')
122 self.get(url)
123
124 # get the project name cells from the table
125 cells = self.find_all('#allbuildstable td[class="project"]')
126
127 selector = 'i.get-help'
128
129 for cell in cells:
130 content = cell.get_attribute('innerHTML')
131 help_icons = cell.find_elements_by_css_selector(selector)
132
133 if re.search(self.PROJECT_NAME, content):
134 # no help icon next to non-cli project name
135 msg = 'should not be a help icon for non-cli builds name'
136 self.assertEqual(len(help_icons), 0, msg)
137 elif re.search(self.CLI_BUILDS_PROJECT_NAME, content):
138 # help icon next to cli project name
139 msg = 'should be a help icon for cli builds name'
140 self.assertEqual(len(help_icons), 1, msg)
141 else:
142 msg = 'found unexpected project name cell in all builds table'
143 self.fail(msg)