diff --git a/cara/apps/calculator/__init__.py b/cara/apps/calculator/__init__.py
index adcfb7f6..37c2e48c 100644
--- a/cara/apps/calculator/__init__.py
+++ b/cara/apps/calculator/__init__.py
@@ -66,6 +66,7 @@ class BaseRequestHandler(RequestHandler):
print(traceback.format_exc())
self.finish(template.render(
user=self.current_user,
+ active_page='Error',
contents=contents
))
@@ -78,6 +79,7 @@ class Missing404Handler(BaseRequestHandler):
"page.html.j2")
self.finish(template.render(
user=self.current_user,
+ active_page='Error',
contents='Unfortunately the page you were looking for does not exist.
'
))
@@ -185,6 +187,7 @@ def make_app(
loader = jinja2.FileSystemLoader([str(path) for path in templates_directories])
template_environment = jinja2.Environment(
loader=loader,
+ undefined=jinja2.StrictUndefined, # fail when rendering any undefined template context variable
)
template_environment.globals['common_text'] = markdown_tools.extract_rendered_markdown_blocks(
diff --git a/cara/tests/apps/calculator/test_webapp.py b/cara/tests/apps/calculator/test_webapp.py
index 3c133684..ca7a893a 100644
--- a/cara/tests/apps/calculator/test_webapp.py
+++ b/cara/tests/apps/calculator/test_webapp.py
@@ -31,6 +31,17 @@ async def test_user_guide(http_server_client):
assert resp.code == 200
+@pytest.mark.xfail(reason="about page not yet implemented")
+async def test_about(http_server_client):
+ resp = await http_server_client.fetch('/about')
+ assert resp.code == 200
+
+
+async def test_404(http_server_client):
+ resp = await http_server_client.fetch('/doesnt-exist', raise_error=False)
+ assert resp.code == 404
+
+
class TestBasicApp(tornado.testing.AsyncHTTPTestCase):
def get_app(self):
return cara.apps.calculator.make_app()
@@ -83,3 +94,20 @@ async def test_invalid_compressed_url(http_server_client, baseline_form):
raise_error=False,
)
assert response.code == 400
+
+
+class TestError500(tornado.testing.AsyncHTTPTestCase):
+ def get_app(self):
+ class ProcessingErrorPage(cara.apps.calculator.BaseRequestHandler):
+ def get(self):
+ raise ValueError('some unexpected error')
+ app = cara.apps.calculator.make_app()
+ page = [
+ (r'/', ProcessingErrorPage),
+ ]
+ return tornado.web.Application(page, **app.settings)
+
+ def test_500(self):
+ response = self.fetch('/')
+ assert response.code == 500
+ assert 'Unfortunately an error occurred when processing your request' in response.body.decode()