~yolanda.robla/glance/precise-security

« back to all changes in this revision

Viewing changes to tests/unit/test_clients.py

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2011-05-25 15:57:15 UTC
  • mto: (50.1.2 precise-proposed)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20110525155715-bcf1daw2ntyfly1v
Tags: upstream-2011.3~bzr132
ImportĀ upstreamĀ versionĀ 2011.3~bzr132

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import webob
25
25
 
26
26
from glance import client
 
27
from glance.common import exception
 
28
import glance.registry.db.api
27
29
from glance.registry import client as rclient
28
 
from glance.common import exception
29
30
from tests import stubs
30
31
 
31
32
 
69
70
        for k, v in fixture.items():
70
71
            self.assertEquals(v, images[0][k])
71
72
 
 
73
    def test_get_image_index_by_name(self):
 
74
        """Test correct set of public, name-filtered image returned. This
 
75
        is just a sanity check, we test the details call more in-depth."""
 
76
        extra_fixture = {'id': 3,
 
77
                         'status': 'active',
 
78
                         'is_public': True,
 
79
                         'disk_format': 'vhd',
 
80
                         'container_format': 'ovf',
 
81
                         'name': 'new name! #123',
 
82
                         'size': 19,
 
83
                         'checksum': None}
 
84
 
 
85
        glance.registry.db.api.image_create(None, extra_fixture)
 
86
 
 
87
        images = self.client.get_images({'name': 'new name! #123'})
 
88
        self.assertEquals(len(images), 1)
 
89
 
 
90
        for image in images:
 
91
            self.assertEquals('new name! #123', image['name'])
 
92
 
72
93
    def test_get_image_details(self):
73
94
        """Tests that the detailed info about public images returned"""
