|
@@ -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
|
|
|
@@ -25,3 +27,27 @@ class TestExceptionHandling(Base):
|
25
|
27
|
response = test_app.get('/my-view', status='*')
|
26
|
28
|
|
27
|
29
|
assert 400 == response.status_code
|
|
30
|
+
|
|
31
|
+ def test_func__catch_one_exception__ok__pyramid(self):
|
|
32
|
+ # TODO - G.M - 17-05-2018 - Move/refactor this test
|
|
33
|
+ # in order to have here only framework agnostic test
|
|
34
|
+ # and framework_specific
|
|
35
|
+ # test somewhere else.
|
|
36
|
+ hapic = Hapic()
|
|
37
|
+ configurator = Configurator(autocommit=True)
|
|
38
|
+ context = PyramidContext(configurator)
|
|
39
|
+ hapic.set_context(context)
|
|
40
|
+
|
|
41
|
+ def my_view(context, request):
|
|
42
|
+ raise ZeroDivisionError('An exception message')
|
|
43
|
+
|
|
44
|
+ configurator.add_route('my_view','/my-view', request_method='GET')
|
|
45
|
+ configurator.add_view(my_view, route_name='my_view', renderer='json')
|
|
46
|
+
|
|
47
|
+ context.handle_exception(ZeroDivisionError, http_code=400)
|
|
48
|
+
|
|
49
|
+ app = configurator.make_wsgi_app()
|
|
50
|
+ test_app = TestApp(app)
|
|
51
|
+ response = test_app.get('/my-view', status='*')
|
|
52
|
+
|
|
53
|
+ assert 400 == response.status_code
|