Revision 97baa5c3 kamaki/clients/test.py
b/kamaki/clients/test.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from mock import patch, call |
|
34 | 35 |
from unittest import makeSuite, TestSuite, TextTestRunner, TestCase |
35 | 36 |
from time import sleep |
36 | 37 |
from inspect import getmembers, isclass |
37 |
from json import loads
|
|
38 |
from itertools import product
|
|
38 | 39 |
from random import randint |
39 | 40 |
|
40 | 41 |
from kamaki.clients.connection.test import ( |
... | ... | |
155 | 156 |
def __init__(self): |
156 | 157 |
pass |
157 | 158 |
|
159 |
def set_header(self, name, value): |
|
160 |
pass |
|
161 |
|
|
158 | 162 |
|
159 | 163 |
class FR(object): |
160 | 164 |
json = None |
... | ... | |
264 | 268 |
self.assertEqual('%s' % ce, '%s %s\n' % (sts_code or '', msg)) |
265 | 269 |
self.assertEqual(ce.status, sts_code or 0) |
266 | 270 |
|
271 |
@patch('%s.FakeConnection.set_header' % __name__) |
|
272 |
def test_set_header(self, SH): |
|
273 |
num_of_calls = 0 |
|
274 |
for name, value, condition in product( |
|
275 |
('n4m3', '', None), |
|
276 |
('v41u3', None, 42), |
|
277 |
(True, False, None, 1, '')): |
|
278 |
self.client.set_header(name, value, iff=condition) |
|
279 |
if value is not None and condition: |
|
280 |
self.assertEqual(SH.mock_calls[-1], call(name, value)) |
|
281 |
num_of_calls += 1 |
|
282 |
else: |
|
283 |
self.assertEqual(num_of_calls, len(SH.mock_calls)) |
|
284 |
|
|
267 | 285 |
|
268 | 286 |
# TestCase auxiliary methods |
269 | 287 |
|
Also available in: Unified diff