Total Complexity | 7 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 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 |