Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/tests/test_rpc_client.py
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def callback(request, context): | ||||
context.headers['Content-Type'] = 'application/x-msgpack' | context.headers['Content-Type'] = 'application/x-msgpack' | ||||
if request.path == '/test_endpoint_url': | if request.path == '/test_endpoint_url': | ||||
context.content = b'\xa3egg' | context.content = b'\xa3egg' | ||||
elif request.path == '/path/to/endpoint': | elif request.path == '/path/to/endpoint': | ||||
context.content = b'\xa4spam' | context.content = b'\xa4spam' | ||||
elif request.path == '/serializer_test': | elif request.path == '/serializer_test': | ||||
context.content = ( | context.content = ( | ||||
b'\x82\xc4\x07swhtype\xa9extratype' | b'\x82\xc4\x07swhtype\xa9extratype' | ||||
b'\xc4\x01d\x92\x81\xa4spam\xa3egg\xa3qux') | b'\xc4\x01d\x92\x81\xa4spam\xa3egg\xa3qux' | ||||
) | |||||
else: | else: | ||||
assert False | assert False | ||||
return context.content | return context.content | ||||
requests_mock.post(re.compile('mock://example.com/'), | requests_mock.post(re.compile('mock://example.com/'), content=callback) | ||||
content=callback) | |||||
return Testclient(url='mock://example.com') | return Testclient(url='mock://example.com') | ||||
def test_client(rpc_client): | def test_client(rpc_client): | ||||
assert hasattr(rpc_client, 'test_endpoint') | assert hasattr(rpc_client, 'test_endpoint') | ||||
assert hasattr(rpc_client, 'something') | assert hasattr(rpc_client, 'something') | ||||
Show All 20 Lines |