0004-toulouse_smart-allow-several-queries-in-mock_respons.patch
tests/test_toulouse_smart.py | ||
---|---|---|
42 | 42 |
basic_auth_password='password', |
43 | 43 |
) |
44 | 44 | |
45 | 45 | |
46 | 46 |
def mock_response(*path_contents): |
47 | 47 |
def decorator(func): |
48 | 48 |
@httmock.urlmatch() |
49 | 49 |
def error(url, request): |
50 |
assert False, 'request to %s' % (url,) |
|
50 |
assert False, 'request to %s' % url.geturl() |
|
51 | ||
52 |
def register(path, content, status_code=200): |
|
53 |
@httmock.urlmatch(path=path) |
|
54 |
def handler(url, request): |
|
55 |
return httmock.response(status_code, content) |
|
56 | ||
57 |
return handler |
|
51 | 58 | |
52 | 59 |
@functools.wraps(func) |
53 | 60 |
def wrapper(*args, **kwargs): |
54 | 61 |
handlers = [] |
55 | 62 |
for row in path_contents: |
56 |
path, content = row[:2] |
|
57 |
if len(row) == 3: |
|
58 |
status_code = row[2] |
|
59 |
else: |
|
60 |
status_code = 200 |
|
61 | ||
62 |
@httmock.urlmatch(path=path) |
|
63 |
def handler(url, request): |
|
64 |
return httmock.response(status_code, content) |
|
65 | ||
66 |
handlers.append(handler) |
|
63 |
handlers.append(register(*row)) |
|
67 | 64 |
handlers.append(error) |
68 | 65 | |
69 | 66 |
with httmock.HTTMock(*handlers): |
70 | 67 |
return func(*args, **kwargs) |
71 | 68 | |
72 | 69 |
return wrapper |
73 | 70 | |
74 | 71 |
return decorator |
75 |
- |