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 app_yaml_helper import AppYamlHelper | 8 from app_yaml_helper import AppYamlHelper |
9 from content_providers import IgnoreMissingContentProviders | 9 from content_providers import IgnoreMissingContentProviders |
10 from cron_servlet import CronServlet | 10 from cron_servlet import CronServlet |
(...skipping 12 matching lines...) Expand all Loading... |
23 from test_file_system import MoveTo, TestFileSystem | 23 from test_file_system import MoveTo, TestFileSystem |
24 from test_util import EnableLogging, ReadFile | 24 from test_util import EnableLogging, ReadFile |
25 | 25 |
26 | 26 |
27 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our | 27 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our |
28 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, | 28 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, |
29 # if the host file systems have different identities, they will be, sort of. | 29 # if the host file systems have different identities, they will be, sort of. |
30 class _TestDelegate(CronServlet.Delegate): | 30 class _TestDelegate(CronServlet.Delegate): |
31 def __init__(self, create_file_system): | 31 def __init__(self, create_file_system): |
32 self.file_systems = [] | 32 self.file_systems = [] |
33 # A callback taking a revision and returning a file system. | 33 # A callback taking a commit and returning a file system. |
34 self._create_file_system = create_file_system | 34 self._create_file_system = create_file_system |
35 self._app_version = GetAppVersion() | 35 self._app_version = GetAppVersion() |
36 | 36 |
37 def CreateBranchUtility(self, object_store_creator): | 37 def CreateBranchUtility(self, object_store_creator): |
38 return TestBranchUtility.CreateWithCannedData() | 38 return TestBranchUtility.CreateWithCannedData() |
39 | 39 |
40 def CreateHostFileSystemProvider(self, | 40 def CreateHostFileSystemProvider(self, |
41 object_store_creator, | 41 object_store_creator, |
42 max_trunk_revision=None): | 42 pinned_commit=None): |
43 def constructor(branch=None, revision=None): | 43 def constructor(branch=None, commit=None): |
44 file_system = self._create_file_system(revision) | 44 file_system = self._create_file_system(commit) |
45 self.file_systems.append(file_system) | 45 self.file_systems.append(file_system) |
46 return file_system | 46 return file_system |
47 return HostFileSystemProvider(object_store_creator, | 47 return HostFileSystemProvider(object_store_creator, |
48 max_trunk_revision=max_trunk_revision, | 48 pinned_commit=pinned_commit, |
49 constructor_for_test=constructor) | 49 constructor_for_test=constructor) |
50 | 50 |
51 def CreateGithubFileSystemProvider(self, object_store_creator): | 51 def CreateGithubFileSystemProvider(self, object_store_creator): |
52 return GithubFileSystemProvider.ForEmpty() | 52 return GithubFileSystemProvider.ForEmpty() |
53 | 53 |
54 def CreateGCSFileSystemProvider(self, object_store_creator): | 54 def CreateGCSFileSystemProvider(self, object_store_creator): |
55 return CloudStorageFileSystemProvider.ForEmpty() | 55 return CloudStorageFileSystemProvider.ForEmpty() |
56 | 56 |
57 def GetAppVersion(self): | 57 def GetAppVersion(self): |
58 return self._app_version | 58 return self._app_version |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 'apps': {'storage.html': update} | 149 'apps': {'storage.html': update} |
150 }) | 150 }) |
151 def static_txt_update(update): | 151 def static_txt_update(update): |
152 return MoveTo(STATIC_DOCS, { | 152 return MoveTo(STATIC_DOCS, { |
153 'static.txt': update | 153 'static.txt': update |
154 }) | 154 }) |
155 | 155 |
156 storage_html_path = PUBLIC_TEMPLATES + 'apps/storage.html' | 156 storage_html_path = PUBLIC_TEMPLATES + 'apps/storage.html' |
157 static_txt_path = STATIC_DOCS + 'static.txt' | 157 static_txt_path = STATIC_DOCS + 'static.txt' |
158 | 158 |
159 def create_file_system(revision=None): | 159 def create_file_system(commit=None): |
160 '''Creates a MockFileSystem at |revision| by applying that many |updates| | 160 '''Creates a MockFileSystem at |commit| by applying that many |updates| |
161 to it. | 161 to it. |
162 ''' | 162 ''' |
163 mock_file_system = MockFileSystem( | 163 mock_file_system = MockFileSystem( |
164 TestFileSystem(test_data, relative_to=CHROME_EXTENSIONS)) | 164 TestFileSystem(test_data, relative_to=CHROME_EXTENSIONS)) |
165 updates_for_revision = ( | 165 updates_for_commit = ( |
166 updates if revision is None else updates[:int(revision)]) | 166 updates if commit is None else updates[:int(commit)]) |
167 for update in updates_for_revision: | 167 for update in updates_for_commit: |
168 mock_file_system.Update(update) | 168 mock_file_system.Update(update) |
169 return mock_file_system | 169 return mock_file_system |
170 | 170 |
171 delegate = _TestDelegate(create_file_system) | 171 delegate = _TestDelegate(create_file_system) |
172 delegate.SetAppVersion('2-0-8') | 172 delegate.SetAppVersion('2-0-8') |
173 | 173 |
174 file_systems = delegate.file_systems | 174 file_systems = delegate.file_systems |
175 | 175 |
176 # No updates applied yet. | 176 # No updates applied yet. |
177 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 177 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), | 242 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), |
243 file_systems[-1].ReadSingle(APP_YAML).Get()) | 243 file_systems[-1].ReadSingle(APP_YAML).Get()) |
244 self.assertEqual('<h1>y</h1> u not update!', | 244 self.assertEqual('<h1>y</h1> u not update!', |
245 file_systems[-1].ReadSingle(storage_html_path).Get()) | 245 file_systems[-1].ReadSingle(storage_html_path).Get()) |
246 self.assertEqual('important content!', | 246 self.assertEqual('important content!', |
247 file_systems[-1].ReadSingle(static_txt_path).Get()) | 247 file_systems[-1].ReadSingle(static_txt_path).Get()) |
248 | 248 |
249 | 249 |
250 if __name__ == '__main__': | 250 if __name__ == '__main__': |
251 unittest.main() | 251 unittest.main() |
OLD | NEW |