blob: 4ad22c7aa75a2448bed9acbaf3dff97dddb4737d [file] [log] [blame]
Brad Bishop96ff1982019-08-19 13:50:42 -04001#! /usr/bin/env python3
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002#
3# BitBake Toaster Implementation
4#
5# Copyright (C) 2013-2016 Intel Corporation
6#
Brad Bishopc342db32019-05-15 21:57:59 -04007# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008#
Andrew Geissler20137392023-10-12 04:59:14 -06009from bldcontrol.models import BuildEnvironment
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010
Andrew Geissler82c905d2020-04-13 13:39:40 -050011from django.urls import reverse
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050012from tests.browser.selenium_helpers import SeleniumTestCase
13
14from orm.models import BitbakeVersion, Release, Project, ProjectLayer, Layer
15from orm.models import Layer_Version, Recipe, CustomImageRecipe
16
Patrick Williamsc0f7c042017-02-23 20:41:17 -060017
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050018class TestNewCustomImagePage(SeleniumTestCase):
19 CUSTOM_IMAGE_NAME = 'roopa-doopa'
20
21 def setUp(self):
Andrew Geissler20137392023-10-12 04:59:14 -060022 BuildEnvironment.objects.get_or_create(
23 betype=BuildEnvironment.TYPE_LOCAL,
24 )
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050025 release = Release.objects.create(
26 name='baz',
27 bitbake_version=BitbakeVersion.objects.create(name='v1')
28 )
29
30 # project to add new custom images to
31 self.project = Project.objects.create(name='foo', release=release)
32
33 # layer associated with the project
34 layer = Layer.objects.create(name='bar')
35 layer_version = Layer_Version.objects.create(
36 layer=layer,
37 project=self.project
38 )
39
40 # properly add the layer to the project
41 ProjectLayer.objects.create(
42 project=self.project,
43 layercommit=layer_version,
44 optional=False
45 )
46
47 # add a fake image recipe to the layer that can be customised
Patrick Williams169d7bc2024-01-05 11:33:25 -060048 builldir = os.environ.get('BUILDDIR', './')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049 self.recipe = Recipe.objects.create(
50 name='core-image-minimal',
51 layer_version=layer_version,
Patrick Williams169d7bc2024-01-05 11:33:25 -060052 file_path=f'{builldir}/core-image-minimal.bb',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053 is_image=True
54 )
Patrick Williamsac13d5f2023-11-24 18:59:46 -060055 # create a tmp file for the recipe
56 with open(self.recipe.file_path, 'w') as f:
57 f.write('foo')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058
59 # another project with a custom image already in it
60 project2 = Project.objects.create(name='whoop', release=release)
61 layer_version2 = Layer_Version.objects.create(
62 layer=layer,
63 project=project2
64 )
65 ProjectLayer.objects.create(
66 project=project2,
67 layercommit=layer_version2,
68 optional=False
69 )
70 recipe2 = Recipe.objects.create(
71 name='core-image-minimal',
72 layer_version=layer_version2,
73 is_image=True
74 )
75 CustomImageRecipe.objects.create(
76 name=self.CUSTOM_IMAGE_NAME,
77 base_recipe=recipe2,
78 layer_version=layer_version2,
79 file_path='/1/2',
80 project=project2
81 )
82
83 def _create_custom_image(self, new_custom_image_name):
84 """
85 1. Go to the 'new custom image' page
86 2. Click the button for the fake core-image-minimal
87 3. Wait for the dialog box for setting the name of the new custom
88 image
89 4. Insert new_custom_image_name into that dialog's text box
90 """
91 url = reverse('newcustomimage', args=(self.project.id,))
92 self.get(url)
93
94 self.click('button[data-recipe="%s"]' % self.recipe.id)
95
96 selector = '#new-custom-image-modal input[type="text"]'
97 self.enter_text(selector, new_custom_image_name)
98
99 self.click('#create-new-custom-image-btn')
100
101 def _check_for_custom_image(self, image_name):
102 """
103 Fetch the list of custom images for the project and check the
104 image with name image_name is listed there
105 """
106 url = reverse('projectcustomimages', args=(self.project.id,))
107 self.get(url)
108
109 self.wait_until_visible('#customimagestable')
110
111 element = self.find('#customimagestable td[class="name"] a')
112 msg = 'should be a custom image link with text %s' % image_name
113 self.assertEqual(element.text.strip(), image_name, msg)
114
115 def test_new_image(self):
116 """
117 Should be able to create a new custom image
118 """
119 custom_image_name = 'boo-image'
120 self._create_custom_image(custom_image_name)
121 self.wait_until_visible('#image-created-notification')
122 self._check_for_custom_image(custom_image_name)
123
124 def test_new_duplicates_other_project_image(self):
125 """
126 Should be able to create a new custom image if its name is the same
127 as a custom image in another project
128 """
129 self._create_custom_image(self.CUSTOM_IMAGE_NAME)
130 self.wait_until_visible('#image-created-notification')
131 self._check_for_custom_image(self.CUSTOM_IMAGE_NAME)
132
133 def test_new_duplicates_non_image_recipe(self):
134 """
135 Should not be able to create a new custom image whose name is the
136 same as an existing non-image recipe
137 """
138 self._create_custom_image(self.recipe.name)
139 element = self.wait_until_visible('#invalid-name-help')
Patrick Williams169d7bc2024-01-05 11:33:25 -0600140 self.assertRegex(element.text.strip(),
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600141 'image with this name already exists')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500142
143 def test_new_duplicates_project_image(self):
144 """
145 Should not be able to create a new custom image whose name is the same
146 as a custom image in this project
147 """
148 # create the image
149 custom_image_name = 'doh-image'
150 self._create_custom_image(custom_image_name)
151 self.wait_until_visible('#image-created-notification')
152 self._check_for_custom_image(custom_image_name)
153
154 # try to create an image with the same name
155 self._create_custom_image(custom_image_name)
156 element = self.wait_until_visible('#invalid-name-help')
157 expected = 'An image with this name already exists in this project'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600158 self.assertRegex(element.text.strip(), expected)