~ubuntu-branches/ubuntu/raring/python-glanceclient/raring-proposed

« back to all changes in this revision

Viewing changes to tests/v1/utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-29 08:34:09 UTC
  • Revision ID: package-import@ubuntu.com-20120529083409-42y5dlpvwd94521t
Tags: upstream-2012.2~f1
ImportĀ upstreamĀ versionĀ 2012.2~f1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import json
 
17
 
 
18
 
 
19
fixtures = {
 
20
    '/v1/images': {
 
21
        'POST': (
 
22
            {
 
23
                'location': '/v1/images/1',
 
24
            },
 
25
            json.dumps(
 
26
                {'image': {
 
27
                    'id': '1',
 
28
                    'name': 'image-1',
 
29
                    'container_format': 'ovf',
 
30
                    'disk_format': 'vhd',
 
31
                    'owner': 'asdf',
 
32
                    'size': '1024',
 
33
                    'min_ram': '512',
 
34
                    'min_disk': '10',
 
35
                    'properties': {'a': 'b', 'c': 'd'},
 
36
                }},
 
37
            ),
 
38
        ),
 
39
    },
 
40
    '/v1/images/detail': {
 
41
        'GET': (
 
42
            {},
 
43
            {'images': [
 
44
                {
 
45
                    'id': '1',
 
46
                    'name': 'image-1',
 
47
                    'properties': {'arch': 'x86_64'},
 
48
                },
 
49
            ]},
 
50
        ),
 
51
    },
 
52
    '/v1/images/1': {
 
53
        'HEAD': (
 
54
            {
 
55
                'x-image-meta-id': '1',
 
56
                'x-image-meta-name': 'image-1',
 
57
                'x-image-meta-property-arch': 'x86_64',
 
58
            },
 
59
            None),
 
60
        'PUT': (
 
61
            {},
 
62
            json.dumps(
 
63
                {'image': {
 
64
                    'id': '1',
 
65
                    'name': 'image-2',
 
66
                    'container_format': 'ovf',
 
67
                    'disk_format': 'vhd',
 
68
                    'owner': 'asdf',
 
69
                    'size': '1024',
 
70
                    'min_ram': '512',
 
71
                    'min_disk': '10',
 
72
                    'properties': {'a': 'b', 'c': 'd'},
 
73
                }},
 
74
            ),
 
75
        ),
 
76
        'DELETE': ({}, None),
 
77
    },
 
78
    '/v1/images/1/members': {
 
79
        'GET': (
 
80
            {},
 
81
            {'members': [
 
82
                {'member_id': '1', 'can_share': False},
 
83
            ]},
 
84
        ),
 
85
        'PUT': ({}, None),
 
86
    },
 
87
    '/v1/images/1/members/1': {
 
88
        'GET': (
 
89
            {},
 
90
            {'member': {
 
91
                'member_id': '1',
 
92
                'can_share': False,
 
93
            }},
 
94
        ),
 
95
        'PUT': ({}, None),
 
96
        'DELETE': ({}, None),
 
97
    },
 
98
    '/v1/shared-images/1': {
 
99
        'GET': (
 
100
            {},
 
101
            {'shared_images': [
 
102
                {'image_id': '1', 'can_share': False},
 
103
            ]},
 
104
        ),
 
105
    },
 
106
}
 
107
 
 
108
 
 
109
class FakeAPI(object):
 
110
 
 
111
    def __init__(self):
 
112
        self.calls = []
 
113
 
 
114
    def _request(self, method, url, headers=None, body=None):
 
115
        call = (method, url, headers or {}, body)
 
116
        self.calls.append(call)
 
117
        # drop any query params
 
118
        url = url.split('?', 1)[0]
 
119
        return fixtures[url][method]
 
120
 
 
121
    def raw_request(self, *args, **kwargs):
 
122
        return self._request(*args, **kwargs)
 
123
 
 
124
    def json_request(self, *args, **kwargs):
 
125
        return self._request(*args, **kwargs)