|
1
|
|
|
from unittest.mock import patch |
|
2
|
|
|
|
|
3
|
|
|
from mountapi.http import RequestData, Request, Response |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
@patch('werkzeug.wrappers.Request') |
|
7
|
|
|
def test_request_data_empty_request_params(wsgi_request_mock): |
|
8
|
|
|
wsgi_request_mock.values.to_dict.return_value = {} |
|
9
|
|
|
wsgi_request_mock.data = {} |
|
10
|
|
|
request_data = RequestData(wsgi_request_mock) |
|
11
|
|
|
assert request_data.params == {} |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
@patch('werkzeug.wrappers.Request') |
|
15
|
|
|
def test_request_data_get_request_params(wsgi_request_mock): |
|
16
|
|
|
wsgi_request_mock.values.to_dict.return_value = {'foo': 'bar'} |
|
17
|
|
|
wsgi_request_mock.data = {} |
|
18
|
|
|
request_data = RequestData(wsgi_request_mock) |
|
19
|
|
|
assert request_data.params == {'foo': 'bar'} |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
@patch('werkzeug.wrappers.Request') |
|
23
|
|
|
def test_request_data_post_request_params(wsgi_request_mock): |
|
24
|
|
|
wsgi_request_mock.values.to_dict.return_value = {} |
|
25
|
|
|
wsgi_request_mock.data = '{"foo": "bar"}' |
|
26
|
|
|
request_data = RequestData(wsgi_request_mock) |
|
27
|
|
|
assert request_data.params == {'foo': 'bar'} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
@patch('mountapi.http.RequestData') |
|
31
|
|
|
def test_request_empty_request_params_output(request_data_mock): |
|
32
|
|
|
def func(): |
|
33
|
|
|
return {'foo': 'bar'} |
|
34
|
|
|
|
|
35
|
|
|
request_data_mock.params = {} |
|
36
|
|
|
request = Request(request_data_mock, func) |
|
37
|
|
|
assert request.get_output() == {'foo': 'bar'} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
@patch('mountapi.http.RequestData') |
|
41
|
|
|
def test_request_non_empty_request_params_output(request_data_mock): |
|
42
|
|
|
def func(foo): |
|
43
|
|
|
return {'foo': foo} |
|
44
|
|
|
|
|
45
|
|
|
request_data_mock.params = {'foo': 'bar'} |
|
46
|
|
|
request = Request(request_data_mock, func) |
|
47
|
|
|
assert request.get_output() == {'foo': 'bar'} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
@patch('mountapi.http.Request') |
|
51
|
|
|
def test_response_empty_output_wsgi(request_mock): |
|
52
|
|
|
request_mock.get_output.return_value = {} |
|
53
|
|
|
response_wsgi = Response(request_mock).wsgi() |
|
54
|
|
|
assert response_wsgi.status_code == 200 |
|
55
|
|
|
assert response_wsgi.response == [b'{}'] |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
@patch('mountapi.http.Request') |
|
59
|
|
|
def test_response_non_empty_output_wsgi(request_mock): |
|
60
|
|
|
request_mock.get_output.return_value = {'foo': 'bar'} |
|
61
|
|
|
response_wsgi = Response(request_mock).wsgi() |
|
62
|
|
|
assert response_wsgi.status_code == 200 |
|
63
|
|
|
assert response_wsgi.response == [b'{"foo": "bar"}'] |
|
64
|
|
|
|