Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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. |
| 5 | |
| 6 | import unittest |
| 7 | |
| 8 | from empty_dir_file_system import EmptyDirFileSystem |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 9 | from instance_servlet import InstanceServlet |
| 10 | from servlet import Request |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 11 | from fail_on_access_file_system import FailOnAccessFileSystem |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 12 | from test_branch_utility import TestBranchUtility |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 13 | from test_util import DisableLogging |
| 14 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 15 | # XXX(kalman): what is this test supposed to be? |
| 16 | # Create a test host file system creator which failz? |
| 17 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 18 | # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto |
| 19 | # our fake AppEngine memcache/datastore, so the tests aren't isolated. |
| 20 | class _TestDelegate(InstanceServlet.Delegate): |
| 21 | def __init__(self, file_system_type): |
| 22 | self._file_system_type = file_system_type |
| 23 | |
| 24 | def CreateBranchUtility(self, object_store_creator): |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 25 | return TestBranchUtility.CreateWithCannedData() |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 26 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 27 | def CreateAppSamplesFileSystem(self, object_store_creator): |
| 28 | return EmptyDirFileSystem() |
| 29 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 30 | class InstanceServletTest(unittest.TestCase): |
| 31 | @DisableLogging('warning') |
| 32 | def testHostFileSystemNotAccessed(self): |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 33 | delegate = _TestDelegate(FailOnAccessFileSystem) |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 34 | constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate) |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 35 | def test_path(path, status=404): |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 36 | response = constructor(Request.ForTest(path)).Get() |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 37 | self.assertEqual(status, response.status) |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 38 | test_path('extensions/storage.html') |
| 39 | test_path('apps/storage.html') |
| 40 | test_path('extensions/examples/foo.zip') |
| 41 | test_path('extensions/examples/foo.html') |
| 42 | test_path('static/foo.css') |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 43 | test_path('beta/extensions/storage.html', status=301) |
| 44 | test_path('beta/apps/storage.html', status=301) |
| 45 | test_path('beta/extensions/examples/foo.zip', status=301) |
| 46 | test_path('beta/extensions/examples/foo.html', status=301) |
| 47 | test_path('beta/static/foo.css', status=301) |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 48 | |
| 49 | if __name__ == '__main__': |
| 50 | unittest.main() |