|
21 | 21 | post_headers = get_headers.copy()
|
22 | 22 | post_headers["Content-Type"] = "application/x-www-form-urlencoded"
|
23 | 23 |
|
24 |
| -def test_get_params(): |
25 |
| - tests = [ |
26 |
| - ("http://httpbin.org/get", {"hey":"you", "foo":"bar"}), |
27 |
| - ("http://httpbin.org/get?hey=you", {"foo":"bar"}), |
28 |
| - ("http://httpbin.org/get?hey=you&foo=bar", {}), |
29 |
| - ] |
30 |
| - |
31 |
| - for test in tests: |
32 |
| - yield check_get_params, test[0], test[1] |
33 |
| - |
34 |
| -def check_get_params(url, params): |
35 |
| - resp = make_request("GET", url, params=params) |
36 |
| - body = json.loads(resp.content) |
37 |
| - |
38 |
| - assert_equals(body["args"]["hey"], "you") |
39 |
| - assert_equals(body["args"]["foo"], "bar") |
40 |
| - |
41 |
| -def test_resp_uri(): |
42 |
| - resp = make_request("GET", "http://httpbin.org/get") |
43 |
| - assert_equals(resp.url, "http://httpbin.org/get") |
| 24 | + |
| 25 | +@patch('twilio.rest.resources.Response') |
| 26 | +@patch('httplib2.Http') |
| 27 | +def test_get_params(http_mock, response_mock): |
| 28 | + http = Mock() |
| 29 | + http.request.return_value = (Mock(), Mock()) |
| 30 | + http_mock.return_value = http |
| 31 | + make_request("GET", "http://httpbin.org/get", params={"hey": "you"}) |
| 32 | + http.request.assert_called_with("http://httpbin.org/get?hey=you", "GET", |
| 33 | + body=None, headers=None) |
| 34 | + |
| 35 | + |
| 36 | +@patch('twilio.rest.resources.Response') |
| 37 | +@patch('httplib2.Http') |
| 38 | +def test_get_extra_paranms(http_mock, response_mock): |
| 39 | + http = Mock() |
| 40 | + http.request.return_value = (Mock(), Mock()) |
| 41 | + http_mock.return_value = http |
| 42 | + make_request("GET", "http://httpbin.org/get?foo=bar", params={"hey": "you"}) |
| 43 | + http.request.assert_called_with("http://httpbin.org/get?foo=bar&hey=you", "GET", |
| 44 | + body=None, headers=None) |
| 45 | + |
| 46 | + |
| 47 | +@patch('twilio.rest.resources.Response') |
| 48 | +@patch('httplib2.Http') |
| 49 | +def test_resp_uri(http_mock, response_mock): |
| 50 | + http = Mock() |
| 51 | + http.request.return_value = (Mock(), Mock()) |
| 52 | + http_mock.return_value = http |
| 53 | + make_request("GET", "http://httpbin.org/get") |
| 54 | + http.request.assert_called_with("http://httpbin.org/get", "GET", |
| 55 | + body=None, headers=None) |
| 56 | + |
44 | 57 |
|
45 | 58 | @patch('twilio.rest.resources.make_request')
|
46 | 59 | def test_make_twilio_request_headers(mock):
|
|
0 commit comments