Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/unit/http/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from twilio.base.version import Version
from twilio.http.http_client import TwilioHttpClient
from twilio.http.response import Response
from twilio.http.request import Request


class TestHttpClientRequest(unittest.TestCase):
Expand Down Expand Up @@ -293,6 +294,25 @@ def test_session_not_preserved(self):
self.assertEqual(response_2.content, "response_2")


class TestTwilioRequest(unittest.TestCase):
def test_str(self):

req = Request(
method="POST",
url="https://api.twilio.com/2010-04-01/Accounts.json",
auth=("AC123", "token"),
params={"PageSize": "1"},
data={"FriendlyName": "My New Account"},
headers={"X-Custom-Header": "Value"},
)
expected = (
"POST https://api.twilio.com/2010-04-01/Accounts.json?PageSize=1\n"
" -d \"FriendlyName=My New Account\"\n"
" -H \"X-Custom-Header: Value\""
)
self.assertEqual(expected, req.__str__())
Copy link
Contributor

@sbansla sbansla Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a check that Authorization is not expected. Although on a second thought this should also work.



class MyVersion(Version):
def __init__(self, domain):
super().__init__(domain, "v1")
Expand Down
7 changes: 1 addition & 6 deletions twilio/http/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def __eq__(self, other) -> bool:
)

def __str__(self) -> str:
auth = ""
if self.auth and self.auth != Match.ANY:
auth = "{} ".format(self.auth)

params = ""
if self.params and self.params != Match.ANY:
params = "?{}".format(urlencode(self.params, doseq=True))
Expand All @@ -78,8 +74,7 @@ def __str__(self) -> str:
"\n".join(' -H "{}: {}"'.format(k, v) for k, v in self.headers.items())
)

return "{auth}{method} {url}{params}{data}{headers}".format(
auth=auth,
return "{method} {url}{params}{data}{headers}".format(
method=self.method,
url=self.url,
params=params,
Expand Down
Loading