Revision 447365fe kamaki/clients/network/test.py

b/kamaki/clients/network/test.py
146 146
                'ret val')
147 147
            self._assert(get, '/ports/%s' % port_id, **kwargs)
148 148

  
149
    @patch('kamaki.clients.Client.set_param')
150 149
    @patch('kamaki.clients.Client.post', return_value='ret val')
151
    def test_ports_post(self, post, set_param):
152
        for params, kwargs in product(
153
                [p for p in product(
154
                    (
155
                        ('name', 'port name', 'port name'),
156
                        ('name', None, None)),
157
                    (
158
                        ('mac_address', 'max address', 'max address'),
159
                        ('mac_address', None, None)),
160
                    (
161
                        ('fixed_ips', 'fixed ip', 'fixed ip'),
162
                        ('fixed_ips', None, None)),
163
                    (
164
                        ('security_groups', 'sec groups', 'sec groups'),
165
                        ('security_groups', None, None))
166
                )],
167
                (dict(), dict(k1='v1'), dict(k2='v2', k3='v3'))):
168

  
169
            callargs = dict()
170
            for p in params:
171
                callargs[p[0]] = p[2]
172
            callargs.update(kwargs)
173

  
174
            self.assertEqual(self.client.ports_post(**callargs), 'ret val')
175
            self._assert(
176
                post, '/ports', set_param, params=params, json=None, **kwargs)
150
    def test_ports_post(self, post):
151
        for kwargs in (dict(), dict(k1='v1'), dict(k2='v2', k3='v3')):
152
            self.assertEqual(self.client.ports_post(**kwargs), 'ret val')
153
            self._assert(post, '/ports', json=None, **kwargs)
177 154

  
178 155
            json_data = dict(id='some id', other_param='other val')
179
            callargs['json_data'] = json_data
180
            self.assertEqual(self.client.ports_post(**callargs), 'ret val')
181
            self._assert(
182
                post, '/ports', set_param, params,
183
                json=json_data, **kwargs)
156
            self.assertEqual(
157
                self.client.ports_post(json_data=json_data, **kwargs),
158
                'ret val')
159
            self._assert(post, '/ports', json=json_data, **kwargs)
184 160

  
185
    @patch('kamaki.clients.Client.set_param')
186 161
    @patch('kamaki.clients.Client.put', return_value='ret val')
187
    def test_ports_put(self, put, set_param):
162
    def test_ports_put(self, put):
188 163
        port_id = 'portid'
189
        for params, kwargs in product(
190
                [p for p in product(
191
                    (
192
                        ('name', 'port name', 'port name'),
193
                        ('name', None, None)),
194
                    (
195
                        ('mac_address', 'max address', 'max address'),
196
                        ('mac_address', None, None)),
197
                    (
198
                        ('fixed_ips', 'fixed ip', 'fixed ip'),
199
                        ('fixed_ips', None, None)),
200
                    (
201
                        ('security_groups', 'sec groups', 'sec groups'),
202
                        ('security_groups', None, None))
203
                )],
204
                (dict(), dict(k1='v1'), dict(k2='v2', k3='v3'))):
205

  
206
            callargs = dict()
207
            for p in params:
208
                callargs[p[0]] = p[2]
209
            callargs.update(kwargs)
210

  
164
        for kwargs in (dict(), dict(k1='v1'), dict(k2='v2', k3='v3')):
211 165
            self.assertEqual(
212
                self.client.ports_put(port_id, **callargs), 'ret val')
213
            self._assert(
214
                put, '/ports/%s' % port_id, set_param,
215
                params=params, json=None, **kwargs)
166
                self.client.ports_put(port_id, **kwargs), 'ret val')
167
            self._assert(put, '/ports/%s' % port_id, json=None, **kwargs)
216 168

  
217 169
            json_data = dict(id='some id', other_param='other val')
218
            callargs['json_data'] = json_data
219 170
            self.assertEqual(
220
                self.client.ports_put(port_id, **callargs), 'ret val')
221
            self._assert(
222
                put, '/ports/%s' % port_id, set_param, params,
223
                json=json_data, **kwargs)
171
                self.client.ports_put(port_id, json_data=json_data, **kwargs),
172
                'ret val')
173
            self._assert(put, '/ports/%s' % port_id, json=json_data, **kwargs)
224 174

  
225 175

  
226 176
class FakeObject(object):
......
517 467
        self.assertEqual(self.client.delete_port(portid), 'ret headers')
518 468
        ports_delete.assert_called_once_with(portid, success=204)
519 469

  
470
    @patch(
471
        'kamaki.clients.network.NetworkClient.ports_put',
472
        return_value=FakeObject())
473
    def test_update_port(self, ports_put):
474
        for (
475
                name, status, admin_state_up, mac_address, fixed_ips,
476
                security_groups) in product(
477
                    ('name', None), ('st', None), (True, None), ('mc', None),
478
                    ('fps', None), ('sg', None)):
479
            FakeObject.json = dict(port='rv')
480
            port_id, network_id = 'pid', 'nid'
481
            kwargs = dict(
482
                network_id=network_id, name=name, status=status,
483
                admin_state_up=admin_state_up, mac_address=mac_address,
484
                fixed_ips=fixed_ips, security_groups=security_groups)
485
            self.assertEqual(
486
                self.client.update_port(port_id, **kwargs), 'rv')
487
            req = dict()
488
            for k, v in kwargs.items():
489
                if v:
490
                    req[k] = v
491
            expargs = dict(json_data=dict(port=req), success=201)
492
            self.assertEqual(
493
                ports_put.mock_calls[-1], call(port_id, **expargs))
494

  
520 495

  
521 496
if __name__ == '__main__':
522 497
    from sys import argv

Also available in: Unified diff