summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-03-31 19:55:44 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-01 07:14:58 +0100
commit961cd90375630773f376328f8921804438e0f033 (patch)
treec468c35dac8565bed6a684f3b182ba1c75e5eb8d /bitbake/lib/toaster
parentf859a3d40e91e64d4b5292cefd880075a27ddaf9 (diff)
downloadpoky-961cd90375630773f376328f8921804438e0f033.tar.gz
bitbake: toaster: tests Migrate all builds page and project page tests to Selenium
(Bitbake rev: 4fda6be831d10e6d266b11975a0e9a35a7f35a77) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r--bitbake/lib/toaster/tests/browser/test_all_builds_page.py143
-rw-r--r--bitbake/lib/toaster/tests/browser/test_project_page.py59
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py140
3 files changed, 202 insertions, 140 deletions
diff --git a/bitbake/lib/toaster/tests/browser/test_all_builds_page.py b/bitbake/lib/toaster/tests/browser/test_all_builds_page.py
new file mode 100644
index 0000000000..e4223f482a
--- /dev/null
+++ b/bitbake/lib/toaster/tests/browser/test_all_builds_page.py
@@ -0,0 +1,143 @@
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
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)
diff --git a/bitbake/lib/toaster/tests/browser/test_project_page.py b/bitbake/lib/toaster/tests/browser/test_project_page.py
new file mode 100644
index 0000000000..786bef1c6e
--- /dev/null
+++ b/bitbake/lib/toaster/tests/browser/test_project_page.py
@@ -0,0 +1,59 @@
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
22from django.core.urlresolvers import reverse
23from django.utils import timezone
24from tests.browser.selenium_helpers import SeleniumTestCase
25
26from orm.models import Build, Project
27
28class TestProjectPage(SeleniumTestCase):
29 """ Test project data at /project/X/ is displayed correctly """
30
31 CLI_BUILDS_PROJECT_NAME = 'Command line builds'
32
33 def test_cli_builds_in_progress(self):
34 """
35 In progress builds should not cause an error to be thrown
36 when navigating to "command line builds" project page;
37 see https://bugzilla.yoctoproject.org/show_bug.cgi?id=8277
38 """
39
40 # add the "command line builds" default project; this mirrors what
41 # we do with get_or_create_default_project()
42 default_project = Project.objects.create_project(self.CLI_BUILDS_PROJECT_NAME, None)
43 default_project.is_default = True
44 default_project.save()
45
46 # add an "in progress" build for the default project
47 now = timezone.now()
48 Build.objects.create(project=default_project,
49 started_on=now,
50 completed_on=now,
51 outcome=Build.IN_PROGRESS)
52
53 # navigate to the project page for the default project
54 url = reverse("project", args=(default_project.id,))
55 self.get(url)
56
57 # check that we get a project page with the correct heading
58 project_name = self.find('#project-name').text.strip()
59 self.assertEqual(project_name, self.CLI_BUILDS_PROJECT_NAME)
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 6b05916f32..78b7c04255 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -897,146 +897,6 @@ class ProjectBuildsPageTests(TestCase):
897 self.assertEqual(len(tabs), 1, 897 self.assertEqual(len(tabs), 1,
898 'should be a top bar shown for non-command-line builds') 898 'should be a top bar shown for non-command-line builds')
899 899
900class AllBuildsPageTests(TestCase):
901 """ Tests for all builds page /builds/ """
902
903 def setUp(self):
904 bbv = BitbakeVersion.objects.create(name="bbv1", giturl="/tmp/",
905 branch="master", dirpath="")
906 release = Release.objects.create(name="release1",
907 bitbake_version=bbv)
908 self.project1 = Project.objects.create_project(name=PROJECT_NAME,
909 release=release)
910 self.default_project = Project.objects.create_project(
911 name=CLI_BUILDS_PROJECT_NAME,
912 release=release
913 )
914 self.default_project.is_default = True
915 self.default_project.save()
916
917 # parameters for builds to associate with the projects
918 now = timezone.now()
919
920 self.project1_build_success = {
921 "project": self.project1,
922 "started_on": now,
923 "completed_on": now,
924 "outcome": Build.SUCCEEDED
925 }
926
927 self.default_project_build_success = {
928 "project": self.default_project,
929 "started_on": now,
930 "completed_on": now,
931 "outcome": Build.SUCCEEDED
932 }
933
934 def _get_row_for_build(self, data, build_id):
935 """ Get the object representing the table data for a project """
936 return [row for row in data['rows']
937 if row['id'] == build_id][0]
938
939 def test_show_tasks_in_allbuilds(self):
940 """ Task should be shown as suffix on build name """
941 build = Build.objects.create(**self.project1_build_success)
942 Target.objects.create(build=build, target='bash', task='clean')
943
944 url = reverse('all-builds')
945 response = self.client.get(url, {'format': 'json'}, follow=True)
946 data = json.loads(response.content)
947 cell = data['rows'][0]['static:target']
948
949 result = re.findall('bash:clean', cell, re.MULTILINE)
950 self.assertEqual(len(result), 1)
951
952 def test_run_again(self):
953 """
954 "Rebuild" button should not be shown for command-line builds,
955 but should be shown for other builds
956 """
957 build1 = Build.objects.create(**self.project1_build_success)
958 default_build = Build.objects.create(**self.default_project_build_success)
959 url = reverse('all-builds')
960 response = self.client.get(url, follow=True)
961 soup = BeautifulSoup(response.content)
962
963 # shouldn't see a run again button for command-line builds
964 attrs = {'data-latest-build-result': default_build.id}
965 result = soup.find('div', attrs=attrs)
966 run_again_button = result.select('button')
967 self.assertEqual(len(run_again_button), 0)
968
969 # should see a run again button for non-command-line builds
970 attrs = {'data-latest-build-result': build1.id}
971 result = soup.find('div', attrs=attrs)
972 run_again_button = result.select('button')
973 self.assertEqual(len(run_again_button), 1)
974
975 def test_tooltips_on_project_name(self):
976 """
977 A tooltip should be present next to the command line
978 builds project name in the all builds page, but not for
979 other projects
980 """
981 build1 = Build.objects.create(**self.project1_build_success)
982 default_build = Build.objects.create(**self.default_project_build_success)
983
984 url = reverse('all-builds')
985 response = self.client.get(url, {'format': 'json'}, follow=True)
986 data = json.loads(response.content)
987
988 # get the data row for the non-command-line builds project
989 other_project_row = self._get_row_for_build(data, build1.id)
990
991 # make sure there is some HTML
992 soup = BeautifulSoup(other_project_row['static:project'])
993 self.assertEqual(len(soup.select('a')), 1,
994 'should be a project name link')
995
996 # no help icon on non-default project name
997 icons = soup.select('i.get-help')
998 self.assertEqual(len(icons), 0,
999 'should not be a help icon for non-cli builds name')
1000
1001 # get the data row for the command-line builds project
1002 default_project_row = self._get_row_for_build(data, default_build.id)
1003
1004 # help icon on default project name
1005 soup = BeautifulSoup(default_project_row['static:project'])
1006 icons = soup.select('i.get-help')
1007 self.assertEqual(len(icons), 1,
1008 'should be a help icon for cli builds name')
1009
1010class ProjectPageTests(TestCase):
1011 """ Test project data at /project/X/ is displayed correctly """
1012 CLI_BUILDS_PROJECT_NAME = 'Command line builds'
1013
1014 def test_command_line_builds_in_progress(self):
1015 """
1016 In progress builds should not cause an error to be thrown
1017 when navigating to "command line builds" project page;
1018 see https://bugzilla.yoctoproject.org/show_bug.cgi?id=8277
1019 """
1020
1021 # add the "command line builds" default project; this mirrors what
1022 # we do in migration 0026_set_default_project.py
1023 default_project = Project.objects.create_project(self.CLI_BUILDS_PROJECT_NAME, None)
1024 default_project.is_default = True
1025 default_project.save()
1026
1027 # add an "in progress" build for the default project
1028 now = timezone.now()
1029 build = Build.objects.create(project=default_project,
1030 started_on=now,
1031 completed_on=now,
1032 outcome=Build.IN_PROGRESS)
1033
1034 # navigate to the project page for the default project
1035 url = reverse("project", args=(default_project.id,))
1036 response = self.client.get(url, follow=True)
1037
1038 self.assertEqual(response.status_code, 200)
1039
1040class BuildDashboardTests(TestCase): 900class BuildDashboardTests(TestCase):
1041 """ Tests for the build dashboard /build/X """ 901 """ Tests for the build dashboard /build/X """
1042 902