38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
|
|
"""Unit tests for pylimerpc.errors (pytest)."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pylimerpc.errors import LsApiError, LsAuthError, LsConnectionError, LsError
|
||
|
|
|
||
|
|
|
||
|
|
def test_api_error_bewaart_originele_rpc_fout():
|
||
|
|
raw = {"code": -32602, "message": "Invalid params"}
|
||
|
|
err = LsApiError(
|
||
|
|
"list_surveys failed",
|
||
|
|
method="list_surveys",
|
||
|
|
rpc_code=raw["code"],
|
||
|
|
rpc_message=raw["message"],
|
||
|
|
raw=raw,
|
||
|
|
)
|
||
|
|
assert isinstance(err, LsError)
|
||
|
|
assert err.method == "list_surveys"
|
||
|
|
assert err.rpc_code == -32602
|
||
|
|
assert err.rpc_message == "Invalid params"
|
||
|
|
assert err.raw == raw
|
||
|
|
assert "list_surveys failed" in str(err)
|
||
|
|
|
||
|
|
|
||
|
|
def test_auth_error_is_een_api_error():
|
||
|
|
err = LsAuthError("login refused", rpc_message="Invalid user name or password!")
|
||
|
|
assert isinstance(err, LsApiError)
|
||
|
|
assert isinstance(err, LsError)
|
||
|
|
assert err.rpc_message == "Invalid user name or password!"
|
||
|
|
|
||
|
|
|
||
|
|
def test_connection_error_bewaart_url_en_cause():
|
||
|
|
cause = OSError("connection timed out")
|
||
|
|
err = LsConnectionError("server onbereikbaar", url="https://ls.example.com", cause=cause)
|
||
|
|
assert isinstance(err, LsError)
|
||
|
|
assert not isinstance(err, LsApiError)
|
||
|
|
assert err.url == "https://ls.example.com"
|
||
|
|
assert err.cause is cause
|