|
4 | 4 | Uses the awesome httpbin.org to validate responses
|
5 | 5 | """
|
6 | 6 | import twilio
|
7 |
| -from nose.tools import raises |
8 |
| -from mock import patch, Mock |
| 7 | +from nose.tools import assert_equal, raises |
| 8 | +from mock import patch, Mock, ANY |
9 | 9 | from twilio import TwilioRestException
|
10 | 10 | from twilio.rest.resources.base import make_request, make_twilio_request
|
| 11 | +from twilio.rest.resources.connection import Connection |
11 | 12 |
|
12 | 13 | get_headers = {
|
13 | 14 | "User-Agent": "twilio-python/%s" % (twilio.__version__),
|
@@ -90,3 +91,19 @@ def test_make_twilio_request_bad_data(mock):
|
90 | 91 | make_twilio_request("POST", url)
|
91 | 92 | mock.assert_called_with("POST", "http://random/url.json",
|
92 | 93 | headers=post_headers)
|
| 94 | + |
| 95 | + |
| 96 | +@patch('twilio.rest.resources.base.Response') |
| 97 | +@patch('httplib2.Http') |
| 98 | +def test_proxy_info(http_mock, resp_mock): |
| 99 | + http = Mock() |
| 100 | + http.request.return_value = (Mock(), Mock()) |
| 101 | + http_mock.return_value = http |
| 102 | + Connection.set_proxy_info('http://example.com/proxy', '8080') |
| 103 | + make_request("GET", "http://httpbin.org/get") |
| 104 | + http_mock.assert_called_with(timeout=None, ca_certs=ANY, proxy_info=ANY) |
| 105 | + http.request.assert_called_with("http://httpbin.org/get", "GET", |
| 106 | + body=None, headers=None) |
| 107 | + proxy_info = http_mock.call_args[1]['proxy_info'] |
| 108 | + assert_equal(proxy_info.proxy_host, 'http://example.com/proxy') |
| 109 | + assert_equal(proxy_info.proxy_port, '8080') |
0 commit comments