summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/tests
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2024-10-17 14:37:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-10-24 11:24:03 +0100
commit86bcd2da051f682bf779cf1b1c5d31b1a689ef45 (patch)
treec68fdd094b8ffa2a936d62772c816f4dd5fbf308 /bitbake/lib/toaster/tests
parent38a29dff866604ec37f983f11b487a630cd87b56 (diff)
downloadpoky-86bcd2da051f682bf779cf1b1c5d31b1a689ef45.tar.gz
bitbake: toaster/tests/functional: Move _create_test_new_project to base class as helper
The test project creation is needed by mutliple tests. Move it to the base class as a helper function for reuse. (Bitbake rev: abe483b98b38e95b4ad42629a67fb5d243c94094) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/tests')
-rw-r--r--bitbake/lib/toaster/tests/functional/functional_helpers.py72
-rw-r--r--bitbake/lib/toaster/tests/functional/test_create_new_project.py69
2 files changed, 72 insertions, 69 deletions
diff --git a/bitbake/lib/toaster/tests/functional/functional_helpers.py b/bitbake/lib/toaster/tests/functional/functional_helpers.py
index 7c20437d14..d3e38b658b 100644
--- a/bitbake/lib/toaster/tests/functional/functional_helpers.py
+++ b/bitbake/lib/toaster/tests/functional/functional_helpers.py
@@ -12,9 +12,12 @@ import logging
12import subprocess 12import subprocess
13import signal 13import signal
14import re 14import re
15import requests
15 16
17from django.urls import reverse
16from tests.browser.selenium_helpers_base import SeleniumTestCaseBase 18from tests.browser.selenium_helpers_base import SeleniumTestCaseBase
17from selenium.webdriver.common.by import By 19from selenium.webdriver.common.by import By
20from selenium.webdriver.support.select import Select
18from selenium.common.exceptions import NoSuchElementException 21from selenium.common.exceptions import NoSuchElementException
19 22
20logger = logging.getLogger("toaster") 23logger = logging.getLogger("toaster")
@@ -136,3 +139,72 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase):
136 except NoSuchElementException: 139 except NoSuchElementException:
137 return False 140 return False
138 return element 141 return element
142
143 def _create_test_new_project(
144 self,
145 project_name,
146 release,
147 release_title,
148 merge_toaster_settings,
149 ):
150 """ Create/Test new project using:
151 - Project Name: Any string
152 - Release: Any string
153 - Merge Toaster settings: True or False
154 """
155
156 # Obtain a CSRF token from a suitable URL
157 projs = requests.get(self.live_server_url + reverse('newproject'))
158 csrftoken = projs.cookies.get('csrftoken')
159
160 # Use the projects typeahead to find out if the project already exists
161 req = requests.get(self.live_server_url + reverse('xhr_projectstypeahead'), {'search': project_name, 'format' : 'json'})
162 data = req.json()
163 # Delete any existing projects
164 for result in data['results']:
165 del_url = reverse('xhr_project', args=(result['id'],))
166 del_response = requests.delete(self.live_server_url + del_url, cookies={'csrftoken': csrftoken}, headers={'X-CSRFToken': csrftoken})
167 self.assertEqual(del_response.status_code, 200)
168
169 self.get(reverse('newproject'))
170 self.wait_until_visible('#new-project-name', poll=3)
171 self.driver.find_element(By.ID,
172 "new-project-name").send_keys(project_name)
173
174 select = Select(self.find('#projectversion'))
175 select.select_by_value(release)
176
177 # check merge toaster settings
178 checkbox = self.find('.checkbox-mergeattr')
179 if merge_toaster_settings:
180 if not checkbox.is_selected():
181 checkbox.click()
182 else:
183 if checkbox.is_selected():
184 checkbox.click()
185
186 self.driver.find_element(By.ID, "create-project-button").click()
187
188 element = self.wait_until_visible('#project-created-notification', poll=3)
189 self.assertTrue(
190 self.element_exists('#project-created-notification'),
191 f"Project:{project_name} creation notification not shown"
192 )
193 self.assertTrue(
194 project_name in element.text,
195 f"New project name:{project_name} not in new project notification"
196 )
197
198 # Use the projects typeahead again to check the project now exists
199 req = requests.get(self.live_server_url + reverse('xhr_projectstypeahead'), {'search': project_name, 'format' : 'json'})
200 data = req.json()
201 self.assertGreater(len(data['results']), 0, f"New project:{project_name} not found in database")
202
203 # check release
204 self.assertTrue(re.search(
205 release_title,
206 self.driver.find_element(By.XPATH,
207 "//span[@id='project-release-title']"
208 ).text),
209 'The project release is not defined')
210
diff --git a/bitbake/lib/toaster/tests/functional/test_create_new_project.py b/bitbake/lib/toaster/tests/functional/test_create_new_project.py
index 577ca7239d..168a396717 100644
--- a/bitbake/lib/toaster/tests/functional/test_create_new_project.py
+++ b/bitbake/lib/toaster/tests/functional/test_create_new_project.py
@@ -8,7 +8,6 @@
8 8
9import re 9import re
10import pytest 10import pytest
11import requests
12from django.urls import reverse 11from django.urls import reverse
13from selenium.webdriver.support.select import Select 12from selenium.webdriver.support.select import Select
14from tests.functional.functional_helpers import SeleniumFunctionalTestCase 13from tests.functional.functional_helpers import SeleniumFunctionalTestCase
@@ -16,74 +15,6 @@ from selenium.webdriver.common.by import By
16 15
17class TestCreateNewProject(SeleniumFunctionalTestCase): 16class TestCreateNewProject(SeleniumFunctionalTestCase):
18 17
19 def _create_test_new_project(
20 self,
21 project_name,
22 release,
23 release_title,
24 merge_toaster_settings,
25 ):
26 """ Create/Test new project using:
27 - Project Name: Any string
28 - Release: Any string
29 - Merge Toaster settings: True or False
30 """
31
32 # Obtain a CSRF token from a suitable URL
33 projs = requests.get(self.live_server_url + reverse('newproject'))
34 csrftoken = projs.cookies.get('csrftoken')
35
36 # Use the projects typeahead to find out if the project already exists
37 req = requests.get(self.live_server_url + reverse('xhr_projectstypeahead'), {'search': project_name, 'format' : 'json'})
38 data = req.json()
39 # Delete any existing projects
40 for result in data['results']:
41 del_url = reverse('xhr_project', args=(result['id'],))
42 del_response = requests.delete(self.live_server_url + del_url, cookies={'csrftoken': csrftoken}, headers={'X-CSRFToken': csrftoken})
43 self.assertEqual(del_response.status_code, 200)
44
45 self.get(reverse('newproject'))
46 self.wait_until_visible('#new-project-name', poll=3)
47 self.driver.find_element(By.ID,
48 "new-project-name").send_keys(project_name)
49
50 select = Select(self.find('#projectversion'))
51 select.select_by_value(release)
52
53 # check merge toaster settings
54 checkbox = self.find('.checkbox-mergeattr')
55 if merge_toaster_settings:
56 if not checkbox.is_selected():
57 checkbox.click()
58 else:
59 if checkbox.is_selected():
60 checkbox.click()
61
62 self.driver.find_element(By.ID, "create-project-button").click()
63
64 element = self.wait_until_visible('#project-created-notification', poll=3)
65 self.assertTrue(
66 self.element_exists('#project-created-notification'),
67 f"Project:{project_name} creation notification not shown"
68 )
69 self.assertTrue(
70 project_name in element.text,
71 f"New project name:{project_name} not in new project notification"
72 )
73
74 # Use the projects typeahead again to check the project now exists
75 req = requests.get(self.live_server_url + reverse('xhr_projectstypeahead'), {'search': project_name, 'format' : 'json'})
76 data = req.json()
77 self.assertGreater(len(data['results']), 0, f"New project:{project_name} not found in database")
78
79 # check release
80 self.assertTrue(re.search(
81 release_title,
82 self.driver.find_element(By.XPATH,
83 "//span[@id='project-release-title']"
84 ).text),
85 'The project release is not defined')
86
87 def test_create_new_project_master(self): 18 def test_create_new_project_master(self):
88 """ Test create new project using: 19 """ Test create new project using:
89 - Project Name: Any string 20 - Project Name: Any string