diff options
Diffstat (limited to 'bitbake/lib/toaster/tests/functional/test_project_config.py')
-rw-r--r-- | bitbake/lib/toaster/tests/functional/test_project_config.py | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/tests/functional/test_project_config.py b/bitbake/lib/toaster/tests/functional/test_project_config.py new file mode 100644 index 0000000000..fcb1bc3284 --- /dev/null +++ b/bitbake/lib/toaster/tests/functional/test_project_config.py | |||
@@ -0,0 +1,294 @@ | |||
1 | #! /usr/bin/env python3 # | ||
2 | # BitBake Toaster UI tests implementation | ||
3 | # | ||
4 | # Copyright (C) 2023 Savoir-faire Linux | ||
5 | # | ||
6 | # SPDX-License-Identifier: GPL-2.0-only | ||
7 | # | ||
8 | |||
9 | import string | ||
10 | import pytest | ||
11 | from django.urls import reverse | ||
12 | from selenium.webdriver import Keys | ||
13 | from selenium.webdriver.support.select import Select | ||
14 | from selenium.common.exceptions import TimeoutException | ||
15 | from tests.functional.functional_helpers import SeleniumFunctionalTestCase | ||
16 | from selenium.webdriver.common.by import By | ||
17 | |||
18 | from .utils import get_projectId_from_url | ||
19 | |||
20 | class TestProjectConfig(SeleniumFunctionalTestCase): | ||
21 | project_id = None | ||
22 | PROJECT_NAME = 'TestProjectConfig' | ||
23 | INVALID_PATH_START_TEXT = 'The directory path should either start with a /' | ||
24 | INVALID_PATH_CHAR_TEXT = 'The directory path cannot include spaces or ' \ | ||
25 | 'any of these characters' | ||
26 | |||
27 | def _get_config_nav_item(self, index): | ||
28 | config_nav = self.find('#config-nav') | ||
29 | return config_nav.find_elements(By.TAG_NAME, 'li')[index] | ||
30 | |||
31 | def _navigate_bbv_page(self): | ||
32 | """ Navigate to project BitBake variables page """ | ||
33 | # check if the menu is displayed | ||
34 | if TestProjectConfig.project_id is None: | ||
35 | TestProjectConfig.project_id = self.create_new_project(self.PROJECT_NAME, '3', None, True) | ||
36 | |||
37 | url = reverse('projectconf', args=(TestProjectConfig.project_id,)) | ||
38 | self.get(url) | ||
39 | self.wait_until_visible('#config-nav') | ||
40 | bbv_page_link = self._get_config_nav_item(9) | ||
41 | bbv_page_link.click() | ||
42 | self.wait_until_visible('#config-nav') | ||
43 | |||
44 | def test_no_underscore_iamgefs_type(self): | ||
45 | """ | ||
46 | Should not accept IMAGEFS_TYPE with an underscore | ||
47 | """ | ||
48 | self._navigate_bbv_page() | ||
49 | imagefs_type = "foo_bar" | ||
50 | |||
51 | self.wait_until_visible('#change-image_fstypes-icon') | ||
52 | |||
53 | self.click('#change-image_fstypes-icon') | ||
54 | |||
55 | self.enter_text('#new-imagefs_types', imagefs_type) | ||
56 | |||
57 | element = self.wait_until_visible('#hintError-image-fs_type') | ||
58 | |||
59 | self.assertTrue(("A valid image type cannot include underscores" in element.text), | ||
60 | "Did not find underscore error message") | ||
61 | |||
62 | def test_checkbox_verification(self): | ||
63 | """ | ||
64 | Should automatically check the checkbox if user enters value | ||
65 | text box, if value is there in the checkbox. | ||
66 | """ | ||
67 | self._navigate_bbv_page() | ||
68 | |||
69 | imagefs_type = "btrfs" | ||
70 | |||
71 | self.wait_until_visible('#change-image_fstypes-icon') | ||
72 | |||
73 | self.click('#change-image_fstypes-icon') | ||
74 | |||
75 | self.enter_text('#new-imagefs_types', imagefs_type) | ||
76 | |||
77 | checkboxes = self.driver.find_elements(By.XPATH, "//input[@class='fs-checkbox-fstypes']") | ||
78 | |||
79 | for checkbox in checkboxes: | ||
80 | if checkbox.get_attribute("value") == "btrfs": | ||
81 | self.assertEqual(checkbox.is_selected(), True) | ||
82 | |||
83 | def test_textbox_with_checkbox_verification(self): | ||
84 | """ | ||
85 | Should automatically add or remove value in textbox, if user checks | ||
86 | or unchecks checkboxes. | ||
87 | """ | ||
88 | self._navigate_bbv_page() | ||
89 | |||
90 | self.wait_until_visible('#change-image_fstypes-icon') | ||
91 | self.click('#change-image_fstypes-icon') | ||
92 | |||
93 | checkboxes_selector = '.fs-checkbox-fstypes' | ||
94 | |||
95 | self.wait_until_visible(checkboxes_selector) | ||
96 | checkboxes = self.find_all(checkboxes_selector) | ||
97 | |||
98 | for checkbox in checkboxes: | ||
99 | if checkbox.get_attribute("value") == "cpio": | ||
100 | checkbox.click() | ||
101 | self.wait_until_visible('#new-imagefs_types') | ||
102 | element = self.driver.find_element(By.ID, 'new-imagefs_types') | ||
103 | |||
104 | self.assertTrue(("cpio" in element.get_attribute('value'), | ||
105 | "Imagefs not added into the textbox")) | ||
106 | checkbox.click() | ||
107 | self.assertTrue(("cpio" not in element.text), | ||
108 | "Image still present in the textbox") | ||
109 | |||
110 | def test_set_download_dir(self): | ||
111 | """ | ||
112 | Validate the allowed and disallowed types in the directory field for | ||
113 | DL_DIR | ||
114 | """ | ||
115 | self._navigate_bbv_page() | ||
116 | |||
117 | # activate the input to edit download dir | ||
118 | try: | ||
119 | change_dl_dir_btn = self.wait_until_visible('#change-dl_dir-icon') | ||
120 | except TimeoutException: | ||
121 | # If download dir is not displayed, test is skipped | ||
122 | change_dl_dir_btn = None | ||
123 | |||
124 | if change_dl_dir_btn: | ||
125 | change_dl_dir_btn.click() | ||
126 | |||
127 | # downloads dir path doesn't start with / or ${...} | ||
128 | input_field = self.wait_until_visible('#new-dl_dir') | ||
129 | input_field.clear() | ||
130 | self.enter_text('#new-dl_dir', 'home/foo') | ||
131 | element = self.wait_until_visible('#hintError-initialChar-dl_dir') | ||
132 | |||
133 | msg = 'downloads directory path starts with invalid character but ' \ | ||
134 | 'treated as valid' | ||
135 | self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg) | ||
136 | |||
137 | # downloads dir path has a space | ||
138 | self.driver.find_element(By.ID, 'new-dl_dir').clear() | ||
139 | self.enter_text('#new-dl_dir', '/foo/bar a') | ||
140 | |||
141 | element = self.wait_until_visible('#hintError-dl_dir') | ||
142 | msg = 'downloads directory path characters invalid but treated as valid' | ||
143 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) | ||
144 | |||
145 | # downloads dir path starts with ${...} but has a space | ||
146 | self.driver.find_element(By.ID,'new-dl_dir').clear() | ||
147 | self.enter_text('#new-dl_dir', '${TOPDIR}/down foo') | ||
148 | |||
149 | element = self.wait_until_visible('#hintError-dl_dir') | ||
150 | msg = 'downloads directory path characters invalid but treated as valid' | ||
151 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) | ||
152 | |||
153 | # downloads dir path starts with / | ||
154 | self.driver.find_element(By.ID,'new-dl_dir').clear() | ||
155 | self.enter_text('#new-dl_dir', '/bar/foo') | ||
156 | |||
157 | hidden_element = self.driver.find_element(By.ID,'hintError-dl_dir') | ||
158 | self.assertEqual(hidden_element.is_displayed(), False, | ||
159 | 'downloads directory path valid but treated as invalid') | ||
160 | |||
161 | # downloads dir path starts with ${...} | ||
162 | self.driver.find_element(By.ID,'new-dl_dir').clear() | ||
163 | self.enter_text('#new-dl_dir', '${TOPDIR}/down') | ||
164 | |||
165 | hidden_element = self.driver.find_element(By.ID,'hintError-dl_dir') | ||
166 | self.assertEqual(hidden_element.is_displayed(), False, | ||
167 | 'downloads directory path valid but treated as invalid') | ||
168 | |||
169 | def test_set_sstate_dir(self): | ||
170 | """ | ||
171 | Validate the allowed and disallowed types in the directory field for | ||
172 | SSTATE_DIR | ||
173 | """ | ||
174 | self._navigate_bbv_page() | ||
175 | |||
176 | try: | ||
177 | btn_chg_sstate_dir = self.wait_until_visible('#change-sstate_dir-icon') | ||
178 | self.click('#change-sstate_dir-icon') | ||
179 | except TimeoutException: | ||
180 | # If sstate_dir is not displayed, test is skipped | ||
181 | btn_chg_sstate_dir = None | ||
182 | |||
183 | if btn_chg_sstate_dir: # Skip continuation if sstate_dir is not displayed | ||
184 | # path doesn't start with / or ${...} | ||
185 | input_field = self.wait_until_visible('#new-sstate_dir') | ||
186 | input_field.clear() | ||
187 | self.enter_text('#new-sstate_dir', 'home/foo') | ||
188 | element = self.wait_until_visible('#hintError-initialChar-sstate_dir') | ||
189 | |||
190 | msg = 'sstate directory path starts with invalid character but ' \ | ||
191 | 'treated as valid' | ||
192 | self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg) | ||
193 | |||
194 | # path has a space | ||
195 | self.driver.find_element(By.ID, 'new-sstate_dir').clear() | ||
196 | self.enter_text('#new-sstate_dir', '/foo/bar a') | ||
197 | |||
198 | element = self.wait_until_visible('#hintError-sstate_dir') | ||
199 | msg = 'sstate directory path characters invalid but treated as valid' | ||
200 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) | ||
201 | |||
202 | # path starts with ${...} but has a space | ||
203 | self.driver.find_element(By.ID,'new-sstate_dir').clear() | ||
204 | self.enter_text('#new-sstate_dir', '${TOPDIR}/down foo') | ||
205 | |||
206 | element = self.wait_until_visible('#hintError-sstate_dir') | ||
207 | msg = 'sstate directory path characters invalid but treated as valid' | ||
208 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) | ||
209 | |||
210 | # path starts with / | ||
211 | self.driver.find_element(By.ID,'new-sstate_dir').clear() | ||
212 | self.enter_text('#new-sstate_dir', '/bar/foo') | ||
213 | |||
214 | hidden_element = self.driver.find_element(By.ID, 'hintError-sstate_dir') | ||
215 | self.assertEqual(hidden_element.is_displayed(), False, | ||
216 | 'sstate directory path valid but treated as invalid') | ||
217 | |||
218 | # paths starts with ${...} | ||
219 | self.driver.find_element(By.ID, 'new-sstate_dir').clear() | ||
220 | self.enter_text('#new-sstate_dir', '${TOPDIR}/down') | ||
221 | |||
222 | hidden_element = self.driver.find_element(By.ID, 'hintError-sstate_dir') | ||
223 | self.assertEqual(hidden_element.is_displayed(), False, | ||
224 | 'sstate directory path valid but treated as invalid') | ||
225 | |||
226 | def _change_bbv_value(self, **kwargs): | ||
227 | var_name, field, btn_id, input_id, value, save_btn, *_ = kwargs.values() | ||
228 | """ Change bitbake variable value """ | ||
229 | self._navigate_bbv_page() | ||
230 | self.wait_until_visible(f'#{btn_id}') | ||
231 | if kwargs.get('new_variable'): | ||
232 | self.find(f"#{btn_id}").clear() | ||
233 | self.enter_text(f"#{btn_id}", f"{var_name}") | ||
234 | else: | ||
235 | self.click(f'#{btn_id}') | ||
236 | |||
237 | self.wait_until_visible(f'#{input_id}') | ||
238 | |||
239 | if kwargs.get('is_select'): | ||
240 | select = Select(self.find(f'#{input_id}')) | ||
241 | select.select_by_visible_text(value) | ||
242 | else: | ||
243 | self.find(f"#{input_id}").clear() | ||
244 | self.enter_text(f'#{input_id}', f'{value}') | ||
245 | self.click(f'#{save_btn}') | ||
246 | value_displayed = str(self.wait_until_visible(f'#{field}').text).lower() | ||
247 | msg = f'{var_name} variable not changed' | ||
248 | self.assertTrue(str(value).lower() in value_displayed, msg) | ||
249 | |||
250 | def test_change_distro_var(self): | ||
251 | """ Test changing distro variable """ | ||
252 | self._change_bbv_value( | ||
253 | var_name='DISTRO', | ||
254 | field='distro', | ||
255 | btn_id='change-distro-icon', | ||
256 | input_id='new-distro', | ||
257 | value='poky-changed', | ||
258 | save_btn="apply-change-distro", | ||
259 | ) | ||
260 | |||
261 | def test_set_image_install_append_var(self): | ||
262 | """ Test setting IMAGE_INSTALL:append variable """ | ||
263 | self._change_bbv_value( | ||
264 | var_name='IMAGE_INSTALL:append', | ||
265 | field='image_install', | ||
266 | btn_id='change-image_install-icon', | ||
267 | input_id='new-image_install', | ||
268 | value='bash, apt, busybox', | ||
269 | save_btn="apply-change-image_install", | ||
270 | ) | ||
271 | |||
272 | def test_set_package_classes_var(self): | ||
273 | """ Test setting PACKAGE_CLASSES variable """ | ||
274 | self._change_bbv_value( | ||
275 | var_name='PACKAGE_CLASSES', | ||
276 | field='package_classes', | ||
277 | btn_id='change-package_classes-icon', | ||
278 | input_id='package_classes-select', | ||
279 | value='package_deb', | ||
280 | save_btn="apply-change-package_classes", | ||
281 | is_select=True, | ||
282 | ) | ||
283 | |||
284 | def test_create_new_bbv(self): | ||
285 | """ Test creating new bitbake variable """ | ||
286 | self._change_bbv_value( | ||
287 | var_name='New_Custom_Variable', | ||
288 | field='configvar-list', | ||
289 | btn_id='variable', | ||
290 | input_id='value', | ||
291 | value='new variable value', | ||
292 | save_btn="add-configvar-button", | ||
293 | new_variable=True | ||
294 | ) | ||