Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # 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.""" |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | import httplib |
| 12 | import unittest |
| 13 | |
| 14 | from framework import exceptions |
| 15 | from services import service_manager |
| 16 | from sitewide import custom_404 |
| 17 | from testing import fake |
| 18 | from testing import testing_helpers |
| 19 | |
| 20 | |
| 21 | class 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) |