2022-07-15 19:57:51 +03:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
import testing_config # Must be imported before the module under test.
|
|
|
|
|
|
|
|
from unittest import mock
|
2022-08-14 18:05:17 +03:00
|
|
|
import flask
|
2022-07-15 19:57:51 +03:00
|
|
|
from flask import testing
|
2022-08-14 18:05:17 +03:00
|
|
|
import html5lib
|
2022-07-15 19:57:51 +03:00
|
|
|
|
2022-08-14 18:05:17 +03:00
|
|
|
from framework import basehandlers
|
2022-07-15 19:57:51 +03:00
|
|
|
import main
|
|
|
|
|
2022-08-14 18:05:17 +03:00
|
|
|
test_app = flask.Flask(__name__)
|
|
|
|
|
2022-07-15 19:57:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-08-14 18:05:17 +03:00
|
|
|
|
|
|
|
class ConstTemplateTest(testing_config.CustomTestCase):
|
|
|
|
|
|
|
|
def check_template(self, route):
|
2022-11-09 21:06:59 +03:00
|
|
|
handler = route.handler_class()
|
2022-08-14 18:05:17 +03:00
|
|
|
|
2022-11-09 21:06:59 +03:00
|
|
|
with test_app.test_request_context(route.path):
|
|
|
|
template_data = handler.get_template_data(**route.defaults)
|
2022-10-24 21:40:33 +03:00
|
|
|
full_template_path = handler.get_template_path(template_data)
|
|
|
|
template_text = handler.render(template_data, full_template_path)
|
2022-08-14 18:05:17 +03:00
|
|
|
|
|
|
|
parser = html5lib.HTMLParser(strict=True)
|
|
|
|
document = parser.parse(template_text)
|
|
|
|
|
|
|
|
def test_const_templates(self):
|
|
|
|
"""All the ConstHandler instances render valid HTML."""
|
2022-09-13 21:54:32 +03:00
|
|
|
for route in main.mpa_page_routes:
|
2022-11-09 21:06:59 +03:00
|
|
|
if (route.handler_class == basehandlers.ConstHandler and
|
|
|
|
not route.path.endswith('.xml')):
|
|
|
|
with self.subTest(path=route.path):
|
2022-08-14 18:05:17 +03:00
|
|
|
self.check_template(route)
|