aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster/tests/browser/test_new_custom_image_page.py
blob: 3b47a497e83c460d22ff3549f1118d3544bbd78f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/env python
#
# BitBake Toaster Implementation
#
# Copyright (C) 2013-2016 Intel Corporation
#
# SPDX-License-Identifier: GPL-2.0-only
#

from django.core.urlresolvers import reverse
from tests.browser.selenium_helpers import SeleniumTestCase

from orm.models import BitbakeVersion, Release, Project, ProjectLayer, Layer
from orm.models import Layer_Version, Recipe, CustomImageRecipe


class TestNewCustomImagePage(SeleniumTestCase):
    CUSTOM_IMAGE_NAME = 'roopa-doopa'

    def setUp(self):
        release = Release.objects.create(
            name='baz',
            bitbake_version=BitbakeVersion.objects.create(name='v1')
        )

        # project to add new custom images to
        self.project = Project.objects.create(name='foo', release=release)

        # layer associated with the project
        layer = Layer.objects.create(name='bar')
        layer_version = Layer_Version.objects.create(
            layer=layer,
            project=self.project
        )

        # properly add the layer to the project
        ProjectLayer.objects.create(
            project=self.project,
            layercommit=layer_version,
            optional=False
        )

        # add a fake image recipe to the layer that can be customised
        self.recipe = Recipe.objects.create(
            name='core-image-minimal',
            layer_version=layer_version,
            is_image=True
        )

        # another project with a custom image already in it
        project2 = Project.objects.create(name='whoop', release=release)
        layer_version2 = Layer_Version.objects.create(
            layer=layer,
            project=project2
        )
        ProjectLayer.objects.create(
            project=project2,
            layercommit=layer_version2,
            optional=False
        )
        recipe2 = Recipe.objects.create(
            name='core-image-minimal',
            layer_version=layer_version2,
            is_image=True
        )
        CustomImageRecipe.objects.create(
            name=self.CUSTOM_IMAGE_NAME,
            base_recipe=recipe2,
            layer_version=layer_version2,
            file_path='/1/2',
            project=project2
        )

    def _create_custom_image(self, new_custom_image_name):
        """
        1. Go to the 'new custom image' page
        2. Click the button for the fake core-image-minimal
        3. Wait for the dialog box for setting the name of the new custom
           image
        4. Insert new_custom_image_name into that dialog's text box
        """
        url = reverse('newcustomimage', args=(self.project.id,))
        self.get(url)

        self.click('button[data-recipe="%s"]' % self.recipe.id)

        selector = '#new-custom-image-modal input[type="text"]'
        self.enter_text(selector, new_custom_image_name)

        self.click('#create-new-custom-image-btn')

    def _check_for_custom_image(self, image_name):
        """
        Fetch the list of custom images for the project and check the
        image with name image_name is listed there
        """
        url = reverse('projectcustomimages', args=(self.project.id,))
        self.get(url)

        self.wait_until_visible('#customimagestable')

        element = self.find('#customimagestable td[class="name"] a')
        msg = 'should be a custom image link with text %s' % image_name
        self.assertEqual(element.text.strip(), image_name, msg)

    def test_new_image(self):
        """
        Should be able to create a new custom image
        """
        custom_image_name = 'boo-image'
        self._create_custom_image(custom_image_name)
        self.wait_until_visible('#image-created-notification')
        self._check_for_custom_image(custom_image_name)

    def test_new_duplicates_other_project_image(self):
        """
        Should be able to create a new custom image if its name is the same
        as a custom image in another project
        """
        self._create_custom_image(self.CUSTOM_IMAGE_NAME)
        self.wait_until_visible('#image-created-notification')
        self._check_for_custom_image(self.CUSTOM_IMAGE_NAME)

    def test_new_duplicates_non_image_recipe(self):
        """
        Should not be able to create a new custom image whose name is the
        same as an existing non-image recipe
        """
        self._create_custom_image(self.recipe.name)
        element = self.wait_until_visible('#invalid-name-help')
        self.assertRegexpMatches(element.text.strip(),
                                 'image with this name already exists')

    def test_new_duplicates_project_image(self):
        """
        Should not be able to create a new custom image whose name is the same
        as a custom image in this project
        """
        # create the image
        custom_image_name = 'doh-image'
        self._create_custom_image(custom_image_name)
        self.wait_until_visible('#image-created-notification')
        self._check_for_custom_image(custom_image_name)

        # try to create an image with the same name
        self._create_custom_image(custom_image_name)
        element = self.wait_until_visible('#invalid-name-help')
        expected = 'An image with this name already exists in this project'
        self.assertRegexpMatches(element.text.strip(), expected)