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