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 |
(...skipping 13 matching lines...) Expand all Loading... |
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 CreateHostFileSystemCreator(self, object_store_creator): |
34 def constructor(branch, revision=None): | 34 def constructor(branch=None, revision=None): |
35 file_system = self._create_file_system(branch, revision) | 35 file_system = self._create_file_system(revision) |
36 self.file_systems.append(file_system) | 36 self.file_systems.append(file_system) |
37 return file_system | 37 return file_system |
38 return HostFileSystemCreator(object_store_creator, | 38 return HostFileSystemCreator(object_store_creator, |
39 constructor_for_test=constructor) | 39 constructor_for_test=constructor) |
40 | 40 |
41 def CreateAppSamplesFileSystem(self, object_store_creator): | 41 def CreateAppSamplesFileSystem(self, object_store_creator): |
42 return EmptyDirFileSystem() | 42 return EmptyDirFileSystem() |
43 | 43 |
44 def GetAppVersion(self): | 44 def GetAppVersion(self): |
45 return self._app_version | 45 return self._app_version |
46 | 46 |
47 # (non-Delegate method). | 47 # (non-Delegate method). |
48 def SetAppVersion(self, app_version): | 48 def SetAppVersion(self, app_version): |
49 self._app_version = app_version | 49 self._app_version = app_version |
50 | 50 |
51 class CronServletTest(unittest.TestCase): | 51 class CronServletTest(unittest.TestCase): |
52 @EnableLogging('info') | 52 @EnableLogging('info') |
53 def testEverything(self): | 53 def testEverything(self): |
54 # All these tests are dependent (see above comment) so lump everything in | 54 # All these tests are dependent (see above comment) so lump everything in |
55 # the one test. | 55 # the one test. |
56 delegate = _TestDelegate( | 56 delegate = _TestDelegate(lambda _: MockFileSystem(LocalFileSystem.Create())) |
57 lambda _, __: MockFileSystem(LocalFileSystem.Create())) | |
58 | 57 |
59 # Test that the cron runs successfully. | 58 # Test that the cron runs successfully. |
60 response = CronServlet(Request.ForTest('trunk'), | 59 response = CronServlet(Request.ForTest('trunk'), |
61 delegate_for_test=delegate).Get() | 60 delegate_for_test=delegate).Get() |
62 self.assertEqual(200, response.status) | 61 self.assertEqual(200, response.status) |
63 | 62 |
64 # Save the file systems created, start with a fresh set for the next run. | 63 # Save the file systems created, start with a fresh set for the next run. |
65 first_run_file_systems = delegate.file_systems[:] | 64 first_run_file_systems = delegate.file_systems[:] |
66 delegate.file_systems[:] = [] | 65 delegate.file_systems[:] = [] |
67 | 66 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 }}}}} | 114 }}}}} |
116 def static_txt_update(update): | 115 def static_txt_update(update): |
117 return {'docs': {'static': { | 116 return {'docs': {'static': { |
118 'static.txt': update | 117 'static.txt': update |
119 }}} | 118 }}} |
120 | 119 |
121 app_yaml_path = 'docs/server2/app.yaml' | 120 app_yaml_path = 'docs/server2/app.yaml' |
122 storage_html_path = 'docs/templates/public/apps/storage.html' | 121 storage_html_path = 'docs/templates/public/apps/storage.html' |
123 static_txt_path = 'docs/static/static.txt' | 122 static_txt_path = 'docs/static/static.txt' |
124 | 123 |
125 def create_file_system(branch, revision=None): | 124 def create_file_system(revision=None): |
126 '''Creates a MockFileSystem at |revision| by applying that many |updates| | 125 '''Creates a MockFileSystem at |revision| by applying that many |updates| |
127 to it. | 126 to it. |
128 ''' | 127 ''' |
129 mock_file_system = MockFileSystem(TestFileSystem(test_data)) | 128 mock_file_system = MockFileSystem(TestFileSystem(test_data)) |
130 for update in updates[:revision]: | 129 for update in updates[:revision]: |
131 mock_file_system.Update(update) | 130 mock_file_system.Update(update) |
132 return mock_file_system | 131 return mock_file_system |
133 | 132 |
134 delegate = _TestDelegate(create_file_system) | 133 delegate = _TestDelegate(create_file_system) |
135 delegate.SetAppVersion('2-0-8') | 134 delegate.SetAppVersion('2-0-8') |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 203 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
205 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), | 204 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), |
206 file_systems[-1].ReadSingle(app_yaml_path)) | 205 file_systems[-1].ReadSingle(app_yaml_path)) |
207 self.assertEqual('y u not update!', | 206 self.assertEqual('y u not update!', |
208 file_systems[-1].ReadSingle(storage_html_path)) | 207 file_systems[-1].ReadSingle(storage_html_path)) |
209 self.assertEqual('important content!', | 208 self.assertEqual('important content!', |
210 file_systems[-1].ReadSingle(static_txt_path)) | 209 file_systems[-1].ReadSingle(static_txt_path)) |
211 | 210 |
212 if __name__ == '__main__': | 211 if __name__ == '__main__': |
213 unittest.main() | 212 unittest.main() |
OLD | NEW |