Passed
Push — master ( 602b7e...b49b41 )
by Mingyu
47s
created

TestBroadExceptionHandler.test_500()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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.path = '/foo'
12
13
    def add_route_raises_exception(self, exception_cls):
14
        self.app.view_functions.pop('handler', None)
15
16
        @self.app.route(self.path)
17
        def handler():
18
            raise exception_cls()
19
20
21
class TestHTTPExceptionHandler(TestError):
22
    def test(self):
23
        for exception_cls in HTTPException.__subclasses__():
24
            if exception_cls is RequestRedirect or exception_cls.code == 412:
25
                continue
26
27
            self.add_route_raises_exception(exception_cls)
28
29
            resp = self.request()
30
            self.assertEqual(exception_cls.code, resp.status_code)
31
            self.assertTrue(resp.is_json)
32
            self.assertDictEqual({
33
                'message': exception_cls.description
34
            }, resp.json)
35
36
37
class TestBroadExceptionHandler(TestError):
38
    # TODO broad_exception_handler가 세분화될 때마다 테스트 케이스 추가
39
40
    def test_500(self):
41
        self.add_route_raises_exception(Exception)
42
43
        resp = self.request()
44
        self.assertEqual(500, resp.status_code)
45
        self.assertEqual('', resp.data.decode())
46