diff options
| author | Elliot Smith <elliot.smith@intel.com> | 2016-07-14 15:58:00 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-08-11 00:09:27 +0100 |
| commit | cf0b07c96f3f02f867fcb2e340cff94f950b44e9 (patch) | |
| tree | 493934de573663e2c974c87edf99613491765ec3 /bitbake/lib | |
| parent | 36f71db680db36a2378b5c03b70819ecaf5814fa (diff) | |
| download | poky-cf0b07c96f3f02f867fcb2e340cff94f950b44e9.tar.gz | |
bitbake: toaster-tests: add tests for most recent builds state changes
Add tests for the state transitions in the "most recent builds"
area of the all builds page.
[YOCTO #9631]
(Bitbake rev: b95681cf38475903ad4f73059313dda8c0dccef6)
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
| -rw-r--r-- | bitbake/lib/toaster/tests/browser/test_most_recent_builds_states.py | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/tests/browser/test_most_recent_builds_states.py b/bitbake/lib/toaster/tests/browser/test_most_recent_builds_states.py new file mode 100644 index 0000000000..abc0b0bc88 --- /dev/null +++ b/bitbake/lib/toaster/tests/browser/test_most_recent_builds_states.py | |||
| @@ -0,0 +1,211 @@ | |||
| 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 | from tests.browser.selenium_helpers import SeleniumTestCase | ||
| 25 | from tests.browser.selenium_helpers_base import Wait | ||
| 26 | from orm.models import Project, Build, Task, Recipe, Layer, Layer_Version | ||
| 27 | from bldcontrol.models import BuildRequest | ||
| 28 | |||
| 29 | class TestMostRecentBuildsStates(SeleniumTestCase): | ||
| 30 | """ Test states update correctly in most recent builds area """ | ||
| 31 | |||
| 32 | def _create_build_request(self): | ||
| 33 | project = Project.objects.get_or_create_default_project() | ||
| 34 | |||
| 35 | now = timezone.now() | ||
| 36 | |||
| 37 | build = Build.objects.create(project=project, build_name='fakebuild', | ||
| 38 | started_on=now, completed_on=now) | ||
| 39 | |||
| 40 | return BuildRequest.objects.create(build=build, project=project, | ||
| 41 | state=BuildRequest.REQ_QUEUED) | ||
| 42 | |||
| 43 | def _create_recipe(self): | ||
| 44 | """ Add a recipe to the database and return it """ | ||
| 45 | layer = Layer.objects.create() | ||
| 46 | layer_version = Layer_Version.objects.create(layer=layer) | ||
| 47 | return Recipe.objects.create(name='foo', layer_version=layer_version) | ||
| 48 | |||
| 49 | def _check_build_states(self, build_request): | ||
| 50 | recipes_to_parse = 10 | ||
| 51 | url = reverse('all-builds') | ||
| 52 | self.get(url) | ||
| 53 | |||
| 54 | build = build_request.build | ||
| 55 | base_selector = '[data-latest-build-result="%s"] ' % build.id | ||
| 56 | |||
| 57 | # build queued; check shown as queued | ||
| 58 | selector = base_selector + '[data-build-state="Queued"]' | ||
| 59 | element = self.wait_until_visible(selector) | ||
| 60 | self.assertRegexpMatches(element.get_attribute('innerHTML'), | ||
| 61 | 'Build queued', 'build should show queued status') | ||
| 62 | |||
| 63 | # waiting for recipes to be parsed | ||
| 64 | build.outcome = Build.IN_PROGRESS | ||
| 65 | build.recipes_to_parse = recipes_to_parse | ||
| 66 | build.recipes_parsed = 0 | ||
| 67 | |||
| 68 | build_request.state = BuildRequest.REQ_INPROGRESS | ||
| 69 | build_request.save() | ||
| 70 | |||
| 71 | self.get(url) | ||
| 72 | |||
| 73 | selector = base_selector + '[data-build-state="Parsing"]' | ||
| 74 | element = self.wait_until_visible(selector) | ||
| 75 | |||
| 76 | bar_selector = '#recipes-parsed-percentage-bar-%s' % build.id | ||
| 77 | bar_element = element.find_element_by_css_selector(bar_selector) | ||
| 78 | self.assertEqual(bar_element.value_of_css_property('width'), '0px', | ||
| 79 | 'recipe parse progress should be at 0') | ||
| 80 | |||
| 81 | # recipes being parsed; check parse progress | ||
| 82 | build.recipes_parsed = 5 | ||
| 83 | build.save() | ||
| 84 | |||
| 85 | self.get(url) | ||
| 86 | |||
| 87 | element = self.wait_until_visible(selector) | ||
| 88 | bar_element = element.find_element_by_css_selector(bar_selector) | ||
| 89 | recipe_bar_updated = lambda driver: \ | ||
| 90 | bar_element.get_attribute('style') == 'width: 50%;' | ||
| 91 | msg = 'recipe parse progress bar should update to 50%' | ||
| 92 | element = Wait(self.driver).until(recipe_bar_updated, msg) | ||
| 93 | |||
| 94 | # all recipes parsed, task started, waiting for first task to finish; | ||
| 95 | # check status is shown as "Tasks starting..." | ||
| 96 | build.recipes_parsed = recipes_to_parse | ||
| 97 | build.save() | ||
| 98 | |||
| 99 | recipe = self._create_recipe() | ||
| 100 | task1 = Task.objects.create(build=build, recipe=recipe, | ||
| 101 | task_name='Lionel') | ||
| 102 | task2 = Task.objects.create(build=build, recipe=recipe, | ||
| 103 | task_name='Jeffries') | ||
| 104 | |||
| 105 | self.get(url) | ||
| 106 | |||
| 107 | selector = base_selector + '[data-build-state="Starting"]' | ||
| 108 | element = self.wait_until_visible(selector) | ||
| 109 | self.assertRegexpMatches(element.get_attribute('innerHTML'), | ||
| 110 | 'Tasks starting', 'build should show "tasks starting" status') | ||
| 111 | |||
| 112 | # first task finished; check tasks progress bar | ||
| 113 | task1.order = 1 | ||
| 114 | task1.save() | ||
| 115 | |||
| 116 | self.get(url) | ||
| 117 | |||
| 118 | selector = base_selector + '[data-build-state="In Progress"]' | ||
| 119 | element = self.wait_until_visible(selector) | ||
| 120 | |||
| 121 | bar_selector = '#build-pc-done-bar-%s' % build.id | ||
| 122 | bar_element = element.find_element_by_css_selector(bar_selector) | ||
| 123 | |||
| 124 | task_bar_updated = lambda driver: \ | ||
| 125 | bar_element.get_attribute('style') == 'width: 50%;' | ||
| 126 | msg = 'tasks progress bar should update to 50%' | ||
| 127 | element = Wait(self.driver).until(task_bar_updated, msg) | ||
| 128 | |||
| 129 | # last task finished; check tasks progress bar updates | ||
| 130 | task2.order = 2 | ||
| 131 | task2.save() | ||
| 132 | |||
| 133 | self.get(url) | ||
| 134 | |||
| 135 | element = self.wait_until_visible(selector) | ||
| 136 | bar_element = element.find_element_by_css_selector(bar_selector) | ||
| 137 | task_bar_updated = lambda driver: \ | ||
| 138 | bar_element.get_attribute('style') == 'width: 100%;' | ||
| 139 | msg = 'tasks progress bar should update to 100%' | ||
| 140 | element = Wait(self.driver).until(task_bar_updated, msg) | ||
| 141 | |||
| 142 | def test_states_to_success(self): | ||
| 143 | """ | ||
| 144 | Test state transitions in the recent builds area for a build which | ||
| 145 | completes successfully. | ||
| 146 | """ | ||
| 147 | build_request = self._create_build_request() | ||
| 148 | |||
| 149 | self._check_build_states(build_request) | ||
| 150 | |||
| 151 | # all tasks complete and build succeeded; check success state shown | ||
| 152 | build = build_request.build | ||
| 153 | build.outcome = Build.SUCCEEDED | ||
| 154 | build.save() | ||
| 155 | |||
| 156 | selector = '[data-latest-build-result="%s"] ' \ | ||
| 157 | '[data-build-state="Succeeded"]' % build.id | ||
| 158 | element = self.wait_until_visible(selector) | ||
| 159 | |||
| 160 | def test_states_to_failure(self): | ||
| 161 | """ | ||
| 162 | Test state transitions in the recent builds area for a build which | ||
| 163 | completes in a failure. | ||
| 164 | """ | ||
| 165 | build_request = self._create_build_request() | ||
| 166 | |||
| 167 | self._check_build_states(build_request) | ||
| 168 | |||
| 169 | # all tasks complete and build succeeded; check fail state shown | ||
| 170 | build = build_request.build | ||
| 171 | build.outcome = Build.FAILED | ||
| 172 | build.save() | ||
| 173 | |||
| 174 | selector = '[data-latest-build-result="%s"] ' \ | ||
| 175 | '[data-build-state="Failed"]' % build.id | ||
| 176 | element = self.wait_until_visible(selector) | ||
| 177 | |||
| 178 | def test_states_cancelling(self): | ||
| 179 | """ | ||
| 180 | Test that most recent build area updates correctly for a build | ||
| 181 | which is cancelled. | ||
| 182 | """ | ||
| 183 | url = reverse('all-builds') | ||
| 184 | |||
| 185 | build_request = self._create_build_request() | ||
| 186 | build = build_request.build | ||
| 187 | |||
| 188 | # cancel the build | ||
| 189 | build_request.state = BuildRequest.REQ_CANCELLING | ||
| 190 | build_request.save() | ||
| 191 | |||
| 192 | self.get(url) | ||
| 193 | |||
| 194 | # check cancelling state | ||
| 195 | selector = '[data-latest-build-result="%s"] ' \ | ||
| 196 | '[data-build-state="Cancelling"]' % build.id | ||
| 197 | element = self.wait_until_visible(selector) | ||
| 198 | self.assertRegexpMatches(element.get_attribute('innerHTML'), | ||
| 199 | 'Cancelling the build', 'build should show "cancelling" status') | ||
| 200 | |||
| 201 | # check cancelled state | ||
| 202 | build.outcome = Build.CANCELLED | ||
| 203 | build.save() | ||
| 204 | |||
| 205 | self.get(url) | ||
| 206 | |||
| 207 | selector = '[data-latest-build-result="%s"] ' \ | ||
| 208 | '[data-build-state="Cancelled"]' % build.id | ||
| 209 | element = self.wait_until_visible(selector) | ||
| 210 | self.assertRegexpMatches(element.get_attribute('innerHTML'), | ||
| 211 | 'Build cancelled', 'build should show "cancelled" status') | ||
