Revision 68fd1bda kamaki/clients/cyclades/test.py

b/kamaki/clients/cyclades/test.py
32 32
# or implied, of GRNET S.A.
33 33
from mock import patch, call
34 34
from unittest import TestCase
35
from itertools import product
35 36

  
36 37
from kamaki.clients import ClientError
37
from kamaki.clients.cyclades import CycladesClient
38
from kamaki.clients.cyclades import CycladesClient, CycladesClientApi
38 39

  
39 40
img_ref = "1m4g3-r3f3r3nc3"
40 41
vm_name = "my new VM"
......
89 90
    def release(self):
90 91
        pass
91 92

  
93
rest_pkg = 'kamaki.clients.cyclades.CycladesClientApi'
92 94
cyclades_pkg = 'kamaki.clients.cyclades.CycladesClient'
93 95

  
94 96

  
97
class CycladesRestApi(TestCase):
98

  
99
    """Set up a Cyclades thorough test"""
100
    def setUp(self):
101
        self.url = 'http://cyclades.example.com'
102
        self.token = 'cyc14d3s70k3n'
103
        self.client = CycladesClientApi(self.url, self.token)
104

  
105
    def tearDown(self):
106
        FR.json = vm_recv
107

  
108
    @patch('%s.set_param' % rest_pkg)
109
    @patch('%s.get' % rest_pkg, return_value=FR())
110
    def _test_get(self, service, get, SP):
111
        for args in product(
112
                ('', '%s_id' % service),
113
                ('', 'cmd'),
114
                (200, 204),
115
                (None, '50m3-d473'),
116
                ({}, {'k': 'v'})):
117
            (srv_id, command, success, changes_since, kwargs) = args
118
            method = getattr(self.client, '%s_get' % service)
119
            method(*args[:4], **kwargs)
120
            srv_str = '/%s' % srv_id if srv_id else ''
121
            cmd_str = '/%s' % command if command else ''
122
            self.assertEqual(get.mock_calls[-1], call(
123
                '/%s%s%s' % (service, srv_str, cmd_str),
124
                success=success,
125
                **kwargs))
126
            if changes_since:
127
                self.assertEqual(
128
                    SP.mock_calls[-1],
129
                    call('changes-since', changes_since, changes_since))
130

  
131
    def test_servers_get(self):
132
        self._test_get('servers')
133

  
134

  
95 135
class Cyclades(TestCase):
96 136

  
97 137
    def assert_dicts_are_equal(self, d1, d2):
......
320 360
                self.assertEqual(err.details, [
321 361
                    'Network may be still connected to at least one server'])
322 362

  
363

  
323 364
if __name__ == '__main__':
324 365
    from sys import argv
325 366
    from kamaki.clients.test import runTestCase
326
    runTestCase(Cyclades, 'Cyclades (multi) Client', argv[1:])
367
    not_found = True
368
    if not argv[1:] or argv[1] == 'Cyclades':
369
        not_found = False
370
        runTestCase(Cyclades, 'Cyclades Client', argv[2:])
371
    if not argv[1:] or argv[1] == 'CycladesRestApi':
372
        not_found = False
373
        runTestCase(CycladesRestApi, 'CycladesRestApi Client', argv[2:])
374
    if not_found:
375
        print('TestCase %s not found' % argv[1])

Also available in: Unified diff