Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [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 | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8 | # |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 9 | from bldcontrol.models import BuildEnvironment |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 11 | from django.urls import reverse |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 12 | from tests.browser.selenium_helpers import SeleniumTestCase |
| 13 | |
| 14 | from orm.models import BitbakeVersion, Release, Project, ProjectLayer, Layer |
| 15 | from orm.models import Layer_Version, Recipe, CustomImageRecipe |
| 16 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 17 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 18 | class TestNewCustomImagePage(SeleniumTestCase): |
| 19 | CUSTOM_IMAGE_NAME = 'roopa-doopa' |
| 20 | |
| 21 | def setUp(self): |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 22 | BuildEnvironment.objects.get_or_create( |
| 23 | betype=BuildEnvironment.TYPE_LOCAL, |
| 24 | ) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 25 | 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 Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 48 | builldir = os.environ.get('BUILDDIR', './') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | self.recipe = Recipe.objects.create( |
| 50 | name='core-image-minimal', |
| 51 | layer_version=layer_version, |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 52 | file_path=f'{builldir}/core-image-minimal.bb', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 53 | is_image=True |
| 54 | ) |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 55 | # create a tmp file for the recipe |
| 56 | with open(self.recipe.file_path, 'w') as f: |
| 57 | f.write('foo') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 58 | |
| 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 Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 140 | self.assertRegex(element.text.strip(), |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 141 | 'image with this name already exists') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 142 | |
| 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 Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 158 | self.assertRegex(element.text.strip(), expected) |