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

tests.app.hooks.test_error   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestHTTPExceptionHandler.test() 0 13 4
A TestBroadExceptionHandler.test_500() 0 6 1
A TestError.add_route_raises_exception() 0 6 1
A TestError.setUp() 0 4 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.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