blob: fe099d65b246f1121b87330eab603ea4edc5fbcd [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2017 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Unit tests for the custom_404 servlet."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020010from six.moves import http_client
Copybara854996b2021-09-07 19:36:02 +000011import unittest
12
13from framework import exceptions
14from services import service_manager
15from sitewide import custom_404
16from testing import fake
17from testing import testing_helpers
18
19
20class Custom404Test(unittest.TestCase):
21
22 def setUp(self):
23 self.services = service_manager.Services(
24 project=fake.ProjectService())
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010025 self.servlet = custom_404.ErrorPage(services=self.services)
Copybara854996b2021-09-07 19:36:02 +000026
27 def testGatherPageData_NoProjectSpecified(self):
28 """Project was not included in URL, so raise exception, will cause 400."""
29 _, mr = testing_helpers.GetRequestObjects(
30 path='/not/a/project/url')
31
32 with self.assertRaises(exceptions.InputException):
33 self.servlet.GatherPageData(mr)
34
35 def testGatherPageData_Normal(self):
36 """Return page_data dict with a 404 response code specified."""
37 _project = self.services.project.TestAddProject('proj')
38 _, mr = testing_helpers.GetRequestObjects(path='/p/proj/junk')
39
40 page_data = self.servlet.GatherPageData(mr)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020041 self.assertEqual({'http_response_code': http_client.NOT_FOUND}, page_data)