Debian Codegraph @

glanceclient/tests/unit/v2/test_client_requests.py

raw symbols SCIP
1 # Copyright (c) 2015 OpenStack Foundation
2 # Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
3 # All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16
17 from requests_mock.contrib import fixture as rm_fixture
18
19 from glanceclient import client
20 from glanceclient.tests.unit.v2.fixtures import image_create_fixture
21 from glanceclient.tests.unit.v2.fixtures import image_list_fixture
22 from glanceclient.tests.unit.v2.fixtures import image_show_fixture
23 from glanceclient.tests.unit.v2.fixtures import schema_fixture
24 from glanceclient.tests import utils as testutils
25 from glanceclient.v2.image_schema import _BASE_SCHEMA
26
27
28 DEFAULT_PAGE_SIZE = 200
29
30
31 class ClientTestRequests(testutils.TestCase):
32 """Client tests using the requests mock library."""
33
34 def test_list_bad_image_schema(self):
35 # if kernel_id or ramdisk_id are not uuids, verify we can
36 # still perform an image listing. Regression test for bug
37 # 1477910
38 self.requests = self.useFixture(rm_fixture.Fixture())
39 self.requests.get('http://example.com/v2/schemas/image',
40 json=schema_fixture)
41 self.requests.get('http://example.com/v2/images?'
42 f'limit={DEFAULT_PAGE_SIZE}',
43 json=image_list_fixture)
44 gc = client.Client(2.2, "http://example.com/v2.1")
45 images = gc.images.list()
46 for image in images:
47 pass
48
49 def test_show_bad_image_schema(self):
50 # if kernel_id or ramdisk_id are not uuids, verify we
51 # don't fail due to schema validation
52 self.requests = self.useFixture(rm_fixture.Fixture())
53 self.requests.get('http://example.com/v2/schemas/image',
54 json=schema_fixture)
55 self.requests.get('http://example.com/v2/images/%s'
56 % image_show_fixture['id'],
57 json=image_show_fixture)
58 gc = client.Client(2.2, "http://example.com/v2.1")
59 img = gc.images.get(image_show_fixture['id'])
60 self.assertEqual(image_show_fixture['checksum'], img['checksum'])
61
62 def test_invalid_disk_format(self):
63 self.requests = self.useFixture(rm_fixture.Fixture())
64 self.requests.get('http://example.com/v2/schemas/image',
65 json=_BASE_SCHEMA)
66 self.requests.post('http://example.com/v2/images',
67 json=image_create_fixture)
68 self.requests.get('http://example.com/v2/images/%s'
69 % image_show_fixture['id'],
70 json=image_show_fixture)
71 gc = client.Client(2.2, "http://example.com/v2.1")
72 fields = {"disk_format": "qbull2"}
73 try:
74 gc.images.create(**fields)
75 self.fail("Failed to raise exception when using bad disk format")
76 except TypeError:
77 pass
78
79 def test_valid_disk_format(self):
80 self.requests = self.useFixture(rm_fixture.Fixture())
81 self.requests.get('http://example.com/v2/schemas/image',
82 json=_BASE_SCHEMA)
83 self.requests.post('http://example.com/v2/images',
84 json=image_create_fixture)
85 self.requests.get('http://example.com/v2/images/%s'
86 % image_show_fixture['id'],
87 json=image_show_fixture)
88 gc = client.Client(2.2, "http://example.com/v2.1")
89 fields = {"disk_format": "vhdx"}
90 gc.images.create(**fields)