Browse Source

add test for BottleContext

Bastien Sevajol 6 years ago
parent
commit
cfd242cbc6
1 changed files with 19 additions and 0 deletions
  1. 19 0
      tests/ext/unit/test_bottle.py

+ 19 - 0
tests/ext/unit/test_bottle.py View File

@@ -1,7 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import bottle
3
+from webtest import TestApp
3 4
 
4 5
 import hapic
6
+from hapic.ext.bottle import BottleContext
5 7
 from tests.base import Base
6 8
 
7 9
 
@@ -74,3 +76,20 @@ class TestBottleExt(Base):
74 76
         assert route.original_route_object.callback != MyControllers.controller_a  # nopep8
75 77
         assert route.original_route_object.callback != decoration.reference.wrapped  # nopep8
76 78
         assert route.original_route_object.callback != decoration.reference.wrapper  # nopep8
79
+
80
+    def test_unit__general_exception_handling__ok__nominal_case(self):
81
+        hapic_ = hapic.Hapic()
82
+        app = bottle.Bottle()
83
+        context = BottleContext(app=app)
84
+        hapic_.set_context(context)
85
+
86
+        def my_view():
87
+            raise ZeroDivisionError('An exception message')
88
+
89
+        app.route('/my-view', method='GET', callback=my_view)
90
+        context.handle_exception(ZeroDivisionError, http_code=400)
91
+
92
+        test_app = TestApp(app)
93
+        response = test_app.get('/my-view', status='*')
94
+
95
+        assert 400 == response.status_code