blob: 0aa3b7a7740e4e676dd28fbe4554f4838096424e [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#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05009
10from django.core.urlresolvers import reverse
11from tests.browser.selenium_helpers import SeleniumTestCase
12
13from orm.models import BitbakeVersion, Release, Project, ProjectLayer, Layer
14from orm.models import Layer_Version, Recipe, CustomImageRecipe
15
Patrick Williamsc0f7c042017-02-23 20:41:17 -060016
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050017class TestNewCustomImagePage(SeleniumTestCase):
18 CUSTOM_IMAGE_NAME = 'roopa-doopa'
19
20 def setUp(self):
21 release = Release.objects.create(
22 name='baz',
23 bitbake_version=BitbakeVersion.objects.create(name='v1')
24 )
25
26 # project to add new custom images to
27 self.project = Project.objects.create(name='foo', release=release)
28
29 # layer associated with the project
30 layer = Layer.objects.create(name='bar')
31 layer_version = Layer_Version.objects.create(
32 layer=layer,
33 project=self.project
34 )
35
36 # properly add the layer to the project
37 ProjectLayer.objects.create(
38 project=self.project,
39 layercommit=layer_version,
40 optional=False
41 )
42
43 # add a fake image recipe to the layer that can be customised
44 self.recipe = Recipe.objects.create(
45 name='core-image-minimal',
46 layer_version=layer_version,
47 is_image=True
48 )
49
50 # another project with a custom image already in it
51 project2 = Project.objects.create(name='whoop', release=release)
52 layer_version2 = Layer_Version.objects.create(
53 layer=layer,
54 project=project2
55 )
56 ProjectLayer.objects.create(
57 project=project2,
58 layercommit=layer_version2,
59 optional=False
60 )
61 recipe2 = Recipe.objects.create(
62 name='core-image-minimal',
63 layer_version=layer_version2,
64 is_image=True
65 )
66 CustomImageRecipe.objects.create(
67 name=self.CUSTOM_IMAGE_NAME,
68 base_recipe=recipe2,
69 layer_version=layer_version2,
70 file_path='/1/2',
71 project=project2
72 )
73
74 def _create_custom_image(self, new_custom_image_name):
75 """
76 1. Go to the 'new custom image' page
77 2. Click the button for the fake core-image-minimal
78 3. Wait for the dialog box for setting the name of the new custom
79 image
80 4. Insert new_custom_image_name into that dialog's text box
81 """
82 url = reverse('newcustomimage', args=(self.project.id,))
83 self.get(url)
84
85 self.click('button[data-recipe="%s"]' % self.recipe.id)
86
87 selector = '#new-custom-image-modal input[type="text"]'
88 self.enter_text(selector, new_custom_image_name)
89
90 self.click('#create-new-custom-image-btn')
91
92 def _check_for_custom_image(self, image_name):
93 """
94 Fetch the list of custom images for the project and check the
95 image with name image_name is listed there
96 """
97 url = reverse('projectcustomimages', args=(self.project.id,))
98 self.get(url)
99
100 self.wait_until_visible('#customimagestable')
101
102 element = self.find('#customimagestable td[class="name"] a')
103 msg = 'should be a custom image link with text %s' % image_name
104 self.assertEqual(element.text.strip(), image_name, msg)
105
106 def test_new_image(self):
107 """
108 Should be able to create a new custom image
109 """
110 custom_image_name = 'boo-image'
111 self._create_custom_image(custom_image_name)
112 self.wait_until_visible('#image-created-notification')
113 self._check_for_custom_image(custom_image_name)
114
115 def test_new_duplicates_other_project_image(self):
116 """
117 Should be able to create a new custom image if its name is the same
118 as a custom image in another project
119 """
120 self._create_custom_image(self.CUSTOM_IMAGE_NAME)
121 self.wait_until_visible('#image-created-notification')
122 self._check_for_custom_image(self.CUSTOM_IMAGE_NAME)
123
124 def test_new_duplicates_non_image_recipe(self):
125 """
126 Should not be able to create a new custom image whose name is the
127 same as an existing non-image recipe
128 """
129 self._create_custom_image(self.recipe.name)
130 element = self.wait_until_visible('#invalid-name-help')
131 self.assertRegexpMatches(element.text.strip(),
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600132 'image with this name already exists')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500133
134 def test_new_duplicates_project_image(self):
135 """
136 Should not be able to create a new custom image whose name is the same
137 as a custom image in this project
138 """
139 # create the image
140 custom_image_name = 'doh-image'
141 self._create_custom_image(custom_image_name)
142 self.wait_until_visible('#image-created-notification')
143 self._check_for_custom_image(custom_image_name)
144
145 # try to create an image with the same name
146 self._create_custom_image(custom_image_name)
147 element = self.wait_until_visible('#invalid-name-help')
148 expected = 'An image with this name already exists in this project'
149 self.assertRegexpMatches(element.text.strip(), expected)