File: test_tabs.py

package info (click to toggle)
murano-dashboard 1:2.0.0-5~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,492 kB
  • sloc: python: 7,067; sh: 140; makefile: 29
file content (136 lines) | stat: -rw-r--r-- 4,563 bytes parent folder | download | duplicates (2)
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
#    Copyright (c) 2014 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import mock

from muranodashboard.catalog import tabs
from openstack_dashboard.test import helpers


class TestLicenseTab(helpers.APITestCase):
    def setUp(self):
        """Set up the Form data."""
        super(TestLicenseTab, self).setUp()

    @mock.patch('muranodashboard.catalog.tabs.services')
    def test_license(self, mock_services):
        """Check that a license is returned."""

        # Fake the services.get_app_forms() call.
        m = mock.MagicMock()
        m.base_fields = {
            'license': mock.MagicMock(
                description='Lorem ipsum dolor sit '
                            'amet, consectetur adipiscing elit.')
        }
        mock_services.get_app_forms.return_value = [('', m)]

        # Fake an application object, needed when instantiating tabs.
        app = mock.MagicMock()
        app.id = 1

        group = tabs.ApplicationTabs(self.request, application=app)
        l = group.get_tabs()[2]

        # Should return the license description
        l._get_license()
        self.assertEqual(
            'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
            l.app.license)

    @mock.patch('muranodashboard.catalog.tabs.services')
    def test_no_license(self, mock_services):
        """Check that no license is returned."""

        # Fake the services.get_app_forms() call.
        m = mock.MagicMock()
        m.base_fields = {}
        mock_services.get_app_forms.return_value = [('', m)]

        # Fake an application object, needed when instantiating tabs.
        app = mock.MagicMock()
        app.id = 1

        group = tabs.ApplicationTabs(self.request, application=app)
        l = group.get_tabs()[2]

        # Should return the license description
        l._get_license()
        self.assertEqual('', l.app.license)


class TestRequirementsTab(helpers.APITestCase):
    def setUp(self):
        """Set up the Form data."""
        super(TestRequirementsTab, self).setUp()

    @mock.patch('muranodashboard.catalog.tabs.services')
    def test_requirements(self, mock_services):
        """Check that requirements are returned."""

        m = mock.MagicMock()
        m.base_fields = {
            'flavor': mock.MagicMock(requirements={
                'min_disk': 10,
                'min_vcpus': 2,
                'min_memory_mb': 2048,
                'max_disk': 25,
                'max_vcpus': 5,
                'max_memory_mb': 16000,
            })
        }
        mock_services.get_app_forms.return_value = [('', m)]

        app = mock.MagicMock()
        app.id = 1

        group = tabs.ApplicationTabs(self.request, application=app)
        r = group.get_tabs()[1]

        # Should return the requirements list used by the template file.
        r._get_requirements()

        self.assertIn('Instance flavor:', r.app.requirements)
        flavor_req = r.app.requirements[1]

        self.assertIn('Minimum disk size: 10 GB',
                      flavor_req)
        self.assertIn('Minimum vCPUs: 2',
                      flavor_req)
        self.assertIn('Minimum RAM size: 2048 MB',
                      flavor_req)
        self.assertIn('Maximum disk size: 25 GB',
                      flavor_req)
        self.assertIn('Maximum vCPUs: 5',
                      flavor_req)
        self.assertIn('Maximum RAM size: 16000 MB',
                      flavor_req)

    @mock.patch('muranodashboard.catalog.tabs.services')
    def test_no_requirements(self, mock_services):
        """Check that no requirements are returned."""

        m = mock.MagicMock()
        m.base_fields = {}
        mock_services.get_app_forms.return_value = [('', m)]

        app = mock.MagicMock()
        app.id = 1

        group = tabs.ApplicationTabs(self.request, application=app)
        r = group.get_tabs()[1]

        # Should return an empty requirements list
        r._get_requirements()
        self.assertListEqual([], r.app.requirements)