~ubuntu-branches/ubuntu/precise/horizon/precise-updates

« back to all changes in this revision

Viewing changes to horizon/horizon/dashboards/nova/images_and_snapshots/tests.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-16 16:34:56 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111216163456-ts9ldy8skhsg0scb
Tags: 2012.1~e2-0ubuntu1
* New upstream release (LP: #904039)
* debian/control: Update build-depends.
* debian/watch: Fix to fetch from Launchpad ad well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2011 United States Government as represented by the
 
4
# Administrator of the National Aeronautics and Space Administration.
 
5
# All Rights Reserved.
 
6
#
 
7
# Copyright 2011 Nebula, Inc.
 
8
# Copyright 2011 OpenStack LLC
 
9
#
 
10
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
11
#    not use this file except in compliance with the License. You may obtain
 
12
#    a copy of the License at
 
13
#
 
14
#         http://www.apache.org/licenses/LICENSE-2.0
 
15
#
 
16
#    Unless required by applicable law or agreed to in writing, software
 
17
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
18
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
19
#    License for the specific language governing permissions and limitations
 
20
#    under the License.
 
21
 
 
22
from django import http
 
23
from django.contrib import messages
 
24
from django.core.urlresolvers import reverse
 
25
from glance.common import exception as glance_exception
 
26
from mox import IsA
 
27
 
 
28
from horizon import api
 
29
from horizon import test
 
30
 
 
31
 
 
32
INDEX_URL = reverse('horizon:nova:images_and_snapshots:index')
 
33
 
 
34
 
 
35
class ImagesAndSnapshotsTests(test.BaseViewTests):
 
36
    def setUp(self):
 
37
        super(ImagesAndSnapshotsTests, self).setUp()
 
38
        snapshot_dict = {'name': 'snapshot',
 
39
                         'container_format': 'ami',
 
40
                         'id': 3}
 
41
        snapshot = api.Image(snapshot_dict)
 
42
        self.snapshots = [snapshot, ]
 
43
 
 
44
        image_dict = {'name': 'visibleImage',
 
45
                      'container_format': 'novaImage'}
 
46
        self.visibleImage = api.Image(image_dict)
 
47
        self.visibleImage.id = '1'
 
48
 
 
49
        image_dict = {'name': 'invisibleImage',
 
50
                      'container_format': 'aki'}
 
51
        self.invisibleImage = api.Image(image_dict)
 
52
        self.invisibleImage.id = '2'
 
53
 
 
54
        flavor = api.Flavor(None)
 
55
        flavor.id = 1
 
56
        flavor.name = 'm1.massive'
 
57
        flavor.vcpus = 1000
 
58
        flavor.disk = 1024
 
59
        flavor.ram = 10000
 
60
        self.flavors = (flavor,)
 
61
 
 
62
        self.images = (self.visibleImage, self.invisibleImage)
 
63
 
 
64
        keypair = api.KeyPair(None)
 
65
        keypair.name = 'keyName'
 
66
        self.keypairs = (keypair,)
 
67
 
 
68
        security_group = api.SecurityGroup(None)
 
69
        security_group.name = 'default'
 
70
        self.security_groups = (security_group,)
 
71
 
 
72
    def test_index(self):
 
73
        self.mox.StubOutWithMock(api, 'image_list_detailed')
 
74
        api.image_list_detailed(IsA(http.HttpRequest)).AndReturn(self.images)
 
75
 
 
76
        self.mox.StubOutWithMock(api, 'snapshot_list_detailed')
 
77
        api.snapshot_list_detailed(IsA(http.HttpRequest)).AndReturn(
 
78
                self.snapshots)
 
79
 
 
80
        self.mox.StubOutWithMock(api, 'flavor_list')
 
81
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)
 
82
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)
 
83
 
 
84
        self.mox.StubOutWithMock(api, 'security_group_list')
 
85
        api.security_group_list(IsA(http.HttpRequest)).\
 
86
                                AndReturn(self.security_groups)
 
87
        api.security_group_list(IsA(http.HttpRequest)).\
 
88
                                AndReturn(self.security_groups)
 
89
 
 
90
        self.mox.StubOutWithMock(api, 'keypair_list')
 
91
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)
 
92
 
 
93
        self.mox.StubOutWithMock(api, 'tenant_quota_get')
 
94
        api.tenant_quota_get(IsA(http.HttpRequest),
 
95
                self.TEST_TENANT).AndReturn({})
 
96
 
 
97
        self.mox.ReplayAll()
 
98
 
 
99
        res = self.client.get(INDEX_URL)
 
100
 
 
101
        self.assertTemplateUsed(res,
 
102
                                'nova/images_and_snapshots/index.html')
 
103
 
 
104
        self.assertIn('images', res.context)
 
105
        images = res.context['images']
 
106
        self.assertEqual(len(images), 1)
 
107
        self.assertEqual(images[0].name, 'visibleImage')
 
108
 
 
109
    def test_index_no_images(self):
 
110
        self.mox.StubOutWithMock(api, 'snapshot_list_detailed')
 
111
        api.snapshot_list_detailed(IsA(http.HttpRequest)).\
 
112
                                   AndReturn(self.snapshots)
 
113
 
 
114
        self.mox.StubOutWithMock(api, 'flavor_list')
 
115
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)
 
116
 
 
117
        self.mox.StubOutWithMock(api, 'security_group_list')
 
118
        api.security_group_list(IsA(http.HttpRequest)).\
 
119
                                AndReturn(self.security_groups)
 
120
 
 
121
        self.mox.StubOutWithMock(api, 'keypair_list')
 
122
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)
 
123
 
 
124
        self.mox.StubOutWithMock(api, 'image_list_detailed')
 
125
        api.image_list_detailed(IsA(http.HttpRequest)).AndReturn([])
 
126
 
 
127
        self.mox.StubOutWithMock(api, 'tenant_quota_get')
 
128
        api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \
 
129
                .AndReturn({})
 
130
 
 
131
        self.mox.StubOutWithMock(messages, 'info')
 
132
        messages.info(IsA(http.HttpRequest), IsA(basestring))
 
133
 
 
134
        self.mox.ReplayAll()
 
135
 
 
136
        res = self.client.get(INDEX_URL)
 
137
 
 
138
        self.assertTemplateUsed(res, 'nova/images_and_snapshots/index.html')
 
139
 
 
140
    def test_index_client_conn_error(self):
 
141
 
 
142
        self.mox.StubOutWithMock(api, 'image_list_detailed')
 
143
        exception = glance_exception.ClientConnectionError('clientConnError')
 
144
        api.image_list_detailed(IsA(http.HttpRequest)).AndRaise(exception)
 
145
 
 
146
        self.mox.StubOutWithMock(api, 'tenant_quota_get')
 
147
        api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \
 
148
                .AndReturn({})
 
149
 
 
150
        self.mox.StubOutWithMock(messages, 'error')
 
151
        messages.error(IsA(http.HttpRequest), IsA(basestring))
 
152
 
 
153
        self.mox.ReplayAll()
 
154
 
 
155
        res = self.client.get(INDEX_URL)
 
156
 
 
157
        self.assertTemplateUsed(res, 'nova/images_and_snapshots/index.html')