Skip to content

Commit

Permalink
update to no longer encode to utf-8; include tests indicating why
Browse files Browse the repository at this point in the history
  • Loading branch information
p5k6 committed Oct 21, 2020
1 parent ff3bc04 commit d67d7ed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.6
3.8.5
2 changes: 1 addition & 1 deletion awscurl/awscurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def inner_main(argv):

if args.include or IS_VERBOSE:
print(response.headers, end='\n\n')
print(response.text.encode('utf-8'))
print(response.text)

response.raise_for_status()

Expand Down
35 changes: 35 additions & 0 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from awscurl.awscurl import make_request

from requests.exceptions import SSLError
from requests import Response

import pytest
__author__ = 'iokulist'
Expand Down Expand Up @@ -271,3 +272,37 @@ def test_make_request(self, *args, **kvargs):
self.assertEqual(expected, headers)

pass

class TestRequestResponse(TestCase):
maxDiff = None

@patch('awscurl.awscurl.__send_request')
def test_make_request(self, mocked_resp):
resp = Response()
resp.status_code=200
resp._content= b'{"file_name": "test.yml", "env": "staging", "hash": "\xe5\xad\x97"}'
resp.encoding= 'UTF-8'
mocked_resp.return_value = resp

headers = {}
params = {'method': 'GET',
'service': 'ec2',
'region': 'region',
'uri': 'https://user:pass@host:123/path/?a=b&c=d',
'headers': headers,
'data': b'C\xcfI\x91\xc1\xd0\tw<\xa8\x13\x06{=\x9b\xb3\x1c\xfcl\xfe\xb9\xb18zS\xf4%i*Q\xc9v',
'access_key': '',
'secret_key': '',
'security_token': '',
'data_binary': True}
r = make_request(**params)

expected = u'字'

### assert that the unicode character is in the response.text output
self.assertTrue(expected in r.text)

### assert that the unicode character is _not_ in the response.text which has been converted to bytes
self.assertFalse(expected in str(r.text.encode('utf-8')))

pass

0 comments on commit d67d7ed

Please sign in to comment.