1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-09 17:39:31 +00:00

bitbake: toaster/tests/functiona/project_page: Switch to using library create_project function

Switch this test module to use the common project creation code which contains
race fixes. That code requires the database access wrapper be dropped and
we no longer have ordering constraints.

There are two tests that do require database access. Move these to a separate class
and allow database access there. Use ordering constraints to allow them to run
after the main code. They depend on the project creation from the other class which
isn't ideal but good enough for now.

(Bitbake rev: e441bfe98ac41d48692ffbaeec90a9c780337fa4)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2024-10-18 22:25:38 +01:00
parent 57bdcaf417
commit 566c6dca28
@@ -7,7 +7,6 @@
# #
import os import os
import random
import string import string
from unittest import skip from unittest import skip
import pytest import pytest
@@ -22,58 +21,17 @@ from selenium.webdriver.common.by import By
from .utils import get_projectId_from_url, wait_until_build, wait_until_build_cancelled from .utils import get_projectId_from_url, wait_until_build, wait_until_build_cancelled
class TestProjectPageBase(SeleniumFunctionalTestCase):
@pytest.mark.django_db
@pytest.mark.order("last")
class TestProjectPage(SeleniumFunctionalTestCase):
project_id = None project_id = None
PROJECT_NAME = 'TestProjectPage' PROJECT_NAME = 'TestProjectPage'
def _create_project(self, project_name):
""" Create/Test new project using:
- Project Name: Any string
- Release: Any string
- Merge Toaster settings: True or False
"""
self.get(reverse('newproject'))
self.wait_until_visible('#new-project-name')
self.find("#new-project-name").send_keys(project_name)
select = Select(self.find("#projectversion"))
select.select_by_value('3')
# check merge toaster settings
checkbox = self.find('.checkbox-mergeattr')
if not checkbox.is_selected():
checkbox.click()
if self.PROJECT_NAME != 'TestProjectPage':
# Reset project name if it's not the default one
self.PROJECT_NAME = 'TestProjectPage'
self.find("#create-project-button").click()
try:
self.wait_until_visible('#hint-error-project-name')
url = reverse('project', args=(TestProjectPage.project_id, ))
self.get(url)
self.wait_until_visible('#config-nav', poll=3)
except TimeoutException:
self.wait_until_visible('#config-nav', poll=3)
def _random_string(self, length):
return ''.join(
random.choice(string.ascii_letters) for _ in range(length)
)
def _navigate_to_project_page(self): def _navigate_to_project_page(self):
# Navigate to project page # Navigate to project page
if TestProjectPage.project_id is None: if TestProjectPageBase.project_id is None:
self._create_project(project_name=self._random_string(10)) TestProjectPageBase.project_id = self.create_new_project(self.PROJECT_NAME, '3', None, True)
current_url = self.driver.current_url
TestProjectPage.project_id = get_projectId_from_url(current_url) url = reverse('project', args=(TestProjectPageBase.project_id,))
else: self.get(url)
url = reverse('project', args=(TestProjectPage.project_id,))
self.get(url)
self.wait_until_visible('#config-nav') self.wait_until_visible('#config-nav')
def _get_create_builds(self, **kwargs): def _get_create_builds(self, **kwargs):
@@ -81,14 +39,14 @@ class TestProjectPage(SeleniumFunctionalTestCase):
# parameters for builds to associate with the projects # parameters for builds to associate with the projects
now = timezone.now() now = timezone.now()
self.project1_build_success = { self.project1_build_success = {
'project': Project.objects.get(id=TestProjectPage.project_id), 'project': Project.objects.get(id=TestProjectPageBase.project_id),
'started_on': now, 'started_on': now,
'completed_on': now, 'completed_on': now,
'outcome': Build.SUCCEEDED 'outcome': Build.SUCCEEDED
} }
self.project1_build_failure = { self.project1_build_failure = {
'project': Project.objects.get(id=TestProjectPage.project_id), 'project': Project.objects.get(id=TestProjectPageBase.project_id),
'started_on': now, 'started_on': now,
'completed_on': now, 'completed_on': now,
'outcome': Build.FAILED 'outcome': Build.FAILED
@@ -222,6 +180,8 @@ class TestProjectPage(SeleniumFunctionalTestCase):
rows = self.find_all(f'#{table_selector} tbody tr') rows = self.find_all(f'#{table_selector} tbody tr')
self.assertTrue(len(rows) > 0) self.assertTrue(len(rows) > 0)
class TestProjectPage(TestProjectPageBase):
def test_create_project(self): def test_create_project(self):
""" Create/Test new project using: """ Create/Test new project using:
- Project Name: Any string - Project Name: Any string
@@ -230,26 +190,6 @@ class TestProjectPage(SeleniumFunctionalTestCase):
""" """
self._create_project(project_name=self.PROJECT_NAME) self._create_project(project_name=self.PROJECT_NAME)
def test_image_recipe_editColumn(self):
""" Test the edit column feature in image recipe table on project page """
self._get_create_builds(success=10, failure=10)
url = reverse('projectimagerecipes', args=(TestProjectPage.project_id,))
self.get(url)
self.wait_until_present('#imagerecipestable tbody tr')
column_list = [
'get_description_or_summary', 'layer_version__get_vcs_reference',
'layer_version__layer__name', 'license', 'recipe-file', 'section',
'version'
]
# Check that we can hide the edit column
self._mixin_test_table_edit_column(
'imagerecipestable',
'edit-columns-button',
[f'checkbox-{column}' for column in column_list]
)
def test_page_header_on_project_page(self): def test_page_header_on_project_page(self):
""" Check page header in project page: """ Check page header in project page:
@@ -379,7 +319,7 @@ class TestProjectPage(SeleniumFunctionalTestCase):
self.assertEqual(config_tab.get_attribute('class'), 'active') self.assertEqual(config_tab.get_attribute('class'), 'active')
self.assertIn('Configuration', str(config_tab.text)) self.assertIn('Configuration', str(config_tab.text))
self.assertIn( self.assertIn(
f"/toastergui/project/{TestProjectPage.project_id}", str(self.driver.current_url) f"/toastergui/project/{TestProjectPageBase.project_id}", str(self.driver.current_url)
) )
def get_tabs(): def get_tabs():
@@ -402,7 +342,7 @@ class TestProjectPage(SeleniumFunctionalTestCase):
check_tab_link( check_tab_link(
1, 1,
'Builds', 'Builds',
f"/toastergui/project/{TestProjectPage.project_id}/builds" f"/toastergui/project/{TestProjectPageBase.project_id}/builds"
) )
# check "Import layers" tab # check "Import layers" tab
@@ -411,7 +351,7 @@ class TestProjectPage(SeleniumFunctionalTestCase):
check_tab_link( check_tab_link(
2, 2,
'Import layer', 'Import layer',
f"/toastergui/project/{TestProjectPage.project_id}/importlayer" f"/toastergui/project/{TestProjectPageBase.project_id}/importlayer"
) )
# check "New custom image" tab # check "New custom image" tab
@@ -420,7 +360,7 @@ class TestProjectPage(SeleniumFunctionalTestCase):
check_tab_link( check_tab_link(
3, 3,
'New custom image', 'New custom image',
f"/toastergui/project/{TestProjectPage.project_id}/newcustomimage" f"/toastergui/project/{TestProjectPageBase.project_id}/newcustomimage"
) )
# check search box can be use to build recipes # check search box can be use to build recipes
@@ -766,6 +706,10 @@ class TestProjectPage(SeleniumFunctionalTestCase):
# Check layer description # Check layer description
self.assertIn("Description", section.text) self.assertIn("Description", section.text)
@pytest.mark.django_db
@pytest.mark.order("last")
class TestProjectPageRecipes(TestProjectPageBase):
def test_single_recipe_page(self): def test_single_recipe_page(self):
""" Test recipe page """ Test recipe page
- Check if title is displayed - Check if title is displayed
@@ -777,9 +721,9 @@ class TestProjectPage(SeleniumFunctionalTestCase):
# Use a recipe which is likely to exist in the layer index but not enabled # Use a recipe which is likely to exist in the layer index but not enabled
# in poky out the box - xen-image-minimal from meta-virtualization # in poky out the box - xen-image-minimal from meta-virtualization
self._navigate_to_project_page() self._navigate_to_project_page()
prj = Project.objects.get(pk=TestProjectPage.project_id) prj = Project.objects.get(pk=TestProjectPageBase.project_id)
recipe_id = prj.get_all_compatible_recipes().get(name="xen-image-minimal").pk recipe_id = prj.get_all_compatible_recipes().get(name="xen-image-minimal").pk
url = reverse("recipedetails", args=(TestProjectPage.project_id, recipe_id)) url = reverse("recipedetails", args=(TestProjectPageBase.project_id, recipe_id))
self.get(url) self.get(url)
self.wait_until_visible('.page-header') self.wait_until_visible('.page-header')
# check title is displayed # check title is displayed
@@ -802,3 +746,25 @@ class TestProjectPage(SeleniumFunctionalTestCase):
self.assertIn("Approx. packages included", section.text) self.assertIn("Approx. packages included", section.text)
self.assertIn("Approx. package size", section.text) self.assertIn("Approx. package size", section.text)
self.assertIn("Recipe file", section.text) self.assertIn("Recipe file", section.text)
def test_image_recipe_editColumn(self):
""" Test the edit column feature in image recipe table on project page """
self._get_create_builds(success=10, failure=10)
url = reverse('projectimagerecipes', args=(TestProjectPageBase.project_id,))
self.get(url)
self.wait_until_present('#imagerecipestable tbody tr')
column_list = [
'get_description_or_summary', 'layer_version__get_vcs_reference',
'layer_version__layer__name', 'license', 'recipe-file', 'section',
'version'
]
# Check that we can hide the edit column
self._mixin_test_table_edit_column(
'imagerecipestable',
'edit-columns-button',
[f'checkbox-{column}' for column in column_list]
)