Revision 77d1b504 kamaki/clients/cyclades/test.py

b/kamaki/clients/cyclades/test.py
34 34
from mock import patch, call
35 35
from unittest import TestCase
36 36
from itertools import product
37
from json import dumps
37 38

  
38 39
from kamaki.clients import ClientError, cyclades
39 40

  
......
215 216
            self.assertEqual(get.mock_calls[-1], call(
216 217
                '/os-floating-ip-pools', success=success, **kwargs))
217 218

  
219
    @patch('%s.get' % rest_pkg, return_value=FR())
220
    def test_floating_ips_get(self, get):
221
        for args in product(
222
                (200, 204),
223
                ({}, {'k': 'v'})):
224
            success, kwargs = args
225
            r = self.client.floating_ips_get(success, **kwargs)
226
            self.assertTrue(isinstance(r, FR))
227
            self.assertEqual(get.mock_calls[-1], call(
228
                '/os-floating-ips', success=success, **kwargs))
229

  
230
    @patch('%s.set_header' % rest_pkg)
231
    @patch('%s.post' % rest_pkg, return_value=FR())
232
    def test_floating_ips_post(self, post, SH):
233
        for args in product(
234
                (None, [dict(json="data"), dict(data="json")]),
235
                (202, 204),
236
                ({}, {'k': 'v'})):
237
            (json_data, success, kwargs) = args
238
            self.client.floating_ips_post(*args[:2], **kwargs)
239
            if json_data:
240
                json_data = dumps(json_data)
241
                self.assertEqual(SH.mock_calls[-2:], [
242
                    call('Content-Type', 'application/json'),
243
                    call('Content-Length', len(json_data))])
244
            self.assertEqual(post.mock_calls[-1], call(
245
                '/os-floating-ips',
246
                data=json_data, success=success,
247
                **kwargs))
248

  
249
    @patch('%s.get' % rest_pkg, return_value=FR())
250
    def test_floating_ip_get(self, get):
251
        for args in product(
252
                ('fip1', 'fip2'),
253
                (200, 204),
254
                ({}, {'k': 'v'})):
255
            fip, success, kwargs = args
256
            r = self.client.floating_ip_get(fip, success, **kwargs)
257
            self.assertTrue(isinstance(r, FR))
258
            self.assertEqual(get.mock_calls[-1], call(
259
                '/os-floating-ip/%s' % fip, success=success, **kwargs))
260

  
261
    @patch('%s.delete' % rest_pkg, return_value=FR())
262
    def test_floating_ip_delete(self, delete):
263
        for args in product(
264
                ('fip1', 'fip2'),
265
                (200, 204),
266
                ({}, {'k': 'v'})):
267
            fip, success, kwargs = args
268
            r = self.client.floating_ip_delete(fip, success, **kwargs)
269
            self.assertTrue(isinstance(r, FR))
270
            self.assertEqual(delete.mock_calls[-1], call(
271
                '/os-floating-ip/%s' % fip, success=success, **kwargs))
272

  
218 273

  
219 274
class CycladesClient(TestCase):
220 275

  

Also available in: Unified diff