Repository navigation
Expand file tree
/
Copy pathmain_test.py
More file actions
77 lines (60 loc) · 2.73 KB
/
Copy pathmain_test.py
File metadata and controls
77 lines (60 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright 2021 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for the main application entry point and routing configuration."""
import testing_config # isort: split
import flask
import html5lib
import main
from framework import basehandlers
test_app = flask.Flask(__name__)
class MainTest(testing_config.CustomTestCase):
"""Set of unit tests for our page route registration and other setup."""
def test_app_exists(self):
"""Just test that this file parses and creates an app object."""
self.assertIsNotNone(main.app)
def test_warmup_route_registered(self):
"""Verify that the warmup route is registered to WarmupHandler."""
rules = [
r for r in main.app.url_map.iter_rules() if r.rule == '/_ah/warmup'
]
self.assertEqual(len(rules), 1)
rule = rules[0]
view_func = main.app.view_functions[rule.endpoint]
self.assertEqual(view_func.view_class, basehandlers.WarmupHandler)
def test_warmup_handler(self):
"""Verify that WarmupHandler returns OK."""
handler = basehandlers.WarmupHandler()
response, status = handler.get()
self.assertEqual(response, 'OK')
self.assertEqual(status, 200)
class ConstTemplateTest(testing_config.CustomTestCase):
"""Tests for constant template rendering."""
def check_template(self, route):
"""Checks if a template renders correctly for a given route."""
handler = route.handler_class()
with test_app.test_request_context(route.path):
template_data = handler.get_template_data(**route.defaults)
full_template_path = handler.get_template_path(template_data)
template_text = handler.render(template_data, full_template_path)
parser = html5lib.HTMLParser(strict=True)
document = parser.parse(template_text) # noqa: F841
def test_const_templates(self):
"""All the ConstHandler instances render valid HTML."""
for route in main.mpa_page_routes:
if (
route.handler_class == basehandlers.ConstHandler
and not route.path.endswith('.xml')
):
with self.subTest(path=route.path):
self.check_template(route)