Passed
Push — master ( 622bd5...daf764 )
by Mingyu
57s
created

TestHTTPExceptionHandler.test()   A

Complexity

Conditions 4

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 11
rs 9.95
c 0
b 0
f 0
cc 4
nop 1
1
from werkzeug.exceptions import HTTPException
2
from werkzeug.routing import RequestRedirect
3
4
from tests import BaseTestCase
5
6
7
class TestError(BaseTestCase):
8
    def setUp(self):
9
        super(TestError, self).setUp()
10
11
        self.app.debug = False
12
        # to prevent AssertionError: A setup function was called ...
13
14
        self.path = "/foo"
15
16
    def add_route_raises_exception(self, exception_cls):
17
        self.app.view_functions.pop("handler", None)
18
19
        @self.app.route(self.path)
20
        def handler():
21
            raise exception_cls()
22
23
24
class TestHTTPExceptionHandler(TestError):
25
    def test(self):
26
        for exception_cls in HTTPException.__subclasses__():
27
            if exception_cls is RequestRedirect or exception_cls().code == 412:
28
                continue
29
30
            self.add_route_raises_exception(exception_cls)
31
32
            resp = self.request()
33
            self.assertEqual(exception_cls().code, resp.status_code)
34
            self.assertTrue(resp.is_json)
35
            self.assertDictEqual({"message": exception_cls().description}, resp.json)
36
37
38
class TestBroadExceptionHandler(TestError):
39
    # TODO broad_exception_handler가 세분화될 때마다 테스트 케이스 추가
40
41
    def test_500(self):
42
        self.add_route_raises_exception(Exception)
43
44
        resp = self.request()
45
        self.assertEqual(500, resp.status_code)
46
        self.assertEqual("", resp.data.decode())
47