test_exception_handling.py 774B

12345678910111213141516171819202122232425262728
  1. # coding: utf-8
  2. import bottle
  3. from webtest import TestApp
  4. from hapic import Hapic
  5. from tests.base import Base
  6. from tests.base import MyContext
  7. class TestExceptionHandling(Base):
  8. def test_func__catch_one_exception__ok__nominal_case(self):
  9. hapic = Hapic()
  10. # TODO BS 2018-05-04: Make this test non-bottle
  11. app = bottle.Bottle()
  12. context = MyContext(app=app)
  13. hapic.set_context(context)
  14. def my_view():
  15. raise ZeroDivisionError('An exception message')
  16. app.route('/my-view', method='GET', callback=my_view)
  17. context.handle_exception(ZeroDivisionError, http_code=400)
  18. test_app = TestApp(app)
  19. response = test_app.get('/my-view', status='*')
  20. assert 400 == response.status_code