Skip to content

Commit 25c5ebe

Browse files
authored
Merge pull request #1 from dahlia/fix-unicode-error-message
Exception message shouldn't be unicode on Python 2
2 parents e01fce8 + a5efd2e commit 25c5ebe

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CHANGES.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Changelog
44
Version 0.1.1
55
-------------
66

7-
To be released.
7+
- Fixed a bug that message of ``UnexpectedNirumResponseError`` was not a ``str``
8+
but ``unicode`` in Python 2.
89

910

1011
Version 0.1.0

nirum_http.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ def call(self,
4545
try:
4646
content = response.json()
4747
except ValueError:
48-
raise UnexpectedNirumResponseError(response.text)
48+
raise UnexpectedNirumResponseError(
49+
response.content if isinstance('', bytes) else response.text
50+
)
4951
return response.ok, content

test.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from pytest import fixture
1+
from pytest import fixture, raises
22
from requests import Session
33
from requests_mock import Adapter
44

5-
from nirum_http import HttpTransport
5+
from nirum_http import HttpTransport, UnexpectedNirumResponseError
66

77

88
@fixture
@@ -34,3 +34,21 @@ def callback(request, context):
3434
)
3535
assert successful
3636
assert result == {'_type': 'point', 'x': 1.0, 'top': 2.0}
37+
38+
39+
def test_unexpected_nirum_response_error(fx_adapter, fx_session):
40+
method_name = 'hello_world'
41+
base_url = 'http://example.com/'
42+
url = '{0}?method={1}'.format(base_url, method_name)
43+
fx_adapter.register_uri('POST', url, text='Error message')
44+
t = HttpTransport(base_url, session=fx_session)
45+
with raises(UnexpectedNirumResponseError) as exc_info:
46+
t.call(
47+
method_name, payload={'name': 'John'},
48+
service_annotations={},
49+
method_annotations={},
50+
parameter_annotations={}
51+
)
52+
exc = exc_info.value
53+
assert exc.args == ('Error message',)
54+
assert isinstance(exc.args[0], str)

0 commit comments

Comments
 (0)