| 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 appengine_wrappers import GetAppVersion | 8 from appengine_wrappers import GetAppVersion |
| 9 from app_yaml_helper import AppYamlHelper | 9 from app_yaml_helper import AppYamlHelper |
| 10 from cron_servlet import CronServlet | 10 from cron_servlet import CronServlet |
| 11 from empty_dir_file_system import EmptyDirFileSystem | 11 from empty_dir_file_system import EmptyDirFileSystem |
| 12 from host_file_system_creator import HostFileSystemCreator | 12 from host_file_system_provider import HostFileSystemProvider |
| 13 from local_file_system import LocalFileSystem | 13 from local_file_system import LocalFileSystem |
| 14 from mock_file_system import MockFileSystem | 14 from mock_file_system import MockFileSystem |
| 15 from servlet import Request | 15 from servlet import Request |
| 16 from test_branch_utility import TestBranchUtility | 16 from test_branch_utility import TestBranchUtility |
| 17 from test_file_system import TestFileSystem | 17 from test_file_system import TestFileSystem |
| 18 from test_util import EnableLogging | 18 from test_util import EnableLogging |
| 19 | 19 |
| 20 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our | 20 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our |
| 21 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, | 21 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, |
| 22 # if the host file systems have different identities, they will be, sort of. | 22 # if the host file systems have different identities, they will be, sort of. |
| 23 class _TestDelegate(CronServlet.Delegate): | 23 class _TestDelegate(CronServlet.Delegate): |
| 24 def __init__(self, create_file_system): | 24 def __init__(self, create_file_system): |
| 25 self.file_systems = [] | 25 self.file_systems = [] |
| 26 # A callback taking a revision and returning a file system. | 26 # A callback taking a revision and returning a file system. |
| 27 self._create_file_system = create_file_system | 27 self._create_file_system = create_file_system |
| 28 self._app_version = GetAppVersion() | 28 self._app_version = GetAppVersion() |
| 29 | 29 |
| 30 def CreateBranchUtility(self, object_store_creator): | 30 def CreateBranchUtility(self, object_store_creator): |
| 31 return TestBranchUtility.CreateWithCannedData() | 31 return TestBranchUtility.CreateWithCannedData() |
| 32 | 32 |
| 33 def CreateHostFileSystemCreator(self, object_store_creator): | 33 def CreateHostFileSystemProvider(self, |
| 34 object_store_creator, |
| 35 max_trunk_revision=None): |
| 34 def constructor(branch=None, revision=None): | 36 def constructor(branch=None, revision=None): |
| 35 file_system = self._create_file_system(revision) | 37 file_system = self._create_file_system(revision) |
| 36 self.file_systems.append(file_system) | 38 self.file_systems.append(file_system) |
| 37 return file_system | 39 return file_system |
| 38 return HostFileSystemCreator(object_store_creator, | 40 return HostFileSystemProvider(object_store_creator, |
| 41 max_trunk_revision=max_trunk_revision, |
| 39 constructor_for_test=constructor) | 42 constructor_for_test=constructor) |
| 40 | 43 |
| 41 def CreateAppSamplesFileSystem(self, object_store_creator): | 44 def CreateAppSamplesFileSystem(self, object_store_creator): |
| 42 return EmptyDirFileSystem() | 45 return EmptyDirFileSystem() |
| 43 | 46 |
| 44 def GetAppVersion(self): | 47 def GetAppVersion(self): |
| 45 return self._app_version | 48 return self._app_version |
| 46 | 49 |
| 47 # (non-Delegate method). | 50 # (non-Delegate method). |
| 48 def SetAppVersion(self, app_version): | 51 def SetAppVersion(self, app_version): |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 217 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 215 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), | 218 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), |
| 216 file_systems[-1].ReadSingle(app_yaml_path)) | 219 file_systems[-1].ReadSingle(app_yaml_path)) |
| 217 self.assertEqual('y u not update!', | 220 self.assertEqual('y u not update!', |
| 218 file_systems[-1].ReadSingle(storage_html_path)) | 221 file_systems[-1].ReadSingle(storage_html_path)) |
| 219 self.assertEqual('important content!', | 222 self.assertEqual('important content!', |
| 220 file_systems[-1].ReadSingle(static_txt_path)) | 223 file_systems[-1].ReadSingle(static_txt_path)) |
| 221 | 224 |
| 222 if __name__ == '__main__': | 225 if __name__ == '__main__': |
| 223 unittest.main() | 226 unittest.main() |
| OLD | NEW |