Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [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 | from django.core.urlresolvers import reverse |
| 23 | from django.utils import timezone |
| 24 | |
| 25 | from tests.browser.selenium_helpers import SeleniumTestCase |
| 26 | |
| 27 | from orm.models import Project, Release, BitbakeVersion, Build, Target, Package |
| 28 | from orm.models import Target_Image_File, TargetSDKFile, TargetKernelFile |
| 29 | from orm.models import Target_Installed_Package, Variable |
| 30 | |
| 31 | class TestBuildDashboardPageArtifacts(SeleniumTestCase): |
| 32 | """ Tests for artifacts on the build dashboard /build/X """ |
| 33 | |
| 34 | def setUp(self): |
| 35 | bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/', |
| 36 | branch='master', dirpath="") |
| 37 | release = Release.objects.create(name='release1', |
| 38 | bitbake_version=bbv) |
| 39 | self.project = Project.objects.create_project(name='test project', |
| 40 | release=release) |
| 41 | |
| 42 | def _get_build_dashboard(self, build): |
| 43 | """ |
| 44 | Navigate to the build dashboard for build |
| 45 | """ |
| 46 | url = reverse('builddashboard', args=(build.id,)) |
| 47 | self.get(url) |
| 48 | |
| 49 | def _has_build_artifacts_heading(self): |
| 50 | """ |
| 51 | Check whether the "Build artifacts" heading is visible (True if it |
| 52 | is, False otherwise). |
| 53 | """ |
| 54 | return self.element_exists('[data-heading="build-artifacts"]') |
| 55 | |
| 56 | def _has_images_menu_option(self): |
| 57 | """ |
| 58 | Try to get the "Images" list element from the left-hand menu in the |
| 59 | build dashboard, and return True if it is present, False otherwise. |
| 60 | """ |
| 61 | return self.element_exists('li.nav-header[data-menu-heading="images"]') |
| 62 | |
| 63 | def test_no_artifacts(self): |
| 64 | """ |
| 65 | If a build produced no artifacts, the artifacts heading and images |
| 66 | menu option shouldn't show. |
| 67 | """ |
| 68 | now = timezone.now() |
| 69 | build = Build.objects.create(project=self.project, |
| 70 | started_on=now, completed_on=now, outcome=Build.SUCCEEDED) |
| 71 | |
| 72 | Target.objects.create(is_image=False, build=build, task='', |
| 73 | target='mpfr-native') |
| 74 | |
| 75 | self._get_build_dashboard(build) |
| 76 | |
| 77 | # check build artifacts heading |
| 78 | msg = 'Build artifacts heading should not be displayed for non-image' \ |
| 79 | 'builds' |
| 80 | self.assertFalse(self._has_build_artifacts_heading(), msg) |
| 81 | |
| 82 | # check "Images" option in left-hand menu (should not be there) |
| 83 | msg = 'Images option should not be shown in left-hand menu' |
| 84 | self.assertFalse(self._has_images_menu_option(), msg) |
| 85 | |
| 86 | def test_sdk_artifacts(self): |
| 87 | """ |
| 88 | If a build produced SDK artifacts, they should be shown, but the section |
| 89 | for image files and the images menu option should be hidden. |
| 90 | |
| 91 | The packages count and size should also be hidden. |
| 92 | """ |
| 93 | now = timezone.now() |
| 94 | build = Build.objects.create(project=self.project, |
| 95 | started_on=now, completed_on=timezone.now(), |
| 96 | outcome=Build.SUCCEEDED) |
| 97 | |
| 98 | target = Target.objects.create(is_image=True, build=build, |
| 99 | task='populate_sdk', target='core-image-minimal') |
| 100 | |
| 101 | sdk_file1 = TargetSDKFile.objects.create(target=target, |
| 102 | file_size=100000, |
| 103 | file_name='/home/foo/core-image-minimal.toolchain.sh') |
| 104 | |
| 105 | sdk_file2 = TargetSDKFile.objects.create(target=target, |
| 106 | file_size=120000, |
| 107 | file_name='/home/foo/x86_64.toolchain.sh') |
| 108 | |
| 109 | self._get_build_dashboard(build) |
| 110 | |
| 111 | # check build artifacts heading |
| 112 | msg = 'Build artifacts heading should be displayed for SDK ' \ |
| 113 | 'builds which generate artifacts' |
| 114 | self.assertTrue(self._has_build_artifacts_heading(), msg) |
| 115 | |
| 116 | # check "Images" option in left-hand menu (should not be there) |
| 117 | msg = 'Images option should not be shown in left-hand menu for ' \ |
| 118 | 'builds which didn\'t generate an image file' |
| 119 | self.assertFalse(self._has_images_menu_option(), msg) |
| 120 | |
| 121 | # check links to SDK artifacts |
| 122 | sdk_artifact_links = self.find_all('[data-links="sdk-artifacts"] li') |
| 123 | self.assertEqual(len(sdk_artifact_links), 2, |
| 124 | 'should be links to 2 SDK artifacts') |
| 125 | |
| 126 | # package count and size should not be visible, no link on |
| 127 | # target name |
| 128 | selector = '[data-value="target-package-count"]' |
| 129 | self.assertFalse(self.element_exists(selector), |
| 130 | 'package count should not be shown for non-image builds') |
| 131 | |
| 132 | selector = '[data-value="target-package-size"]' |
| 133 | self.assertFalse(self.element_exists(selector), |
| 134 | 'package size should not be shown for non-image builds') |
| 135 | |
| 136 | selector = '[data-link="target-packages"]' |
| 137 | self.assertFalse(self.element_exists(selector), |
| 138 | 'link to target packages should not be on target heading') |
| 139 | |
| 140 | def test_image_artifacts(self): |
| 141 | """ |
| 142 | If a build produced image files, kernel artifacts, and manifests, |
| 143 | they should all be shown, as well as the image link in the left-hand |
| 144 | menu. |
| 145 | |
| 146 | The packages count and size should be shown, with a link to the |
| 147 | package display page. |
| 148 | """ |
| 149 | now = timezone.now() |
| 150 | build = Build.objects.create(project=self.project, |
| 151 | started_on=now, completed_on=timezone.now(), |
| 152 | outcome=Build.SUCCEEDED) |
| 153 | |
| 154 | # add a variable to the build so that it counts as "started" |
| 155 | Variable.objects.create(build=build, |
| 156 | variable_name='Christopher', |
| 157 | variable_value='Lee') |
| 158 | |
| 159 | target = Target.objects.create(is_image=True, build=build, |
| 160 | task='', target='core-image-minimal', |
| 161 | license_manifest_path='/home/foo/license.manifest', |
| 162 | package_manifest_path='/home/foo/package.manifest') |
| 163 | |
| 164 | image_file = Target_Image_File.objects.create(target=target, |
| 165 | file_name='/home/foo/core-image-minimal.ext4', file_size=9000) |
| 166 | |
| 167 | kernel_file1 = TargetKernelFile.objects.create(target=target, |
| 168 | file_name='/home/foo/bzImage', file_size=2000) |
| 169 | |
| 170 | kernel_file2 = TargetKernelFile.objects.create(target=target, |
| 171 | file_name='/home/foo/bzImage', file_size=2000) |
| 172 | |
| 173 | package = Package.objects.create(build=build, name='foo', size=1024, |
| 174 | installed_name='foo1') |
| 175 | installed_package = Target_Installed_Package.objects.create( |
| 176 | target=target, package=package) |
| 177 | |
| 178 | self._get_build_dashboard(build) |
| 179 | |
| 180 | # check build artifacts heading |
| 181 | msg = 'Build artifacts heading should be displayed for image ' \ |
| 182 | 'builds' |
| 183 | self.assertTrue(self._has_build_artifacts_heading(), msg) |
| 184 | |
| 185 | # check "Images" option in left-hand menu (should be there) |
| 186 | msg = 'Images option should be shown in left-hand menu for image builds' |
| 187 | self.assertTrue(self._has_images_menu_option(), msg) |
| 188 | |
| 189 | # check link to image file |
| 190 | selector = '[data-links="image-artifacts"] li' |
| 191 | self.assertTrue(self.element_exists(selector), |
| 192 | 'should be a link to the image file (selector %s)' % selector) |
| 193 | |
| 194 | # check links to kernel artifacts |
| 195 | kernel_artifact_links = \ |
| 196 | self.find_all('[data-links="kernel-artifacts"] li') |
| 197 | self.assertEqual(len(kernel_artifact_links), 2, |
| 198 | 'should be links to 2 kernel artifacts') |
| 199 | |
| 200 | # check manifest links |
| 201 | selector = 'a[data-link="license-manifest"]' |
| 202 | self.assertTrue(self.element_exists(selector), |
| 203 | 'should be a link to the license manifest (selector %s)' % selector) |
| 204 | |
| 205 | selector = 'a[data-link="package-manifest"]' |
| 206 | self.assertTrue(self.element_exists(selector), |
| 207 | 'should be a link to the package manifest (selector %s)' % selector) |
| 208 | |
| 209 | # check package count and size, link on target name |
| 210 | selector = '[data-value="target-package-count"]' |
| 211 | element = self.find(selector) |
| 212 | self.assertEquals(element.text, '1', |
| 213 | 'package count should be shown for image builds') |
| 214 | |
| 215 | selector = '[data-value="target-package-size"]' |
| 216 | element = self.find(selector) |
| 217 | self.assertEquals(element.text, '1.0 KB', |
| 218 | 'package size should be shown for image builds') |
| 219 | |
| 220 | selector = '[data-link="target-packages"]' |
| 221 | self.assertTrue(self.element_exists(selector), |
| 222 | 'link to target packages should be on target heading') |