Пример #1
0
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")
Пример #2
0
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")
Пример #3
0
def test_not_implemented():
    class TestException(Exception):
        pass

    with pytest.raises(TypeError):
        IUserException(TestException())