diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-07-19 14:47:12 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-08-11 00:09:27 +0100 |
commit | 2ff892d87c6208abb672bd446c36b261690093f2 (patch) | |
tree | cf7879b1e6ddb03b6dab8610104e0f58a2c14b77 /bitbake/lib | |
parent | dd784598cda4d0ec725816c13c95ba3f591450d2 (diff) | |
download | poky-2ff892d87c6208abb672bd446c36b261690093f2.tar.gz |
bitbake: toaster-tests: add tests for reverting to default sort
Add tests for ToasterTable UI table sort reverting, which can
only be exercised via the browser.
Check that if a table is sorted by a column, and that column
is hidden, then the sort reverts to the default for the table.
[YOCTO #9836]
(Bitbake rev: 5b016338478d784fd048ba2baae121c3e558090c)
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_toastertable_ui.py | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/tests/browser/test_toastertable_ui.py b/bitbake/lib/toaster/tests/browser/test_toastertable_ui.py new file mode 100644 index 0000000000..53ddf30c3c --- /dev/null +++ b/bitbake/lib/toaster/tests/browser/test_toastertable_ui.py | |||
@@ -0,0 +1,160 @@ | |||
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 datetime import datetime | ||
23 | |||
24 | from django.core.urlresolvers import reverse | ||
25 | from django.utils import timezone | ||
26 | from tests.browser.selenium_helpers import SeleniumTestCase | ||
27 | from orm.models import BitbakeVersion, Release, Project, Build | ||
28 | |||
29 | class TestToasterTableUI(SeleniumTestCase): | ||
30 | """ | ||
31 | Tests for the UI elements of ToasterTable (sorting etc.); | ||
32 | note that the tests cover generic functionality of ToasterTable which | ||
33 | manifests as UI elements in the browser, and can only be tested via | ||
34 | Selenium. | ||
35 | """ | ||
36 | |||
37 | def setUp(self): | ||
38 | pass | ||
39 | |||
40 | def _get_orderby_heading(self, table): | ||
41 | """ | ||
42 | Get the current order by finding the column heading in <table> with | ||
43 | the sorted class on it. | ||
44 | |||
45 | table: WebElement for a ToasterTable | ||
46 | """ | ||
47 | selector = 'thead a.sorted' | ||
48 | heading = table.find_element_by_css_selector(selector) | ||
49 | return heading.get_attribute('innerHTML').strip() | ||
50 | |||
51 | def _get_datetime_from_cell(self, row, selector): | ||
52 | """ | ||
53 | Return the value in the cell selected by <selector> on <row> as a | ||
54 | datetime. | ||
55 | |||
56 | row: <tr> WebElement for a row in the ToasterTable | ||
57 | selector: CSS selector to use to find the cell containing the date time | ||
58 | string | ||
59 | """ | ||
60 | cell = row.find_element_by_css_selector(selector) | ||
61 | cell_text = cell.get_attribute('innerHTML').strip() | ||
62 | return datetime.strptime(cell_text, '%d/%m/%y %H:%M') | ||
63 | |||
64 | def test_revert_orderby(self): | ||
65 | """ | ||
66 | Test that sort order for a table reverts to the default sort order | ||
67 | if the current sort column is hidden. | ||
68 | """ | ||
69 | now = timezone.now() | ||
70 | later = now + timezone.timedelta(hours=1) | ||
71 | even_later = later + timezone.timedelta(hours=1) | ||
72 | |||
73 | bbv = BitbakeVersion.objects.create(name='test bbv', giturl='/tmp/', | ||
74 | branch='master', dirpath='') | ||
75 | release = Release.objects.create(name='test release', | ||
76 | branch_name='master', | ||
77 | bitbake_version=bbv) | ||
78 | |||
79 | project = Project.objects.create_project('project', release) | ||
80 | |||
81 | # set up two builds which will order differently when sorted by | ||
82 | # started_on or completed_on | ||
83 | |||
84 | # started first, finished last | ||
85 | build1 = Build.objects.create(project=project, | ||
86 | started_on=now, | ||
87 | completed_on=even_later, | ||
88 | outcome=Build.SUCCEEDED) | ||
89 | |||
90 | # started second, finished first | ||
91 | build2 = Build.objects.create(project=project, | ||
92 | started_on=later, | ||
93 | completed_on=later, | ||
94 | outcome=Build.SUCCEEDED) | ||
95 | |||
96 | url = reverse('all-builds') | ||
97 | self.get(url) | ||
98 | table = self.wait_until_visible('#allbuildstable') | ||
99 | |||
100 | # check ordering (default is by -completed_on); so build1 should be | ||
101 | # first as it finished last | ||
102 | active_heading = self._get_orderby_heading(table) | ||
103 | self.assertEqual(active_heading, 'Completed on', | ||
104 | 'table should be sorted by "Completed on" by default') | ||
105 | |||
106 | row_selector = '#allbuildstable tbody tr' | ||
107 | cell_selector = 'td.completed_on' | ||
108 | |||
109 | rows = self.find_all(row_selector) | ||
110 | row1_completed_on = self._get_datetime_from_cell(rows[0], cell_selector) | ||
111 | row2_completed_on = self._get_datetime_from_cell(rows[1], cell_selector) | ||
112 | self.assertTrue(row1_completed_on > row2_completed_on, | ||
113 | 'table should be sorted by -completed_on') | ||
114 | |||
115 | # turn on started_on column | ||
116 | self.click('#edit-columns-button') | ||
117 | self.click('#checkbox-started_on') | ||
118 | |||
119 | # sort by started_on column | ||
120 | links = table.find_elements_by_css_selector('th.started_on a') | ||
121 | for link in links: | ||
122 | if link.get_attribute('innerHTML').strip() == 'Started on': | ||
123 | link.click() | ||
124 | break | ||
125 | |||
126 | # wait for table data to reload in response to new sort | ||
127 | self.wait_until_visible('#allbuildstable') | ||
128 | |||
129 | # check ordering; build1 should be first | ||
130 | active_heading = self._get_orderby_heading(table) | ||
131 | self.assertEqual(active_heading, 'Started on', | ||
132 | 'table should be sorted by "Started on"') | ||
133 | |||
134 | cell_selector = 'td.started_on' | ||
135 | |||
136 | rows = self.find_all(row_selector) | ||
137 | row1_started_on = self._get_datetime_from_cell(rows[0], cell_selector) | ||
138 | row2_started_on = self._get_datetime_from_cell(rows[1], cell_selector) | ||
139 | self.assertTrue(row1_started_on < row2_started_on, | ||
140 | 'table should be sorted by started_on') | ||
141 | |||
142 | # turn off started_on column | ||
143 | self.click('#edit-columns-button') | ||
144 | self.click('#checkbox-started_on') | ||
145 | |||
146 | # wait for table data to reload in response to new sort | ||
147 | self.wait_until_visible('#allbuildstable') | ||
148 | |||
149 | # check ordering (should revert to completed_on); build2 should be first | ||
150 | active_heading = self._get_orderby_heading(table) | ||
151 | self.assertEqual(active_heading, 'Completed on', | ||
152 | 'table should be sorted by "Completed on" after hiding sort column') | ||
153 | |||
154 | cell_selector = 'td.completed_on' | ||
155 | |||
156 | rows = self.find_all(row_selector) | ||
157 | row1_completed_on = self._get_datetime_from_cell(rows[0], cell_selector) | ||
158 | row2_completed_on = self._get_datetime_from_cell(rows[1], cell_selector) | ||
159 | self.assertTrue(row1_completed_on > row2_completed_on, | ||
160 | 'table should be sorted by -completed_on') | ||