| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 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 |
|
| 51 |
|
| 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) |