Revision a8fe029d kamaki/clients/compute/test.py

b/kamaki/clients/compute/test.py
173 173

  
174 174
    @patch('%s.set_header' % rest_pkg)
175 175
    @patch('%s.post' % rest_pkg, return_value=FR())
176
    def test_servers_post(self, post, SH):
177
        vm_id = vm_recv['server']['id']
176
    def _test_post(self, service, post, SH):
178 177
        for args in product(
179
                ('', vm_id),
178
                ('', '%s_id' % service),
180 179
                ('', 'cmd'),
181 180
                (None, [dict(json="data"), dict(data="json")]),
182 181
                (202, 204),
183 182
                ({}, {'k': 'v'})):
184
            (server_id, command, json_data, success, kwargs) = args
185

  
186
            self.client.servers_post(*args[:4], **kwargs)
187
            vm_str = '/%s' % server_id if server_id else ''
183
            (srv_id, command, json_data, success, kwargs) = args
184
            method = getattr(self.client, '%s_post' % service)
185
            method(*args[:4], **kwargs)
186
            vm_str = '/%s' % srv_id if srv_id else ''
188 187
            cmd_str = '/%s' % command if command else ''
189 188
            if json_data:
190 189
                json_data = dumps(json_data)
......
192 191
                    call('Content-Type', 'application/json'),
193 192
                    call('Content-Length', len(json_data))])
194 193
            self.assertEqual(post.mock_calls[-1], call(
195
                '/servers%s%s' % (vm_str, cmd_str),
194
                '/%s%s%s' % (service, vm_str, cmd_str),
196 195
                data=json_data, success=success,
197 196
                **kwargs))
198 197

  
198
    def test_servers_post(self):
199
        self._test_post('servers')
200

  
201
    def test_images_post(self):
202
        self._test_post('images')
203

  
199 204
    @patch('%s.set_header' % rest_pkg)
200 205
    @patch('%s.put' % rest_pkg, return_value=FR())
201
    def test_servers_put(self, put, SH):
202
        vm_id = vm_recv['server']['id']
206
    def _test_put(self, service, put, SH):
203 207
        for args in product(
204
                ('', vm_id),
208
                ('', '%s_id' % service),
205 209
                ('', 'cmd'),
206 210
                (None, [dict(json="data"), dict(data="json")]),
207 211
                (204, 504),
208 212
                ({}, {'k': 'v'})):
209 213
            (server_id, command, json_data, success, kwargs) = args
210

  
211
            self.client.servers_put(*args[:4], **kwargs)
214
            method = getattr(self.client, '%s_put' % service)
215
            method(*args[:4], **kwargs)
212 216
            vm_str = '/%s' % server_id if server_id else ''
213 217
            cmd_str = '/%s' % command if command else ''
214 218
            if json_data:
......
217 221
                    call('Content-Type', 'application/json'),
218 222
                    call('Content-Length', len(json_data))])
219 223
            self.assertEqual(put.mock_calls[-1], call(
220
                '/servers%s%s' % (vm_str, cmd_str),
224
                '/%s%s%s' % (service, vm_str, cmd_str),
221 225
                data=json_data, success=success,
222 226
                **kwargs))
223 227

  
228
    def test_servers_put(self):
229
        self._test_put('servers')
230

  
231
    def test_images_put(self):
232
        self._test_put('images')
233

  
224 234

  
225 235
class Compute(TestCase):
226 236

  

Also available in: Unified diff