| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from empty_dir_file_system import EmptyDirFileSystem | 8 from empty_dir_file_system import EmptyDirFileSystem |
| 9 from file_system import FileSystem | 9 from file_system import FileSystem |
| 10 from instance_servlet import InstanceServlet | 10 from instance_servlet import InstanceServlet |
| 11 from servlet import Request | 11 from servlet import Request |
| 12 from test_branch_utility import TestBranchUtility | |
| 13 from test_file_system import TestFileSystem | 12 from test_file_system import TestFileSystem |
| 14 from test_util import DisableLogging | 13 from test_util import DisableLogging |
| 15 | 14 |
| 16 # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto | 15 # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto |
| 17 # our fake AppEngine memcache/datastore, so the tests aren't isolated. | 16 # our fake AppEngine memcache/datastore, so the tests aren't isolated. |
| 18 class _TestDelegate(InstanceServlet.Delegate): | 17 class _FailOnAccessDelegate(InstanceServlet.Delegate): |
| 19 def __init__(self, file_system_type): | 18 def CreateHostFileSystem(self): |
| 20 self._file_system_type = file_system_type | 19 # All this needs to do is implement GetIdentity. All other methods will |
| 21 | 20 # automatically fail with NotImplementedErrors. |
| 22 def CreateBranchUtility(self, object_store_creator): | 21 class FailFS(FileSystem): |
| 23 return TestBranchUtility() | 22 def GetIdentity(self): |
| 24 | 23 return '42' |
| 25 def CreateHostFileSystemForBranch(self, branch): | 24 return FailFS() |
| 26 return self._file_system_type() | |
| 27 | 25 |
| 28 def CreateAppSamplesFileSystem(self, object_store_creator): | 26 def CreateAppSamplesFileSystem(self, object_store_creator): |
| 29 return EmptyDirFileSystem() | 27 return EmptyDirFileSystem() |
| 30 | 28 |
| 31 class _FailOnAccessFileSystem(FileSystem): | |
| 32 # All this needs to do is implement GetIdentity. All other methods will | |
| 33 # automatically fail with NotImplementedErrors. | |
| 34 def GetIdentity(self): | |
| 35 return '42' | |
| 36 | |
| 37 class InstanceServletTest(unittest.TestCase): | 29 class InstanceServletTest(unittest.TestCase): |
| 38 @DisableLogging('warning') | 30 @DisableLogging('warning') |
| 39 def testHostFileSystemNotAccessed(self): | 31 def testHostFileSystemNotAccessed(self): |
| 40 delegate = _TestDelegate(_FailOnAccessFileSystem) | 32 constructor = InstanceServlet.GetConstructor( |
| 41 constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate) | 33 delegate_for_test=_FailOnAccessDelegate()) |
| 42 def test_path(path): | 34 def test_path(path): |
| 43 response = constructor(Request.ForTest(path)).Get() | 35 response = constructor(Request.ForTest(path)).Get() |
| 44 self.assertEqual(404, response.status) | 36 self.assertEqual(404, response.status) |
| 45 test_path('extensions/storage.html') | 37 test_path('extensions/storage.html') |
| 46 test_path('apps/storage.html') | 38 test_path('apps/storage.html') |
| 47 test_path('extensions/examples/foo.zip') | 39 test_path('extensions/examples/foo.zip') |
| 48 test_path('extensions/examples/foo.html') | 40 test_path('extensions/examples/foo.html') |
| 49 test_path('static/foo.css') | 41 test_path('static/foo.css') |
| 50 test_path('beta/extensions/storage.html') | |
| 51 test_path('beta/apps/storage.html') | |
| 52 test_path('beta/extensions/examples/foo.zip') | |
| 53 test_path('beta/extensions/examples/foo.html') | |
| 54 test_path('beta/static/foo.css') | |
| 55 | 42 |
| 56 if __name__ == '__main__': | 43 if __name__ == '__main__': |
| 57 unittest.main() | 44 unittest.main() |
| OLD | NEW |