def test_adaptaion(): class TestException(Exception): pass uexc = IUserException( user_exception(TestException(), title="Title", message="Message", detail="Detail", http_status_code=418, data=dict(key="value"))) assert uexc.title == "Title" assert uexc.message == "Message" assert uexc.detail == "Detail" assert uexc.http_status_code == 418 assert uexc.data == dict(key="value")
def test_interface(): @implementer(IUserException) class TestException(Exception): title = "Title" message = "Message" detail = "Detail" http_status_code = 418 data = dict(key="value") exc = TestException() uexc = IUserException(exc) assert uexc.title == "Title" assert uexc.message == "Message" assert uexc.detail == "Detail" assert uexc.http_status_code == 418 assert uexc.data == dict(key="value")
def test_not_implemented(): class TestException(Exception): pass with pytest.raises(TypeError): IUserException(TestException())