summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/toaster/tests/browser/test_new_custom_image_page.py160
1 files changed, 160 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/tests/browser/test_new_custom_image_page.py b/bitbake/lib/toaster/tests/browser/test_new_custom_image_page.py
new file mode 100644
index 0000000000..8906cb27d9
--- /dev/null
+++ b/bitbake/lib/toaster/tests/browser/test_new_custom_image_page.py
@@ -0,0 +1,160 @@
1#! /usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# BitBake Toaster Implementation
6#
7# Copyright (C) 2013-2016 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22from django.core.urlresolvers import reverse
23from tests.browser.selenium_helpers import SeleniumTestCase
24
25from orm.models import BitbakeVersion, Release, Project, ProjectLayer, Layer
26from orm.models import Layer_Version, Recipe, CustomImageRecipe
27
28class TestNewCustomImagePage(SeleniumTestCase):
29 CUSTOM_IMAGE_NAME = 'roopa-doopa'
30
31 def setUp(self):
32 release = Release.objects.create(
33 name='baz',
34 bitbake_version=BitbakeVersion.objects.create(name='v1')
35 )
36
37 # project to add new custom images to
38 self.project = Project.objects.create(name='foo', release=release)
39
40 # layer associated with the project
41 layer = Layer.objects.create(name='bar')
42 layer_version = Layer_Version.objects.create(
43 layer=layer,
44 project=self.project
45 )
46
47 # properly add the layer to the project
48 ProjectLayer.objects.create(
49 project=self.project,
50 layercommit=layer_version,
51 optional=False
52 )
53
54 # add a fake image recipe to the layer that can be customised
55 self.recipe = Recipe.objects.create(
56 name='core-image-minimal',
57 layer_version=layer_version,
58 is_image=True
59 )
60
61 # another project with a custom image already in it
62 project2 = Project.objects.create(name='whoop', release=release)
63 layer_version2 = Layer_Version.objects.create(
64 layer=layer,
65 project=project2
66 )
67 ProjectLayer.objects.create(
68 project=project2,
69 layercommit=layer_version2,
70 optional=False
71 )
72 recipe2 = Recipe.objects.create(
73 name='core-image-minimal',
74 layer_version=layer_version2,
75 is_image=True
76 )
77 CustomImageRecipe.objects.create(
78 name=self.CUSTOM_IMAGE_NAME,
79 base_recipe=recipe2,
80 layer_version=layer_version2,
81 file_path='/1/2',
82 project=project2
83 )
84
85 def _create_custom_image(self, new_custom_image_name):
86 """
87 1. Go to the 'new custom image' page
88 2. Click the button for the fake core-image-minimal
89 3. Wait for the dialog box for setting the name of the new custom
90 image
91 4. Insert new_custom_image_name into that dialog's text box
92 """
93 url = reverse('newcustomimage', args=(self.project.id,))
94 self.get(url)
95
96 self.click('button[data-recipe="%s"]' % self.recipe.id)
97
98 selector = '#new-custom-image-modal input[type="text"]'
99 self.enter_text(selector, new_custom_image_name)
100
101 self.click('#create-new-custom-image-btn')
102
103 def _check_for_custom_image(self, image_name):
104 """
105 Fetch the list of custom images for the project and check the
106 image with name image_name is listed there
107 """
108 url = reverse('projectcustomimages', args=(self.project.id,))
109 self.get(url)
110
111 self.wait_until_visible('#customimagestable')
112
113 element = self.find('#customimagestable td[class="name"] a')
114 msg = 'should be a custom image link with text %s' % image_name
115 self.assertEqual(element.text.strip(), image_name, msg)
116
117 def test_new_image(self):
118 """
119 Should be able to create a new custom image
120 """
121 custom_image_name = 'boo-image'
122 self._create_custom_image(custom_image_name)
123 self.wait_until_visible('#image-created-notification')
124 self._check_for_custom_image(custom_image_name)
125
126 def test_new_duplicates_other_project_image(self):
127 """
128 Should be able to create a new custom image if its name is the same
129 as a custom image in another project
130 """
131 self._create_custom_image(self.CUSTOM_IMAGE_NAME)
132 self.wait_until_visible('#image-created-notification')
133 self._check_for_custom_image(self.CUSTOM_IMAGE_NAME)
134
135 def test_new_duplicates_non_image_recipe(self):
136 """
137 Should not be able to create a new custom image whose name is the
138 same as an existing non-image recipe
139 """
140 self._create_custom_image(self.recipe.name)
141 element = self.wait_until_visible('#invalid-name-help')
142 self.assertRegexpMatches(element.text.strip(),
143 'recipe with this name already exists')
144
145 def test_new_duplicates_project_image(self):
146 """
147 Should not be able to create a new custom image whose name is the same
148 as a custom image in this project
149 """
150 # create the image
151 custom_image_name = 'doh-image'
152 self._create_custom_image(custom_image_name)
153 self.wait_until_visible('#image-created-notification')
154 self._check_for_custom_image(custom_image_name)
155
156 # try to create an image with the same name
157 self._create_custom_image(custom_image_name)
158 element = self.wait_until_visible('#invalid-name-help')
159 expected = 'An image with this name already exists in this project'
160 self.assertRegexpMatches(element.text.strip(), expected)