| 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 extensions_paths import ( |
| 13 APP_YAML, CONTENT_PROVIDERS, EXTENSIONS, PUBLIC_TEMPLATES, SERVER2, |
| 14 STATIC_DOCS) |
| 12 from github_file_system_provider import GithubFileSystemProvider | 15 from github_file_system_provider import GithubFileSystemProvider |
| 13 from host_file_system_provider import HostFileSystemProvider | 16 from host_file_system_provider import HostFileSystemProvider |
| 14 from local_file_system import LocalFileSystem | 17 from local_file_system import LocalFileSystem |
| 15 from mock_file_system import MockFileSystem | 18 from mock_file_system import MockFileSystem |
| 16 from servlet import Request | 19 from servlet import Request |
| 17 from svn_constants import JSON_PATH | |
| 18 from test_branch_utility import TestBranchUtility | 20 from test_branch_utility import TestBranchUtility |
| 19 from test_file_system import TestFileSystem | 21 from test_file_system import MoveTo, TestFileSystem |
| 20 from test_util import EnableLogging, ReadFile | 22 from test_util import EnableLogging, ReadFile |
| 21 | 23 |
| 24 |
| 22 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our | 25 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our |
| 23 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, | 26 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course, |
| 24 # if the host file systems have different identities, they will be, sort of. | 27 # if the host file systems have different identities, they will be, sort of. |
| 25 class _TestDelegate(CronServlet.Delegate): | 28 class _TestDelegate(CronServlet.Delegate): |
| 26 def __init__(self, create_file_system): | 29 def __init__(self, create_file_system): |
| 27 self.file_systems = [] | 30 self.file_systems = [] |
| 28 # A callback taking a revision and returning a file system. | 31 # A callback taking a revision and returning a file system. |
| 29 self._create_file_system = create_file_system | 32 self._create_file_system = create_file_system |
| 30 self._app_version = GetAppVersion() | 33 self._app_version = GetAppVersion() |
| 31 | 34 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 'templates': { | 105 'templates': { |
| 103 'public': { | 106 'public': { |
| 104 'apps': { | 107 'apps': { |
| 105 'storage.html': 'storage.html contents' | 108 'storage.html': 'storage.html contents' |
| 106 }, | 109 }, |
| 107 'extensions': { | 110 'extensions': { |
| 108 'storage.html': 'storage.html contents' | 111 'storage.html': 'storage.html contents' |
| 109 }, | 112 }, |
| 110 }, | 113 }, |
| 111 'json': { | 114 'json': { |
| 112 'content_providers.json': ReadFile('%s/content_providers.json' % | 115 'content_providers.json': ReadFile(CONTENT_PROVIDERS), |
| 113 JSON_PATH), | |
| 114 'manifest.json': '{}', | 116 'manifest.json': '{}', |
| 115 'permissions.json': '{}', | 117 'permissions.json': '{}', |
| 116 'strings.json': '{}', | 118 'strings.json': '{}', |
| 117 'apps_sidenav.json': '{}', | 119 'apps_sidenav.json': '{}', |
| 118 'extensions_sidenav.json': '{}', | 120 'extensions_sidenav.json': '{}', |
| 119 }, | 121 }, |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 updates = [] | 126 updates = [] |
| 125 | 127 |
| 126 def app_yaml_update(version): | 128 def app_yaml_update(version): |
| 127 return {'docs': {'server2': { | 129 return MoveTo(SERVER2, { |
| 128 'app.yaml': AppYamlHelper.GenerateAppYaml(version) | 130 'app.yaml': AppYamlHelper.GenerateAppYaml(version) |
| 129 }}} | 131 }) |
| 130 def storage_html_update(update): | 132 def storage_html_update(update): |
| 131 return {'docs': {'templates': {'public': {'apps': { | 133 return MoveTo(PUBLIC_TEMPLATES, { |
| 132 'storage.html': update | 134 'apps': {'storage.html': update} |
| 133 }}}}} | 135 }) |
| 134 def static_txt_update(update): | 136 def static_txt_update(update): |
| 135 return {'docs': {'static': { | 137 return MoveTo(STATIC_DOCS, { |
| 136 'static.txt': update | 138 'static.txt': update |
| 137 }}} | 139 }) |
| 138 | 140 |
| 139 app_yaml_path = 'docs/server2/app.yaml' | 141 storage_html_path = '%s/apps/storage.html' % PUBLIC_TEMPLATES |
| 140 storage_html_path = 'docs/templates/public/apps/storage.html' | 142 static_txt_path = '%s/static.txt' % STATIC_DOCS |
| 141 static_txt_path = 'docs/static/static.txt' | |
| 142 | 143 |
| 143 def create_file_system(revision=None): | 144 def create_file_system(revision=None): |
| 144 '''Creates a MockFileSystem at |revision| by applying that many |updates| | 145 '''Creates a MockFileSystem at |revision| by applying that many |updates| |
| 145 to it. | 146 to it. |
| 146 ''' | 147 ''' |
| 147 mock_file_system = MockFileSystem(TestFileSystem(test_data)) | 148 mock_file_system = MockFileSystem( |
| 149 TestFileSystem(test_data, relative_to=EXTENSIONS)) |
| 148 updates_for_revision = ( | 150 updates_for_revision = ( |
| 149 updates if revision is None else updates[:int(revision)]) | 151 updates if revision is None else updates[:int(revision)]) |
| 150 for update in updates_for_revision: | 152 for update in updates_for_revision: |
| 151 mock_file_system.Update(update) | 153 mock_file_system.Update(update) |
| 152 return mock_file_system | 154 return mock_file_system |
| 153 | 155 |
| 154 delegate = _TestDelegate(create_file_system) | 156 delegate = _TestDelegate(create_file_system) |
| 155 delegate.SetAppVersion('2-0-8') | 157 delegate.SetAppVersion('2-0-8') |
| 156 | 158 |
| 157 file_systems = delegate.file_systems | 159 file_systems = delegate.file_systems |
| 158 | 160 |
| 159 # No updates applied yet. | 161 # No updates applied yet. |
| 160 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 162 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 161 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), | 163 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), |
| 162 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 164 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 163 self.assertEqual('storage.html contents', | 165 self.assertEqual('storage.html contents', |
| 164 file_systems[-1].ReadSingle(storage_html_path).Get()) | 166 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 165 | 167 |
| 166 # Apply updates to storage.html. | 168 # Apply updates to storage.html. |
| 167 updates.append(storage_html_update('interim contents')) | 169 updates.append(storage_html_update('interim contents')) |
| 168 updates.append(storage_html_update('new contents')) | 170 updates.append(storage_html_update('new contents')) |
| 169 | 171 |
| 170 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 172 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 171 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), | 173 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), |
| 172 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 174 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 173 self.assertEqual('new contents', | 175 self.assertEqual('new contents', |
| 174 file_systems[-1].ReadSingle(storage_html_path).Get()) | 176 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 175 | 177 |
| 176 # Apply several updates to storage.html and app.yaml. The file system | 178 # Apply several updates to storage.html and app.yaml. The file system |
| 177 # should be pinned at the version before app.yaml changed. | 179 # should be pinned at the version before app.yaml changed. |
| 178 updates.append(storage_html_update('stuck here contents')) | 180 updates.append(storage_html_update('stuck here contents')) |
| 179 | 181 |
| 180 double_update = storage_html_update('newer contents') | 182 double_update = storage_html_update('newer contents') |
| 181 double_update.update(app_yaml_update('2-0-10')) | 183 double_update.update(app_yaml_update('2-0-10')) |
| 182 updates.append(double_update) | 184 updates.append(double_update) |
| 183 | 185 |
| 184 updates.append(storage_html_update('never gonna reach here')) | 186 updates.append(storage_html_update('never gonna reach here')) |
| 185 | 187 |
| 186 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 188 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 187 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), | 189 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), |
| 188 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 190 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 189 self.assertEqual('stuck here contents', | 191 self.assertEqual('stuck here contents', |
| 190 file_systems[-1].ReadSingle(storage_html_path).Get()) | 192 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 191 | 193 |
| 192 # Further pushes to storage.html will keep it pinned. | 194 # Further pushes to storage.html will keep it pinned. |
| 193 updates.append(storage_html_update('y u not update!')) | 195 updates.append(storage_html_update('y u not update!')) |
| 194 | 196 |
| 195 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 197 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 196 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), | 198 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), |
| 197 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 199 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 198 self.assertEqual('stuck here contents', | 200 self.assertEqual('stuck here contents', |
| 199 file_systems[-1].ReadSingle(storage_html_path).Get()) | 201 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 200 | 202 |
| 201 # Likewise app.yaml. | 203 # Likewise app.yaml. |
| 202 updates.append(app_yaml_update('2-1-0')) | 204 updates.append(app_yaml_update('2-1-0')) |
| 203 | 205 |
| 204 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 206 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 205 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), | 207 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), |
| 206 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 208 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 207 self.assertEqual('stuck here contents', | 209 self.assertEqual('stuck here contents', |
| 208 file_systems[-1].ReadSingle(storage_html_path).Get()) | 210 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 209 | 211 |
| 210 # And updates to other content won't happen either. | 212 # And updates to other content won't happen either. |
| 211 updates.append(static_txt_update('important content!')) | 213 updates.append(static_txt_update('important content!')) |
| 212 | 214 |
| 213 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 215 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 214 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), | 216 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'), |
| 215 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 217 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 216 self.assertEqual('stuck here contents', | 218 self.assertEqual('stuck here contents', |
| 217 file_systems[-1].ReadSingle(storage_html_path).Get()) | 219 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 218 self.assertEqual('static.txt contents', | 220 self.assertEqual('static.txt contents', |
| 219 file_systems[-1].ReadSingle(static_txt_path).Get()) | 221 file_systems[-1].ReadSingle(static_txt_path).Get()) |
| 220 | 222 |
| 221 # Lastly - when the app version changes, everything should no longer be | 223 # Lastly - when the app version changes, everything should no longer be |
| 222 # pinned. | 224 # pinned. |
| 223 delegate.SetAppVersion('2-1-0') | 225 delegate.SetAppVersion('2-1-0') |
| 224 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() | 226 CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get() |
| 225 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), | 227 self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'), |
| 226 file_systems[-1].ReadSingle(app_yaml_path).Get()) | 228 file_systems[-1].ReadSingle(APP_YAML).Get()) |
| 227 self.assertEqual('y u not update!', | 229 self.assertEqual('y u not update!', |
| 228 file_systems[-1].ReadSingle(storage_html_path).Get()) | 230 file_systems[-1].ReadSingle(storage_html_path).Get()) |
| 229 self.assertEqual('important content!', | 231 self.assertEqual('important content!', |
| 230 file_systems[-1].ReadSingle(static_txt_path).Get()) | 232 file_systems[-1].ReadSingle(static_txt_path).Get()) |
| 231 | 233 |
| 232 if __name__ == '__main__': | 234 if __name__ == '__main__': |
| 233 unittest.main() | 235 unittest.main() |
| OLD | NEW |