|
1 | 1 | # -*- coding: utf-8 -*-
|
2 |
| - |
3 | 2 | import six
|
4 | 3 |
|
5 | 4 | import unittest
|
6 | 5 |
|
7 |
| -import mock |
8 | 6 | from mock import patch, Mock
|
9 |
| -from requests import Request |
10 |
| -from requests import Session |
| 7 | +from requests import Request, Session |
11 | 8 |
|
12 | 9 | from twilio.http.http_client import TwilioHttpClient
|
13 | 10 | from twilio.http.response import Response
|
@@ -42,6 +39,61 @@ def test_request_sets_host_header_if_missing(self):
|
42 | 39 | self.assertIsNotNone(self.client.last_request)
|
43 | 40 | self.assertIsNotNone(self.client.last_response)
|
44 | 41 |
|
| 42 | + def test_request_with_timeout(self): |
| 43 | + self.request_mock.url = 'https://api.twilio.com/' |
| 44 | + self.request_mock.headers = {'Host': 'other.twilio.com'} |
| 45 | + |
| 46 | + response = self.client.request( |
| 47 | + 'doesnt matter', 'doesnt matter', None, None, None, None, 30, None) |
| 48 | + |
| 49 | + self.assertEqual('other.twilio.com', self.request_mock.headers['Host']) |
| 50 | + self.assertEqual(200, response.status_code) |
| 51 | + self.assertEqual('testing-unicode: Ω≈ç√, 💩', response.content) |
| 52 | + |
| 53 | + def test_request_where_method_timeout_equals_zero(self): |
| 54 | + self.request_mock.url = 'https://api.twilio.com/' |
| 55 | + self.request_mock.headers = {'Host': 'other.twilio.com'} |
| 56 | + |
| 57 | + try: |
| 58 | + self.client.request( |
| 59 | + 'doesnt matter', 'doesnt matter', None, None, None, None, 0, None) |
| 60 | + except Exception as e: |
| 61 | + self.assertEqual(ValueError, type(e)) |
| 62 | + |
| 63 | + def test_request_where_class_timeout_manually_set(self): |
| 64 | + self.request_mock.url = 'https://api.twilio.com/' |
| 65 | + self.request_mock.headers = {'Host': 'other.twilio.com'} |
| 66 | + self.client.timeout = 30 |
| 67 | + |
| 68 | + response = self.client.request( |
| 69 | + 'doesnt matter', 'doesnt matter') |
| 70 | + self.assertEqual('other.twilio.com', self.request_mock.headers['Host']) |
| 71 | + self.assertEqual(200, response.status_code) |
| 72 | + self.assertEqual('testing-unicode: Ω≈ç√, 💩', response.content) |
| 73 | + |
| 74 | + def test_request_where_class_timeout_equals_zero(self): |
| 75 | + self.request_mock.url = 'https://api.twilio.com/' |
| 76 | + self.request_mock.headers = {'Host': 'other.twilio.com'} |
| 77 | + self.client.timeout = 0 |
| 78 | + |
| 79 | + try: |
| 80 | + self.client.request( |
| 81 | + 'doesnt matter', 'doesnt matter') |
| 82 | + except Exception as e: |
| 83 | + self.assertEqual(type(e), ValueError) |
| 84 | + |
| 85 | + def test_request_where_class_timeout_and_method_timeout_set(self): |
| 86 | + self.request_mock.url = 'https://api.twilio.com/' |
| 87 | + self.request_mock.headers = {'Host': 'other.twilio.com'} |
| 88 | + self.client.timeout = 30 |
| 89 | + |
| 90 | + response = self.client.request( |
| 91 | + 'doesnt matter', 'doesnt matter', None, None, None, None, 15, None) |
| 92 | + |
| 93 | + self.assertEqual('other.twilio.com', self.request_mock.headers['Host']) |
| 94 | + self.assertEqual(200, response.status_code) |
| 95 | + self.assertEqual('testing-unicode: Ω≈ç√, 💩', response.content) |
| 96 | + |
45 | 97 | def test_request_with_unicode_response(self):
|
46 | 98 | self.request_mock.url = 'https://api.twilio.com/'
|
47 | 99 | self.request_mock.headers = {'Host': 'other.twilio.com'}
|
|
0 commit comments