-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.py
54 lines (45 loc) · 1.61 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from pytest import fixture, raises
from requests import Session
from requests_mock import Adapter
from nirum_http import HttpTransport, UnexpectedNirumResponseError
@fixture
def fx_adapter():
return Adapter()
@fixture
def fx_session(fx_adapter):
s = Session()
s.mount('http://', fx_adapter)
s.mount('https://', fx_adapter)
return s
def test_call(fx_adapter, fx_session):
def callback(request, context):
return {'_type': 'point', 'x': 1.0, 'top': 2.0}
method_name = 'hello_world'
base_url = 'http://example.com/'
url = '{0}?method={1}'.format(base_url, method_name)
fx_adapter.register_uri('POST', url, json=callback)
t = HttpTransport(base_url, session=fx_session)
successful, result = t.call(
method_name, payload={'name': 'John'},
service_annotations={},
method_annotations={},
parameter_annotations={}
)
assert successful
assert result == {'_type': 'point', 'x': 1.0, 'top': 2.0}
def test_unexpected_nirum_response_error(fx_adapter, fx_session):
method_name = 'hello_world'
base_url = 'http://example.com/'
url = '{0}?method={1}'.format(base_url, method_name)
fx_adapter.register_uri('POST', url, text='Error message')
t = HttpTransport(base_url, session=fx_session)
with raises(UnexpectedNirumResponseError) as exc_info:
t.call(
method_name, payload={'name': 'John'},
service_annotations={},
method_annotations={},
parameter_annotations={}
)
exc = exc_info.value
assert exc.args == ('Error message',)
assert isinstance(exc.args[0], str)