diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-03-31 19:55:45 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-04-01 07:14:59 +0100 |
commit | f2a38ea4a1b2fbc9ed14d54c9fc6f401b05d7715 (patch) | |
tree | db8cd285cd9fecc5a83b0843e29faaf6219656d6 /bitbake | |
parent | 961cd90375630773f376328f8921804438e0f033 (diff) | |
download | poky-f2a38ea4a1b2fbc9ed14d54c9fc6f401b05d7715.tar.gz |
bitbake: toaster: tests Migrate project builds page tests to Selenium
(Bitbake rev: 31204937f71a7e0aa08361c3e20d02d063788a86)
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')
-rw-r--r-- | bitbake/lib/toaster/tests/browser/test_project_builds_page.py | 168 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/tests.py | 133 |
2 files changed, 168 insertions, 133 deletions
diff --git a/bitbake/lib/toaster/tests/browser/test_project_builds_page.py b/bitbake/lib/toaster/tests/browser/test_project_builds_page.py new file mode 100644 index 0000000000..9fe91ab067 --- /dev/null +++ b/bitbake/lib/toaster/tests/browser/test_project_builds_page.py | |||
@@ -0,0 +1,168 @@ | |||
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') | ||
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 78b7c04255..7192947326 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py | |||
@@ -764,139 +764,6 @@ class AllProjectsPageTests(TestCase): | |||
764 | self.assertEqual(soup.find('a')['href'], expected_url, | 764 | self.assertEqual(soup.find('a')['href'], expected_url, |
765 | 'link on project name should point to configuration') | 765 | 'link on project name should point to configuration') |
766 | 766 | ||
767 | class ProjectBuildsPageTests(TestCase): | ||
768 | """ Test data at /project/X/builds is displayed correctly """ | ||
769 | |||
770 | def setUp(self): | ||
771 | bbv = BitbakeVersion.objects.create(name="bbv1", giturl="/tmp/", | ||
772 | branch="master", dirpath="") | ||
773 | release = Release.objects.create(name="release1", | ||
774 | bitbake_version=bbv) | ||
775 | self.project1 = Project.objects.create_project(name=PROJECT_NAME, | ||
776 | release=release) | ||
777 | self.project1.save() | ||
778 | |||
779 | self.project2 = Project.objects.create_project(name=PROJECT_NAME, | ||
780 | release=release) | ||
781 | self.project2.save() | ||
782 | |||
783 | self.default_project = Project.objects.create_project( | ||
784 | name=CLI_BUILDS_PROJECT_NAME, | ||
785 | release=release | ||
786 | ) | ||
787 | self.default_project.is_default = True | ||
788 | self.default_project.save() | ||
789 | |||
790 | # parameters for builds to associate with the projects | ||
791 | now = timezone.now() | ||
792 | |||
793 | self.project1_build_success = { | ||
794 | "project": self.project1, | ||
795 | "started_on": now, | ||
796 | "completed_on": now, | ||
797 | "outcome": Build.SUCCEEDED | ||
798 | } | ||
799 | |||
800 | self.project1_build_in_progress = { | ||
801 | "project": self.project1, | ||
802 | "started_on": now, | ||
803 | "completed_on": now, | ||
804 | "outcome": Build.IN_PROGRESS | ||
805 | } | ||
806 | |||
807 | self.project2_build_success = { | ||
808 | "project": self.project2, | ||
809 | "started_on": now, | ||
810 | "completed_on": now, | ||
811 | "outcome": Build.SUCCEEDED | ||
812 | } | ||
813 | |||
814 | self.project2_build_in_progress = { | ||
815 | "project": self.project2, | ||
816 | "started_on": now, | ||
817 | "completed_on": now, | ||
818 | "outcome": Build.IN_PROGRESS | ||
819 | } | ||
820 | |||
821 | def _get_rows_for_project(self, project_id): | ||
822 | """ Helper to retrieve HTML rows for a project """ | ||
823 | url = reverse("projectbuilds", args=(project_id,)) | ||
824 | response = self.client.get(url, {'format': 'json'}, follow=True) | ||
825 | data = json.loads(response.content) | ||
826 | return data['rows'] | ||
827 | |||
828 | def test_show_builds_for_project(self): | ||
829 | """ Builds for a project should be displayed """ | ||
830 | Build.objects.create(**self.project1_build_success) | ||
831 | Build.objects.create(**self.project1_build_success) | ||
832 | build_rows = self._get_rows_for_project(self.project1.id) | ||
833 | self.assertEqual(len(build_rows), 2) | ||
834 | |||
835 | def test_show_builds_project_only(self): | ||
836 | """ Builds for other projects should be excluded """ | ||
837 | Build.objects.create(**self.project1_build_success) | ||
838 | Build.objects.create(**self.project1_build_success) | ||
839 | Build.objects.create(**self.project1_build_success) | ||
840 | |||
841 | # shouldn't see these two | ||
842 | Build.objects.create(**self.project2_build_success) | ||
843 | Build.objects.create(**self.project2_build_in_progress) | ||
844 | |||
845 | build_rows = self._get_rows_for_project(self.project1.id) | ||
846 | self.assertEqual(len(build_rows), 3) | ||
847 | |||
848 | def test_builds_exclude_in_progress(self): | ||
849 | """ "in progress" builds should not be shown """ | ||
850 | Build.objects.create(**self.project1_build_success) | ||
851 | Build.objects.create(**self.project1_build_success) | ||
852 | |||
853 | # shouldn't see this one | ||
854 | Build.objects.create(**self.project1_build_in_progress) | ||
855 | |||
856 | # shouldn't see these two either, as they belong to a different project | ||
857 | Build.objects.create(**self.project2_build_success) | ||
858 | Build.objects.create(**self.project2_build_in_progress) | ||
859 | |||
860 | build_rows = self._get_rows_for_project(self.project1.id) | ||
861 | self.assertEqual(len(build_rows), 2) | ||
862 | |||
863 | def test_tasks_in_projectbuilds(self): | ||
864 | """ Task should be shown as suffix on build name """ | ||
865 | build = Build.objects.create(**self.project1_build_success) | ||
866 | Target.objects.create(build=build, target='bash', task='clean') | ||
867 | |||
868 | url = reverse('projectbuilds', args=(self.project1.id,)) | ||
869 | response = self.client.get(url, {'format': 'json'}, follow=True) | ||
870 | data = json.loads(response.content) | ||
871 | cell = data['rows'][0]['static:target'] | ||
872 | |||
873 | result = re.findall('^ +bash:clean', cell, re.MULTILINE) | ||
874 | self.assertEqual(len(result), 1) | ||
875 | |||
876 | def test_cli_builds_hides_tabs(self): | ||
877 | """ | ||
878 | Display for command line builds should hide tabs; | ||
879 | note that the latest builds section is already tested in | ||
880 | AllBuildsPageTests, as the template is the same | ||
881 | """ | ||
882 | url = reverse("projectbuilds", args=(self.default_project.id,)) | ||
883 | response = self.client.get(url, follow=True) | ||
884 | soup = BeautifulSoup(response.content) | ||
885 | tabs = soup.select('#project-topbar') | ||
886 | self.assertEqual(len(tabs), 0, | ||
887 | 'should be no top bar shown for command line builds') | ||
888 | |||
889 | def test_non_cli_builds_has_tabs(self): | ||
890 | """ | ||
891 | Non-command-line builds projects should show the tabs | ||
892 | """ | ||
893 | url = reverse("projectbuilds", args=(self.project1.id,)) | ||
894 | response = self.client.get(url, follow=True) | ||
895 | soup = BeautifulSoup(response.content) | ||
896 | tabs = soup.select('#project-topbar') | ||
897 | self.assertEqual(len(tabs), 1, | ||
898 | 'should be a top bar shown for non-command-line builds') | ||
899 | |||
900 | class BuildDashboardTests(TestCase): | 767 | class BuildDashboardTests(TestCase): |
901 | """ Tests for the build dashboard /build/X """ | 768 | """ Tests for the build dashboard /build/X """ |
902 | 769 | ||