Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rest] fix str check in content kwarg to be six.string_types check for 2.7 #21550

Merged
merged 5 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/rest/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _shared_set_content_body(content):
if isinstance(content, ET.Element):
# XML body
return set_xml_body(content)
if isinstance(content, (str, bytes)):
if isinstance(content, (six.string_types, bytes)):
headers = {}
body = content
if isinstance(content, six.string_types):
Expand Down
11 changes: 11 additions & 0 deletions sdk/core/azure-core/tests/test_rest_http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ def test_data_str_input():
assert len(request.headers) == 1
assert request.headers['Content-Type'] == 'application/x-www-form-urlencoded'

def test_content_str_input():
requests = [
HttpRequest("POST", "/fake", content="hello, world!"),
HttpRequest("POST", "/fake", content=u"hello, world!"),
]
for request in requests:
assert len(request.headers) == 2
assert request.headers["Content-Type"] == "text/plain"
assert request.headers["Content-Length"] == "13"
assert request.content == "hello, world!"

@pytest.mark.parametrize(("value"), (object(), {"key": "value"}))
def test_multipart_invalid_value(value):

Expand Down