Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | #! /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 | |
| 22 | import re |
| 23 | |
| 24 | from django.core.urlresolvers import reverse |
| 25 | from django.utils import timezone |
| 26 | from tests.browser.selenium_helpers import SeleniumTestCase |
| 27 | |
| 28 | from orm.models import BitbakeVersion, Release, Project, Build, Target |
| 29 | |
| 30 | class TestProjectBuildsPage(SeleniumTestCase): |
| 31 | """ Test data at /project/X/builds is displayed correctly """ |
| 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.project1.save() |
| 44 | |
| 45 | self.project2 = Project.objects.create_project(name=self.PROJECT_NAME, |
| 46 | release=release) |
| 47 | self.project2.save() |
| 48 | |
| 49 | self.default_project = Project.objects.create_project( |
| 50 | name=self.CLI_BUILDS_PROJECT_NAME, |
| 51 | release=release |
| 52 | ) |
| 53 | self.default_project.is_default = True |
| 54 | self.default_project.save() |
| 55 | |
| 56 | # parameters for builds to associate with the projects |
| 57 | now = timezone.now() |
| 58 | |
| 59 | self.project1_build_success = { |
| 60 | 'project': self.project1, |
| 61 | 'started_on': now, |
| 62 | 'completed_on': now, |
| 63 | 'outcome': Build.SUCCEEDED |
| 64 | } |
| 65 | |
| 66 | self.project1_build_in_progress = { |
| 67 | 'project': self.project1, |
| 68 | 'started_on': now, |
| 69 | 'completed_on': now, |
| 70 | 'outcome': Build.IN_PROGRESS |
| 71 | } |
| 72 | |
| 73 | self.project2_build_success = { |
| 74 | 'project': self.project2, |
| 75 | 'started_on': now, |
| 76 | 'completed_on': now, |
| 77 | 'outcome': Build.SUCCEEDED |
| 78 | } |
| 79 | |
| 80 | self.project2_build_in_progress = { |
| 81 | 'project': self.project2, |
| 82 | 'started_on': now, |
| 83 | 'completed_on': now, |
| 84 | 'outcome': Build.IN_PROGRESS |
| 85 | } |
| 86 | |
| 87 | def _get_rows_for_project(self, project_id): |
| 88 | """ |
| 89 | Helper to retrieve HTML rows for a project's builds, |
| 90 | as shown in the main table of the page |
| 91 | """ |
| 92 | url = reverse('projectbuilds', args=(project_id,)) |
| 93 | self.get(url) |
| 94 | self.wait_until_present('#projectbuildstable tbody tr') |
| 95 | return self.find_all('#projectbuildstable tbody tr') |
| 96 | |
| 97 | def test_show_builds_for_project(self): |
| 98 | """ Builds for a project should be displayed in the main table """ |
| 99 | Build.objects.create(**self.project1_build_success) |
| 100 | Build.objects.create(**self.project1_build_success) |
| 101 | build_rows = self._get_rows_for_project(self.project1.id) |
| 102 | self.assertEqual(len(build_rows), 2) |
| 103 | |
| 104 | def test_show_builds_project_only(self): |
| 105 | """ Builds for other projects should be excluded """ |
| 106 | Build.objects.create(**self.project1_build_success) |
| 107 | Build.objects.create(**self.project1_build_success) |
| 108 | Build.objects.create(**self.project1_build_success) |
| 109 | |
| 110 | # shouldn't see these two |
| 111 | Build.objects.create(**self.project2_build_success) |
| 112 | Build.objects.create(**self.project2_build_in_progress) |
| 113 | |
| 114 | build_rows = self._get_rows_for_project(self.project1.id) |
| 115 | self.assertEqual(len(build_rows), 3) |
| 116 | |
| 117 | def test_builds_exclude_in_progress(self): |
| 118 | """ "in progress" builds should not be shown in main table """ |
| 119 | Build.objects.create(**self.project1_build_success) |
| 120 | Build.objects.create(**self.project1_build_success) |
| 121 | |
| 122 | # shouldn't see this one |
| 123 | Build.objects.create(**self.project1_build_in_progress) |
| 124 | |
| 125 | # shouldn't see these two either, as they belong to a different project |
| 126 | Build.objects.create(**self.project2_build_success) |
| 127 | Build.objects.create(**self.project2_build_in_progress) |
| 128 | |
| 129 | build_rows = self._get_rows_for_project(self.project1.id) |
| 130 | self.assertEqual(len(build_rows), 2) |
| 131 | |
| 132 | def test_show_tasks_with_suffix(self): |
| 133 | """ Task should be shown as suffixes on build names """ |
| 134 | build = Build.objects.create(**self.project1_build_success) |
| 135 | target = 'bash' |
| 136 | task = 'clean' |
| 137 | Target.objects.create(build=build, target=target, task=task) |
| 138 | |
| 139 | url = reverse('projectbuilds', args=(self.project1.id,)) |
| 140 | self.get(url) |
| 141 | self.wait_until_present('td[class="target"]') |
| 142 | |
| 143 | cell = self.find('td[class="target"]') |
| 144 | content = cell.get_attribute('innerHTML') |
| 145 | expected_text = '%s:%s' % (target, task) |
| 146 | |
| 147 | self.assertTrue(re.search(expected_text, content), |
| 148 | '"target" cell should contain text %s' % expected_text) |
| 149 | |
| 150 | def test_cli_builds_hides_tabs(self): |
| 151 | """ |
| 152 | Display for command line builds should hide tabs |
| 153 | """ |
| 154 | url = reverse('projectbuilds', args=(self.default_project.id,)) |
| 155 | self.get(url) |
| 156 | tabs = self.find_all('#project-topbar') |
| 157 | self.assertEqual(len(tabs), 0, |
| 158 | 'should be no top bar shown for command line builds') |
| 159 | |
| 160 | def test_non_cli_builds_has_tabs(self): |
| 161 | """ |
| 162 | Non-command-line builds projects should show the tabs |
| 163 | """ |
| 164 | url = reverse('projectbuilds', args=(self.project1.id,)) |
| 165 | self.get(url) |
| 166 | tabs = self.find_all('#project-topbar') |
| 167 | self.assertEqual(len(tabs), 1, |
| 168 | 'should be a top bar shown for non-command-line builds') |