Revision f3cb8dad kamaki/clients/compute/test.py

b/kamaki/clients/compute/test.py
123 123
        FR.json = vm_recv
124 124

  
125 125
    @patch('%s.get' % rest_pkg, return_value=FR())
126
    def test_servers_get(self, get):
127
        vm_id = vm_recv['server']['id']
126
    def _test_get(self, service, get):
128 127
        for args in product(
129
                ('', vm_id),
128
                ('', '%s_id' % service),
130 129
                ('', 'cmd'),
131 130
                (200, 204),
132 131
                ({}, {'k': 'v'})):
133
            (server_id, command, success, kwargs) = args
134
            self.client.servers_get(*args[:3], **kwargs)
135
            vm_str = '/%s' % server_id if server_id else ''
132
            (srv_id, command, success, kwargs) = args
133
            method = getattr(self.client, '%s_get' % service)
134
            method(*args[:3], **kwargs)
135
            srv_str = '/%s' % srv_id if srv_id else ''
136 136
            cmd_str = '/%s' % command if command else ''
137 137
            self.assertEqual(get.mock_calls[-1], call(
138
                '/servers%s%s' % (vm_str, cmd_str),
138
                '/%s%s%s' % (service, srv_str, cmd_str),
139 139
                success=success,
140 140
                **kwargs))
141 141

  
142
    def test_servers_get(self):
143
        self._test_get('servers')
144

  
145
    def test_flavors_get(self):
146
        self._test_get('flavors')
147

  
148
    def test_images_get(self):
149
        self._test_get('images')
150

  
142 151
    @patch('%s.delete' % rest_pkg, return_value=FR())
143
    def test_servers_delete(self, delete):
144
        vm_id = vm_recv['server']['id']
152
    def _test_delete(self, service, delete):
145 153
        for args in product(
146
                ('', vm_id),
154
                ('', '%s_id' % service),
147 155
                ('', 'cmd'),
148 156
                (204, 208),
149 157
                ({}, {'k': 'v'})):
150
            (server_id, command, success, kwargs) = args
151
            self.client.servers_delete(*args[:3], **args[3])
152
            vm_str = '/%s' % server_id if server_id else ''
158
            (srv_id, command, success, kwargs) = args
159
            method = getattr(self.client, '%s_delete' % service)
160
            method(*args[:3], **kwargs)
161
            vm_str = '/%s' % srv_id if srv_id else ''
153 162
            cmd_str = '/%s' % command if command else ''
154 163
            self.assertEqual(delete.mock_calls[-1], call(
155
                '/servers%s%s' % (vm_str, cmd_str),
164
                '/%s%s%s' % (service, vm_str, cmd_str),
156 165
                success=success,
157 166
                **kwargs))
158 167

  
168
    def test_servers_delete(self):
169
        self._test_delete('servers')
170

  
171
    def test_images_delete(self):
172
        self._test_delete('images')
173

  
159 174
    @patch('%s.set_header' % rest_pkg)
160 175
    @patch('%s.post' % rest_pkg, return_value=FR())
161 176
    def test_servers_post(self, post, SH):
......
206 221
                data=json_data, success=success,
207 222
                **kwargs))
208 223

  
209
    @patch('%s.get' % rest_pkg, return_value=FR())
210
    def test_flavors_get(self, get):
211
        vm_id = vm_recv['server']['id']
212
        for args in product(
213
                ('', vm_id),
214
                ('', 'cmd'),
215
                (200, 204),
216
                ({}, {'k': 'v'})):
217
            (server_id, command, success, kwargs) = args
218
            self.client.flavors_get(*args[:3], **kwargs)
219
            vm_str = '/%s' % server_id if server_id else ''
220
            cmd_str = '/%s' % command if command else ''
221
            self.assertEqual(get.mock_calls[-1], call(
222
                '/flavors%s%s' % (vm_str, cmd_str),
223
                success=success,
224
                **kwargs))
225

  
226 224

  
227 225
class Compute(TestCase):
228 226

  

Also available in: Unified diff