|
10 | 10 | from twilio.base.version import Version |
11 | 11 | from twilio.http.http_client import TwilioHttpClient |
12 | 12 | from twilio.http.response import Response |
| 13 | +from twilio.http.request import Request |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class TestHttpClientRequest(unittest.TestCase): |
@@ -293,6 +294,43 @@ def test_session_not_preserved(self): |
293 | 294 | self.assertEqual(response_2.content, "response_2") |
294 | 295 |
|
295 | 296 |
|
| 297 | +class TestTwilioRequest(unittest.TestCase): |
| 298 | + def test_str(self): |
| 299 | + |
| 300 | + req = Request( |
| 301 | + method="POST", |
| 302 | + url="https://api.twilio.com/2010-04-01/Accounts.json", |
| 303 | + auth=("AC123", "token"), |
| 304 | + params={"PageSize": "1"}, |
| 305 | + data={"FriendlyName": "My New Account"}, |
| 306 | + headers={"X-Custom-Header": "Value"}, |
| 307 | + ) |
| 308 | + expected = ( |
| 309 | + "POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n" |
| 310 | + ' -d "FriendlyName=My New Account"\n' |
| 311 | + ' -H "X-Custom-Header: Value"' |
| 312 | + ) |
| 313 | + self.assertEqual(expected, req.__str__()) |
| 314 | + |
| 315 | + def test_str_excludes_authorization_header(self): |
| 316 | + req = Request( |
| 317 | + method="POST", |
| 318 | + url="https://api.twilio.com/2010-04-01/Accounts.json", |
| 319 | + params={"PageSize": "1"}, |
| 320 | + data={"FriendlyName": "My New Account"}, |
| 321 | + headers={ |
| 322 | + "Authorization": "Bearer secret-token", |
| 323 | + "X-Custom-Header": "Value" |
| 324 | + }, |
| 325 | + ) |
| 326 | + expected = ( |
| 327 | + "POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n" |
| 328 | + ' -d "FriendlyName=My New Account"\n' |
| 329 | + ' -H "X-Custom-Header: Value"' |
| 330 | + ) |
| 331 | + self.assertEqual(expected, req.__str__()) |
| 332 | + |
| 333 | + |
296 | 334 | class MyVersion(Version): |
297 | 335 | def __init__(self, domain): |
298 | 336 | super().__init__(domain, "v1") |
|
0 commit comments