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 13 matching lines...) Expand all Loading... |
24 from test_file_system import MoveTo, TestFileSystem | 24 from test_file_system import MoveTo, TestFileSystem |
25 from test_util import EnableLogging, ReadFile | 25 from test_util import EnableLogging, ReadFile |
26 | 26 |
27 | 27 |
28 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our | 28 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our |
29 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, | 29 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, |
30 # if the host file systems have different identities, they will be, sort of. | 30 # if the host file systems have different identities, they will be, sort of. |
31 class _TestDelegate(CronServlet.Delegate): | 31 class _TestDelegate(CronServlet.Delegate): |
32 def __init__(self, create_file_system): | 32 def __init__(self, create_file_system): |
33 self.file_systems = [] | 33 self.file_systems = [] |
34 # A callback taking a revision and returning a file system. | 34 # A callback taking a commit and returning a file system. |
35 self._create_file_system = create_file_system | 35 self._create_file_system = create_file_system |
36 self._app_version = GetAppVersion() | 36 self._app_version = GetAppVersion() |
37 | 37 |
38 def CreateBranchUtility(self, object_store_creator): | 38 def CreateBranchUtility(self, object_store_creator): |
39 return TestBranchUtility.CreateWithCannedData() | 39 return TestBranchUtility.CreateWithCannedData() |
40 | 40 |
41 def CreateHostFileSystemProvider(self, | 41 def CreateHostFileSystemProvider(self, |
42 object_store_creator, | 42 object_store_creator, |
43 max_trunk_revision=None): | 43 pinned_commit=None): |
44 def constructor(branch=None, revision=None): | 44 def constructor(branch=None, commit=None): |
45 file_system = self._create_file_system(revision) | 45 file_system = self._create_file_system(commit) |
46 self.file_systems.append(file_system) | 46 self.file_systems.append(file_system) |
47 return file_system | 47 return file_system |
48 return HostFileSystemProvider(object_store_creator, | 48 return HostFileSystemProvider(object_store_creator, |
49 max_trunk_revision=max_trunk_revision, | 49 pinned_commit=pinned_commit, |
50 constructor_for_test=constructor) | 50 constructor_for_test=constructor) |
51 | 51 |
52 def CreateGithubFileSystemProvider(self, object_store_creator): | 52 def CreateGithubFileSystemProvider(self, object_store_creator): |
53 return GithubFileSystemProvider.ForEmpty() | 53 return GithubFileSystemProvider.ForEmpty() |
54 | 54 |
55 def CreateGCSFileSystemProvider(self, object_store_creator): | 55 def CreateGCSFileSystemProvider(self, object_store_creator): |
56 return CloudStorageFileSystemProvider.ForEmpty() | 56 return CloudStorageFileSystemProvider.ForEmpty() |
57 | 57 |
58 def GetAppVersion(self): | 58 def GetAppVersion(self): |
59 return self._app_version | 59 return self._app_version |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 'apps': {'storage.html': update} | 167 'apps': {'storage.html': update} |
168 }) | 168 }) |
169 def static_txt_update(update): | 169 def static_txt_update(update): |
170 return MoveTo(STATIC_DOCS, { | 170 return MoveTo(STATIC_DOCS, { |
171 'static.txt': update | 171 'static.txt': update |
172 }) | 172 }) |
173 | 173 |
174 storage_html_path = PUBLIC_TEMPLATES + 'apps/storage.html' | 174 storage_html_path = PUBLIC_TEMPLATES + 'apps/storage.html' |
175 static_txt_path = STATIC_DOCS + 'static.txt' | 175 static_txt_path = STATIC_DOCS + 'static.txt' |
176 | 176 |
177 def create_file_system(revision=None): | 177 def create_file_system(commit=None): |
178 '''Creates a MockFileSystem at |revision| by applying that many |updates| | 178 '''Creates a MockFileSystem at |commit| by applying that many |updates| |
179 to it. | 179 to it. |
180 ''' | 180 ''' |
181 mock_file_system = MockFileSystem(TestFileSystem(test_data)) | 181 mock_file_system = MockFileSystem(TestFileSystem(test_data)) |
182 updates_for_revision = ( | 182 updates_for_commit = ( |
183 updates if revision is None else updates[:int(revision)]) | 183 updates if commit is None else updates[:int(commit)]) |
184 for update in updates_for_revision: | 184 for update in updates_for_commit: |
185 mock_file_system.Update(update) | 185 mock_file_system.Update(update) |
186 return mock_file_system | 186 return mock_file_system |
187 | 187 |
188 delegate = _TestDelegate(create_file_system) | 188 delegate = _TestDelegate(create_file_system) |
189 delegate.SetAppVersion('2-0-8') | 189 delegate.SetAppVersion('2-0-8') |
190 | 190 |
191 file_systems = delegate.file_systems | 191 file_systems = delegate.file_systems |
192 | 192 |
193 # No updates applied yet. | 193 # No updates applied yet. |
194 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 194 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), | 259 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), |
260 file_systems[-1].ReadSingle(APP_YAML).Get()) | 260 file_systems[-1].ReadSingle(APP_YAML).Get()) |
261 self.assertEqual('<h1>y</h1> u not update!', | 261 self.assertEqual('<h1>y</h1> u not update!', |
262 file_systems[-1].ReadSingle(storage_html_path).Get()) | 262 file_systems[-1].ReadSingle(storage_html_path).Get()) |
263 self.assertEqual('important content!', | 263 self.assertEqual('important content!', |
264 file_systems[-1].ReadSingle(static_txt_path).Get()) | 264 file_systems[-1].ReadSingle(static_txt_path).Get()) |
265 | 265 |
266 | 266 |
267 if __name__ == '__main__': | 267 if __name__ == '__main__': |
268 unittest.main() | 268 unittest.main() |
OLD | NEW |