Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 1 | #! /usr/bin/env python3 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2 | # |
| 3 | # BitBake Toaster Implementation |
| 4 | # |
| 5 | # Copyright (C) 2013-2016 Intel Corporation |
| 6 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 7 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 8 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | |
| 10 | import re |
| 11 | |
| 12 | from django.core.urlresolvers import reverse |
| 13 | from django.utils import timezone |
| 14 | from tests.browser.selenium_helpers import SeleniumTestCase |
| 15 | |
| 16 | from orm.models import BitbakeVersion, Release, Project, ProjectVariable |
| 17 | |
| 18 | class TestProjectConfigsPage(SeleniumTestCase): |
| 19 | """ Test data at /project/X/builds is displayed correctly """ |
| 20 | |
| 21 | PROJECT_NAME = 'test project' |
| 22 | INVALID_PATH_START_TEXT = 'The directory path should either start with a /' |
| 23 | INVALID_PATH_CHAR_TEXT = 'The directory path cannot include spaces or ' \ |
| 24 | 'any of these characters' |
| 25 | |
| 26 | def setUp(self): |
| 27 | bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/', |
| 28 | branch='master', dirpath='') |
| 29 | release = Release.objects.create(name='release1', |
| 30 | bitbake_version=bbv) |
| 31 | self.project1 = Project.objects.create_project(name=self.PROJECT_NAME, |
| 32 | release=release) |
| 33 | self.project1.save() |
| 34 | |
| 35 | |
| 36 | def test_no_underscore_iamgefs_type(self): |
| 37 | """ |
| 38 | Should not accept IMAGEFS_TYPE with an underscore |
| 39 | """ |
| 40 | |
| 41 | imagefs_type = "foo_bar" |
| 42 | |
| 43 | ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ") |
| 44 | url = reverse('projectconf', args=(self.project1.id,)); |
| 45 | self.get(url); |
| 46 | |
| 47 | self.click('#change-image_fstypes-icon') |
| 48 | |
| 49 | self.enter_text('#new-imagefs_types', imagefs_type) |
| 50 | |
| 51 | element = self.wait_until_visible('#hintError-image-fs_type') |
| 52 | |
| 53 | self.assertTrue(("A valid image type cannot include underscores" in element.text), |
| 54 | "Did not find underscore error message") |
| 55 | |
| 56 | |
| 57 | def test_checkbox_verification(self): |
| 58 | """ |
| 59 | Should automatically check the checkbox if user enters value |
| 60 | text box, if value is there in the checkbox. |
| 61 | """ |
| 62 | imagefs_type = "btrfs" |
| 63 | |
| 64 | ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ") |
| 65 | url = reverse('projectconf', args=(self.project1.id,)); |
| 66 | self.get(url); |
| 67 | |
| 68 | self.click('#change-image_fstypes-icon') |
| 69 | |
| 70 | self.enter_text('#new-imagefs_types', imagefs_type) |
| 71 | |
| 72 | checkboxes = self.driver.find_elements_by_xpath("//input[@class='fs-checkbox-fstypes']") |
| 73 | |
| 74 | for checkbox in checkboxes: |
| 75 | if checkbox.get_attribute("value") == "btrfs": |
| 76 | self.assertEqual(checkbox.is_selected(), True) |
| 77 | |
| 78 | |
| 79 | def test_textbox_with_checkbox_verification(self): |
| 80 | """ |
| 81 | Should automatically add or remove value in textbox, if user checks |
| 82 | or unchecks checkboxes. |
| 83 | """ |
| 84 | |
| 85 | ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ") |
| 86 | url = reverse('projectconf', args=(self.project1.id,)); |
| 87 | self.get(url); |
| 88 | |
| 89 | self.click('#change-image_fstypes-icon') |
| 90 | |
| 91 | self.wait_until_visible('#new-imagefs_types') |
| 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 | element = self.driver.find_element_by_id('new-imagefs_types') |
| 102 | |
| 103 | self.wait_until_visible('#new-imagefs_types') |
| 104 | |
| 105 | self.assertTrue(("cpio" in element.get_attribute('value'), |
| 106 | "Imagefs not added into the textbox")) |
| 107 | checkbox.click() |
| 108 | self.assertTrue(("cpio" not in element.text), |
| 109 | "Image still present in the textbox") |
| 110 | |
| 111 | def test_set_download_dir(self): |
| 112 | """ |
| 113 | Validate the allowed and disallowed types in the directory field for |
| 114 | DL_DIR |
| 115 | """ |
| 116 | |
| 117 | ProjectVariable.objects.get_or_create(project=self.project1, |
| 118 | name='DL_DIR') |
| 119 | url = reverse('projectconf', args=(self.project1.id,)) |
| 120 | self.get(url) |
| 121 | |
| 122 | # activate the input to edit download dir |
| 123 | self.click('#change-dl_dir-icon') |
| 124 | self.wait_until_visible('#new-dl_dir') |
| 125 | |
| 126 | # downloads dir path doesn't start with / or ${...} |
| 127 | self.enter_text('#new-dl_dir', 'home/foo') |
| 128 | element = self.wait_until_visible('#hintError-initialChar-dl_dir') |
| 129 | |
| 130 | msg = 'downloads directory path starts with invalid character but ' \ |
| 131 | 'treated as valid' |
| 132 | self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg) |
| 133 | |
| 134 | # downloads dir path has a space |
| 135 | self.driver.find_element_by_id('new-dl_dir').clear() |
| 136 | self.enter_text('#new-dl_dir', '/foo/bar a') |
| 137 | |
| 138 | element = self.wait_until_visible('#hintError-dl_dir') |
| 139 | msg = 'downloads directory path characters invalid but treated as valid' |
| 140 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) |
| 141 | |
| 142 | # downloads dir path starts with ${...} but has a space |
| 143 | self.driver.find_element_by_id('new-dl_dir').clear() |
| 144 | self.enter_text('#new-dl_dir', '${TOPDIR}/down foo') |
| 145 | |
| 146 | element = self.wait_until_visible('#hintError-dl_dir') |
| 147 | msg = 'downloads directory path characters invalid but treated as valid' |
| 148 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) |
| 149 | |
| 150 | # downloads dir path starts with / |
| 151 | self.driver.find_element_by_id('new-dl_dir').clear() |
| 152 | self.enter_text('#new-dl_dir', '/bar/foo') |
| 153 | |
| 154 | hidden_element = self.driver.find_element_by_id('hintError-dl_dir') |
| 155 | self.assertEqual(hidden_element.is_displayed(), False, |
| 156 | 'downloads directory path valid but treated as invalid') |
| 157 | |
| 158 | # downloads dir path starts with ${...} |
| 159 | self.driver.find_element_by_id('new-dl_dir').clear() |
| 160 | self.enter_text('#new-dl_dir', '${TOPDIR}/down') |
| 161 | |
| 162 | hidden_element = self.driver.find_element_by_id('hintError-dl_dir') |
| 163 | self.assertEqual(hidden_element.is_displayed(), False, |
| 164 | 'downloads directory path valid but treated as invalid') |
| 165 | |
| 166 | def test_set_sstate_dir(self): |
| 167 | """ |
| 168 | Validate the allowed and disallowed types in the directory field for |
| 169 | SSTATE_DIR |
| 170 | """ |
| 171 | |
| 172 | ProjectVariable.objects.get_or_create(project=self.project1, |
| 173 | name='SSTATE_DIR') |
| 174 | url = reverse('projectconf', args=(self.project1.id,)) |
| 175 | self.get(url) |
| 176 | |
| 177 | self.click('#change-sstate_dir-icon') |
| 178 | |
| 179 | self.wait_until_visible('#new-sstate_dir') |
| 180 | |
| 181 | # path doesn't start with / or ${...} |
| 182 | self.enter_text('#new-sstate_dir', 'home/foo') |
| 183 | element = self.wait_until_visible('#hintError-initialChar-sstate_dir') |
| 184 | |
| 185 | msg = 'sstate directory path starts with invalid character but ' \ |
| 186 | 'treated as valid' |
| 187 | self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg) |
| 188 | |
| 189 | # path has a space |
| 190 | self.driver.find_element_by_id('new-sstate_dir').clear() |
| 191 | self.enter_text('#new-sstate_dir', '/foo/bar a') |
| 192 | |
| 193 | element = self.wait_until_visible('#hintError-sstate_dir') |
| 194 | msg = 'sstate directory path characters invalid but treated as valid' |
| 195 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) |
| 196 | |
| 197 | # path starts with ${...} but has a space |
| 198 | self.driver.find_element_by_id('new-sstate_dir').clear() |
| 199 | self.enter_text('#new-sstate_dir', '${TOPDIR}/down foo') |
| 200 | |
| 201 | element = self.wait_until_visible('#hintError-sstate_dir') |
| 202 | msg = 'sstate directory path characters invalid but treated as valid' |
| 203 | self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) |
| 204 | |
| 205 | # path starts with / |
| 206 | self.driver.find_element_by_id('new-sstate_dir').clear() |
| 207 | self.enter_text('#new-sstate_dir', '/bar/foo') |
| 208 | |
| 209 | hidden_element = self.driver.find_element_by_id('hintError-sstate_dir') |
| 210 | self.assertEqual(hidden_element.is_displayed(), False, |
| 211 | 'sstate directory path valid but treated as invalid') |
| 212 | |
| 213 | # paths starts with ${...} |
| 214 | self.driver.find_element_by_id('new-sstate_dir').clear() |
| 215 | self.enter_text('#new-sstate_dir', '${TOPDIR}/down') |
| 216 | |
| 217 | hidden_element = self.driver.find_element_by_id('hintError-sstate_dir') |
| 218 | self.assertEqual(hidden_element.is_displayed(), False, |
| 219 | 'sstate directory path valid but treated as invalid') |