Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/tests/test_rpc_client_server.py
Show All 24 Lines | class RPCTest: | ||||
@remote_api_endpoint("path/to/endpoint") | @remote_api_endpoint("path/to/endpoint") | ||||
def something(self, data, db=None, cur=None): | def something(self, data, db=None, cur=None): | ||||
return data | return data | ||||
@remote_api_endpoint("raises_typeerror") | @remote_api_endpoint("raises_typeerror") | ||||
def raise_typeerror(self): | def raise_typeerror(self): | ||||
raise TypeError("Did I pass through?") | raise TypeError("Did I pass through?") | ||||
@remote_api_endpoint("raise_exception_exc_arg") | |||||
def raise_exception_exc_arg(self): | |||||
raise Exception(Exception("error")) | |||||
# this class is used on the client part. We cannot inherit from RPCTest | # this class is used on the client part. We cannot inherit from RPCTest | ||||
# because the automagic metaclass based code that generates the RPCClient | # because the automagic metaclass based code that generates the RPCClient | ||||
# proxy class from this does not handle inheritance properly. | # proxy class from this does not handle inheritance properly. | ||||
# We do add an endpoint on the client side that has no implementation | # We do add an endpoint on the client side that has no implementation | ||||
# server-side to test this very situation (in should generate a 404) | # server-side to test this very situation (in should generate a 404) | ||||
class RPCTest2: | class RPCTest2: | ||||
@remote_api_endpoint("endpoint_url") | @remote_api_endpoint("endpoint_url") | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | with pytest.raises(RemoteException) as exc_info: | ||||
swh_rpc_client.raise_typeerror() | swh_rpc_client.raise_typeerror() | ||||
assert exc_info.value.args[0]["type"] == "TypeError" | assert exc_info.value.args[0]["type"] == "TypeError" | ||||
assert exc_info.value.args[0]["args"] == ["Did I pass through?"] | assert exc_info.value.args[0]["args"] == ["Did I pass through?"] | ||||
assert ( | assert ( | ||||
str(exc_info.value) | str(exc_info.value) | ||||
== "<RemoteException 500 TypeError: ['Did I pass through?']>" | == "<RemoteException 500 TypeError: ['Did I pass through?']>" | ||||
) | ) | ||||
def test_api_raise_exception_exc_arg(swh_rpc_client): | |||||
with pytest.raises(RemoteException) as exc_info: | |||||
swh_rpc_client.post("raise_exception_exc_arg", data={}) | |||||
assert exc_info.value.args[0]["type"] == "Exception" | |||||
assert type(exc_info.value.args[0]["args"][0]) == Exception | |||||
assert str(exc_info.value.args[0]["args"][0]) == "error" |