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 | 12 from test_branch_utility import TestBranchUtility |
13 from test_util import DisableLogging | 13 from test_util import DisableLogging |
14 | 14 |
| 15 # XXX(kalman): what is this test supposed to be? |
| 16 # Create a test host file system creator which failz? |
| 17 |
15 # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto | 18 # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto |
16 # our fake AppEngine memcache/datastore, so the tests aren't isolated. | 19 # our fake AppEngine memcache/datastore, so the tests aren't isolated. |
17 class _TestDelegate(InstanceServlet.Delegate): | 20 class _TestDelegate(InstanceServlet.Delegate): |
18 def __init__(self, file_system_type): | 21 def __init__(self, file_system_type): |
19 self._file_system_type = file_system_type | 22 self._file_system_type = file_system_type |
20 | 23 |
21 def CreateBranchUtility(self, object_store_creator): | 24 def CreateBranchUtility(self, object_store_creator): |
22 return TestBranchUtility.CreateWithCannedData() | 25 return TestBranchUtility.CreateWithCannedData() |
23 | 26 |
24 def CreateAppSamplesFileSystem(self, object_store_creator): | 27 def CreateAppSamplesFileSystem(self, object_store_creator): |
25 return EmptyDirFileSystem() | 28 return EmptyDirFileSystem() |
26 | 29 |
27 class _FailOnAccessFileSystem(FileSystem): | 30 class _FailOnAccessFileSystem(FileSystem): |
28 # All this needs to do is implement GetIdentity. All other methods will | 31 # All this needs to do is implement GetIdentity. All other methods will |
29 # automatically fail with NotImplementedErrors. | 32 # automatically fail with NotImplementedErrors. |
30 def GetIdentity(self): | 33 def GetIdentity(self): |
31 return '42' | 34 return '42' |
32 | 35 |
33 class InstanceServletTest(unittest.TestCase): | 36 class InstanceServletTest(unittest.TestCase): |
34 @DisableLogging('warning') | 37 @DisableLogging('warning') |
35 def testHostFileSystemNotAccessed(self): | 38 def testHostFileSystemNotAccessed(self): |
36 delegate = _TestDelegate(_FailOnAccessFileSystem) | 39 delegate = _TestDelegate(_FailOnAccessFileSystem) |
37 constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate) | 40 constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate) |
38 def test_path(path): | 41 def test_path(path, status=404): |
39 response = constructor(Request.ForTest(path)).Get() | 42 response = constructor(Request.ForTest(path)).Get() |
40 self.assertEqual(404, response.status) | 43 self.assertEqual(status, response.status) |
41 test_path('extensions/storage.html') | 44 test_path('extensions/storage.html') |
42 test_path('apps/storage.html') | 45 test_path('apps/storage.html') |
43 test_path('extensions/examples/foo.zip') | 46 test_path('extensions/examples/foo.zip') |
44 test_path('extensions/examples/foo.html') | 47 test_path('extensions/examples/foo.html') |
45 test_path('static/foo.css') | 48 test_path('static/foo.css') |
46 test_path('beta/extensions/storage.html') | 49 test_path('beta/extensions/storage.html', status=301) |
47 test_path('beta/apps/storage.html') | 50 test_path('beta/apps/storage.html', status=301) |
48 test_path('beta/extensions/examples/foo.zip') | 51 test_path('beta/extensions/examples/foo.zip', status=301) |
49 test_path('beta/extensions/examples/foo.html') | 52 test_path('beta/extensions/examples/foo.html', status=301) |
50 test_path('beta/static/foo.css') | 53 test_path('beta/static/foo.css', status=301) |
51 | 54 |
52 if __name__ == '__main__': | 55 if __name__ == '__main__': |
53 unittest.main() | 56 unittest.main() |
OLD | NEW |