2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
8 from github_file_system_provider import GithubFileSystemProvider
9 from instance_servlet import InstanceServlet
10 from servlet import Request
11 from fail_on_access_file_system import FailOnAccessFileSystem
12 from test_branch_utility import TestBranchUtility
13 from test_util import DisableLogging
15 # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto
16 # our fake AppEngine memcache/datastore, so the tests aren't isolated.
17 class _TestDelegate(InstanceServlet.Delegate):
18 def __init__(self, file_system_type):
19 self._file_system_type = file_system_type
21 def CreateBranchUtility(self, object_store_creator):
22 return TestBranchUtility.CreateWithCannedData()
24 def CreateGithubFileSystemProvider(self, object_store_creator):
25 return GithubFileSystemProvider.ForEmpty()
27 class InstanceServletTest(unittest.TestCase):
28 '''Tests that if the file systems underlying the docserver's data fail,
29 the instance servlet still returns 404s or 301s with a best-effort.
30 It should never return a 500 (i.e. crash).
33 # XXX(kalman): Disabled, see comment in instance_servlet.py and
34 # http://crbug.com/345361.
35 @DisableLogging('warning')
36 def DISABLED_testHostFileSystemNotAccessed(self):
37 delegate = _TestDelegate(FailOnAccessFileSystem)
38 constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate)
39 def test_path(path, status=404):
40 response = constructor(Request.ForTest(path)).Get()
41 self.assertEqual(status, response.status)
42 test_path('extensions/storage.html')
43 test_path('apps/storage.html')
44 test_path('extensions/examples/foo.zip')
45 test_path('extensions/examples/foo.html')
46 test_path('static/foo.css')
47 test_path('beta/extensions/storage.html', status=301)
48 test_path('beta/apps/storage.html', status=301)
49 test_path('beta/extensions/examples/foo.zip', status=301)
50 test_path('beta/extensions/examples/foo.html', status=301)
51 test_path('beta/static/foo.css', status=301)
53 if __name__ == '__main__':