|
@@ -1,8 +1,10 @@
|
1
|
1
|
# coding: utf-8
|
2
|
2
|
import bottle
|
|
3
|
+from pyramid.config import Configurator
|
3
|
4
|
from webtest import TestApp
|
4
|
5
|
|
5
|
6
|
from hapic import Hapic
|
|
7
|
+from hapic.ext.pyramid import PyramidContext
|
6
|
8
|
from tests.base import Base
|
7
|
9
|
from tests.base import MyContext
|
8
|
10
|
|
|
@@ -19,9 +21,43 @@ class TestExceptionHandling(Base):
|
19
|
21
|
raise ZeroDivisionError('An exception message')
|
20
|
22
|
|
21
|
23
|
app.route('/my-view', method='GET', callback=my_view)
|
|
24
|
+ # FIXME - G.M - 17-05-2018 - Verify if:
|
|
25
|
+ # - other view that work/raise an other exception do not go
|
|
26
|
+ # into this code for handle this exceptions.
|
|
27
|
+ # - response come clearly from there, not from web framework:
|
|
28
|
+ # Check not only http code, but also body.
|
22
|
29
|
context.handle_exception(ZeroDivisionError, http_code=400)
|
23
|
30
|
|
24
|
31
|
test_app = TestApp(app)
|
25
|
32
|
response = test_app.get('/my-view', status='*')
|
26
|
33
|
|
27
|
34
|
assert 400 == response.status_code
|
|
35
|
+
|
|
36
|
+ def test_func__catch_one_exception__ok__pyramid(self):
|
|
37
|
+ # TODO - G.M - 17-05-2018 - Move/refactor this test
|
|
38
|
+ # in order to have here only framework agnostic test
|
|
39
|
+ # and framework_specific
|
|
40
|
+ # test somewhere else.
|
|
41
|
+ hapic = Hapic()
|
|
42
|
+ configurator = Configurator(autocommit=True)
|
|
43
|
+ context = PyramidContext(configurator)
|
|
44
|
+ hapic.set_context(context)
|
|
45
|
+
|
|
46
|
+ def my_view(context, request):
|
|
47
|
+ raise ZeroDivisionError('An exception message')
|
|
48
|
+
|
|
49
|
+ configurator.add_route('my_view','/my-view', request_method='GET')
|
|
50
|
+ configurator.add_view(my_view, route_name='my_view', renderer='json')
|
|
51
|
+
|
|
52
|
+ # FIXME - G.M - 17-05-2018 - Verify if:
|
|
53
|
+ # - other view that work/raise an other exception do not go
|
|
54
|
+ # into this code for handle this exceptions.
|
|
55
|
+ # - response come clearly from there, not from web framework:
|
|
56
|
+ # Check not only http code, but also body.
|
|
57
|
+ context.handle_exception(ZeroDivisionError, http_code=400)
|
|
58
|
+
|
|
59
|
+ app = configurator.make_wsgi_app()
|
|
60
|
+ test_app = TestApp(app)
|
|
61
|
+ response = test_app.get('/my-view', status='*')
|
|
62
|
+
|
|
63
|
+ assert 400 == response.status_code
|