q3stats/tests_web_app/test_app_handle_error.py

46 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import os
from q3stats.testing import BaseQ3StatsWebAppTestCase
class Test_GetFrontendIndex(BaseQ3StatsWebAppTestCase):
@classmethod
def setUpClass(cls):
super(Test_GetFrontendIndex, cls).setUpClass()
cls.app.config['PROPAGATE_EXCEPTIONS'] = False
cls.app.config['LOGGER_HANDLER_POLICY'] = 'never'
def test_404(self):
with self.app.test_request_context():
rsp = self.client.get('/idontexist')
assert rsp.status_code == 404
data = rsp.data.decode('utf-8')
assert 'body id="server-error" class="error-404"' in data
def test_400(self):
with self.app.test_request_context():
rsp = self.client.post('/receivestats')
assert rsp.status_code == 400
data = rsp.data.decode('utf-8')
assert 'body id="server-error" class="error-400"' in data
def test_500(self):
broken_tarball = os.path.join(
os.path.dirname(__file__), 'fixtures', 'broken_tarball.tar'
)
with self.app.test_request_context():
with open(broken_tarball, 'rb') as broken_tarball_f:
rsp = self.client.post('/receivestats', data={
'stats': (broken_tarball_f, 'stats.tar')
})
assert rsp.status_code == 500
data = rsp.data.decode('utf-8')
assert 'body id="server-error" class="error-500"' in data