Total Complexity | 7 |
Total Lines | 47 |
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.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 |