blob: 71b52f86b162b86ef638f8a464f64442b2112106 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""Unit tests for the custom_404 servlet."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import httplib
12import unittest
13
14from framework import exceptions
15from services import service_manager
16from sitewide import custom_404
17from testing import fake
18from testing import testing_helpers
19
20
21class Custom404Test(unittest.TestCase):
22
23 def setUp(self):
24 self.services = service_manager.Services(
25 project=fake.ProjectService())
26 self.servlet = custom_404.ErrorPage('req', 'res', services=self.services)
27
28 def testGatherPageData_NoProjectSpecified(self):
29 """Project was not included in URL, so raise exception, will cause 400."""
30 _, mr = testing_helpers.GetRequestObjects(
31 path='/not/a/project/url')
32
33 with self.assertRaises(exceptions.InputException):
34 self.servlet.GatherPageData(mr)
35
36 def testGatherPageData_Normal(self):
37 """Return page_data dict with a 404 response code specified."""
38 _project = self.services.project.TestAddProject('proj')
39 _, mr = testing_helpers.GetRequestObjects(path='/p/proj/junk')
40
41 page_data = self.servlet.GatherPageData(mr)
42 self.assertEqual(
43 {'http_response_code': httplib.NOT_FOUND},
44 page_data)