Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Unit tests for the custom_404 servlet.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 10 | from six.moves import http_client |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 11 | import unittest |
| 12 | |
| 13 | from framework import exceptions |
| 14 | from services import service_manager |
| 15 | from sitewide import custom_404 |
| 16 | from testing import fake |
| 17 | from testing import testing_helpers |
| 18 | |
| 19 | |
| 20 | class Custom404Test(unittest.TestCase): |
| 21 | |
| 22 | def setUp(self): |
| 23 | self.services = service_manager.Services( |
| 24 | project=fake.ProjectService()) |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 25 | self.servlet = custom_404.ErrorPage(services=self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 26 | |
| 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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 41 | self.assertEqual({'http_response_code': http_client.NOT_FOUND}, page_data) |