|
1 |
| -from pytest import fixture |
| 1 | +from pytest import fixture, raises |
2 | 2 | from requests import Session
|
3 | 3 | from requests_mock import Adapter
|
4 | 4 |
|
5 |
| -from nirum_http import HttpTransport |
| 5 | +from nirum_http import HttpTransport, UnexpectedNirumResponseError |
6 | 6 |
|
7 | 7 |
|
8 | 8 | @fixture
|
@@ -34,3 +34,21 @@ def callback(request, context):
|
34 | 34 | )
|
35 | 35 | assert successful
|
36 | 36 | 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