74
95
        fixture = {'id': 2,
87
108
        for k, v in fixture.items():
88
109
            self.assertEquals(v, images[0][k])
89
110
 
 
111
    def test_get_image_details_by_name(self):
 
112
        """Tests that a detailed call can be filtered by name"""
 
113
        extra_fixture = {'id': 3,
 
114
                         'status': 'active',
 
115
                         'is_public': True,
 
116
                         'disk_format': 'vhd',
 
117
                         'container_format': 'ovf',
 
118
                         'name': 'new name! #123',
 
119
                         'size': 19,
 
120
                         'checksum': None}
 
121
 
 
122
        glance.registry.db.api.image_create(None, extra_fixture)
 
123
 
 
124
        images = self.client.get_images_detailed({'name': 'new name! #123'})
 
125
        self.assertEquals(len(images), 1)
 
126
 
 
127
        for image in images:
 
128
            self.assertEquals('new name! #123', image['name'])
 
129
 
 
130
    def test_get_image_details_by_status(self):
 
131
        """Tests that a detailed call can be filtered by status"""
 
132
        extra_fixture = {'id': 3,
 
133
                         'status': 'saving',
 
134
                         'is_public': True,
 
135
                         'disk_format': 'vhd',
 
136
                         'container_format': 'ovf',
 
137
                         'name': 'new name! #123',
 
138
                         'size': 19,
 
139
                         'checksum': None}
 
140
 
 
141
        glance.registry.db.api.image_create(None, extra_fixture)
 
142
 
 
143
        images = self.client.get_images_detailed({'status': 'saving'})
 
144
        self.assertEquals(len(images), 1)
 
145
 
 
146
        for image in images:
 
147
            self.assertEquals('saving', image['status'])
 
148
 
 
149
    def test_get_image_details_by_container_format(self):
 
150
        """Tests that a detailed call can be filtered by container_format"""
 
151
        extra_fixture = {'id': 3,
 
152
                         'status': 'saving',
 
153
                         'is_public': True,
 
154
                         'disk_format': 'vhd',
 
155
                         'container_format': 'ovf',
 
156
                         'name': 'new name! #123',
 
157
                         'size': 19,
 
158
                         'checksum': None}
 
159
 
 
160
        glance.registry.db.api.image_create(None, extra_fixture)
 
161
 
 
162
        images = self.client.get_images_detailed({'container_format': 'ovf'})
 
163
        self.assertEquals(len(images), 2)
 
164
 
 
165
        for image in images:
 
166
            self.assertEquals('ovf', image['container_format'])
 
167
 
 
168
    def test_get_image_details_by_disk_format(self):
 
169
        """Tests that a detailed call can be filtered by disk_format"""
 
170
        extra_fixture = {'id': 3,
 
171
                         'status': 'saving',
 
172
                         'is_public': True,
 
173
                         'disk_format': 'vhd',
 
174
                         'container_format': 'ovf',
 
175
                         'name': 'new name! #123',
 
176
                         'size': 19,
 
177
                         'checksum': None}
 
178
 
 
179
        glance.registry.db.api.image_create(None, extra_fixture)
 
180
 
 
181
        images = self.client.get_images_detailed({'disk_format': 'vhd'})
 
182
        self.assertEquals(len(images), 2)
 
183
 
 
184
        for image in images:
 
185
            self.assertEquals('vhd', image['disk_format'])
 
186
 
 
187
    def test_get_image_details_with_maximum_size(self):
 
188
        """Tests that a detailed call can be filtered by size_max"""
 
189
        extra_fixture = {'id': 3,
 
190
                         'status': 'saving',
 
191
                         'is_public': True,
 
192
                         'disk_format': 'vhd',
 
193
                         'container_format': 'ovf',
 
194
                         'name': 'new name! #123',
 
195
                         'size': 21,
 
196
                         'checksum': None}
 
197
 
 
198
        glance.registry.db.api.image_create(None, extra_fixture)
 
199
 
 
200
        images = self.client.get_images_detailed({'size_max': 20})
 
201
        self.assertEquals(len(images), 1)
 
202
 
 
203
        for image in images:
 
204
            self.assertTrue(image['size'] <= 20)
 
205
 
 
206
    def test_get_image_details_with_minimum_size(self):
 
207
        """Tests that a detailed call can be filtered by size_min"""
 
208
        extra_fixture = {'id': 3,
 
209
                         'status': 'saving',
 
210
                         'is_public': True,
 
211
                         'disk_format': 'vhd',
 
212
                         'container_format': 'ovf',
 
213
                         'name': 'new name! #123',
 
214
                         'size': 20,
 
215
                         'checksum': None}
 
216
 
 
217
        glance.registry.db.api.image_create(None, extra_fixture)
 
218
 
 
219
        images = self.client.get_images_detailed({'size_min': 20})
 
220
        self.assertEquals(len(images), 1)
 
221
 
 
222
        for image in images:
 
223
            self.assertTrue(image['size'] >= 20)
 
224
 
 
225
    def test_get_image_details_by_property(self):
 
226
        """Tests that a detailed call can be filtered by a property"""
 
227
        extra_fixture = {'id': 3,
 
228
                         'status': 'saving',
 
229
                         'is_public': True,
 
230
                         'disk_format': 'vhd',
 
231
                         'container_format': 'ovf',
 
232
                         'name': 'new name! #123',
 
233
                         'size': 19,
 
234
                         'checksum': None,
 
235
                         'properties': {'p a': 'v a'}}
 
236
 
 
237
        glance.registry.db.api.image_create(None, extra_fixture)
 
238
 
 
239
        images = self.client.get_images_detailed({'property-p a': 'v a'})
 
240
        self.assertEquals(len(images), 1)
 
241
 
 
242
        for image in images:
 
243
            self.assertEquals('v a', image['properties']['p a'])
 
244
 
90
245
    def test_get_image(self):
91
246
        """Tests that the detailed info about an image returned"""
92
247
        fixture = {'id': 1,
256
411
        stubs.stub_out_registry_db_image_api(self.stubs)
257
412
        stubs.stub_out_registry_and_store_server(self.stubs)
258
413
        stubs.stub_out_filesystem_backend()
259
 
        self.client = client.Client("0.0.0.0")
 
414
        self.client = client.Client("0.0.0.0", doc_root="")
260
415
 
261
416
    def tearDown(self):
262
417
        """Clear the test environment"""