test_app_handle_error.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. import os
  3. from q3stats.testing import BaseQ3StatsWebAppTestCase
  4. class Test_GetFrontendIndex(BaseQ3StatsWebAppTestCase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super(Test_GetFrontendIndex, cls).setUpClass()
  8. cls.app.config['PROPAGATE_EXCEPTIONS'] = False
  9. cls.app.config['LOGGER_HANDLER_POLICY'] = 'never'
  10. def test_404(self):
  11. with self.app.test_request_context():
  12. rsp = self.client.get('/idontexist')
  13. assert rsp.status_code == 404
  14. data = rsp.data.decode('utf-8')
  15. assert 'body id="server-error" class="error-404"' in data
  16. def test_400(self):
  17. with self.app.test_request_context():
  18. rsp = self.client.post('/receivestats')
  19. assert rsp.status_code == 400
  20. data = rsp.data.decode('utf-8')
  21. assert 'body id="server-error" class="error-400"' in data
  22. def test_500(self):
  23. broken_tarball = os.path.join(
  24. os.path.dirname(__file__), 'fixtures', 'broken_tarball.tar'
  25. )
  26. with self.app.test_request_context():
  27. with open(broken_tarball, 'rb') as broken_tarball_f:
  28. rsp = self.client.post('/receivestats', data={
  29. 'stats': (broken_tarball_f, 'stats.tar')
  30. })
  31. assert rsp.status_code == 500
  32. data = rsp.data.decode('utf-8')
  33. assert 'body id="server-error" class="error-500"' in data