| OLD | NEW |
| 1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides stubs for os, sys and subprocess for testing | 5 """Provides stubs for os, sys and subprocess for testing |
| 6 | 6 |
| 7 This test allows one to test code that itself uses os, sys, and subprocess. | 7 This test allows one to test code that itself uses os, sys, and subprocess. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 pass | 175 pass |
| 176 | 176 |
| 177 def __init__(self): | 177 def __init__(self): |
| 178 self.default_remote_paths = {CloudStorageModuleStub.INTERNAL_BUCKET:{}, | 178 self.default_remote_paths = {CloudStorageModuleStub.INTERNAL_BUCKET:{}, |
| 179 CloudStorageModuleStub.PARTNER_BUCKET:{}, | 179 CloudStorageModuleStub.PARTNER_BUCKET:{}, |
| 180 CloudStorageModuleStub.PUBLIC_BUCKET:{}} | 180 CloudStorageModuleStub.PUBLIC_BUCKET:{}} |
| 181 self.remote_paths = self.default_remote_paths | 181 self.remote_paths = self.default_remote_paths |
| 182 self.local_file_hashes = {} | 182 self.local_file_hashes = {} |
| 183 self.local_hash_files = {} | 183 self.local_hash_files = {} |
| 184 self.permission_level = CloudStorageModuleStub.INTERNAL_PERMISSION | 184 self.permission_level = CloudStorageModuleStub.INTERNAL_PERMISSION |
| 185 self.downloaded_files = [] |
| 185 | 186 |
| 186 def SetPermissionLevelForTesting(self, permission_level): | 187 def SetPermissionLevelForTesting(self, permission_level): |
| 187 self.permission_level = permission_level | 188 self.permission_level = permission_level |
| 188 | 189 |
| 189 def CheckPermissionLevelForBucket(self, bucket): | 190 def CheckPermissionLevelForBucket(self, bucket): |
| 190 if bucket == CloudStorageModuleStub.PUBLIC_BUCKET: | 191 if bucket == CloudStorageModuleStub.PUBLIC_BUCKET: |
| 191 return | 192 return |
| 192 elif (self.permission_level == | 193 elif (self.permission_level == |
| 193 CloudStorageModuleStub.CREDENTIALS_ERROR_PERMISSION): | 194 CloudStorageModuleStub.CREDENTIALS_ERROR_PERMISSION): |
| 194 raise CloudStorageModuleStub.CredentialsError() | 195 raise CloudStorageModuleStub.CredentialsError() |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 def GetHelper(self, bucket, remote_path, local_path, only_if_changed): | 254 def GetHelper(self, bucket, remote_path, local_path, only_if_changed): |
| 254 CloudStorageModuleStub.CheckPermissionLevelForBucket(self, bucket) | 255 CloudStorageModuleStub.CheckPermissionLevelForBucket(self, bucket) |
| 255 if not remote_path in self.remote_paths[bucket]: | 256 if not remote_path in self.remote_paths[bucket]: |
| 256 if only_if_changed: | 257 if only_if_changed: |
| 257 return False | 258 return False |
| 258 raise CloudStorageModuleStub.NotFoundError('Remote file does not exist.') | 259 raise CloudStorageModuleStub.NotFoundError('Remote file does not exist.') |
| 259 remote_hash = self.remote_paths[bucket][remote_path] | 260 remote_hash = self.remote_paths[bucket][remote_path] |
| 260 local_hash = self.local_file_hashes[local_path] | 261 local_hash = self.local_file_hashes[local_path] |
| 261 if only_if_changed and remote_hash == local_hash: | 262 if only_if_changed and remote_hash == local_hash: |
| 262 return False | 263 return False |
| 264 self.downloaded_files.append(remote_path) |
| 263 self.local_file_hashes[local_path] = remote_hash | 265 self.local_file_hashes[local_path] = remote_hash |
| 264 self.local_hash_files[local_path + '.sha1'] = remote_hash | 266 self.local_hash_files[local_path + '.sha1'] = remote_hash |
| 265 return remote_hash | 267 return remote_hash |
| 266 | 268 |
| 267 def Get(self, bucket, remote_path, local_path): | 269 def Get(self, bucket, remote_path, local_path): |
| 268 return CloudStorageModuleStub.GetHelper(self, bucket, remote_path, | 270 return CloudStorageModuleStub.GetHelper(self, bucket, remote_path, |
| 269 local_path, False) | 271 local_path, False) |
| 270 | 272 |
| 271 def GetIfChanged(self, local_path, bucket=None): | 273 def GetIfChanged(self, local_path, bucket=None): |
| 272 remote_path = os.path.basename(local_path) | 274 remote_path = os.path.basename(local_path) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 class AdbInstallCertStub(object): | 493 class AdbInstallCertStub(object): |
| 492 class AndroidCertInstaller(object): | 494 class AndroidCertInstaller(object): |
| 493 def __init__(self, device_id, _cert_name, _cert_path): | 495 def __init__(self, device_id, _cert_name, _cert_path): |
| 494 if device_id == 'success': | 496 if device_id == 'success': |
| 495 pass | 497 pass |
| 496 elif device_id == 'failure': | 498 elif device_id == 'failure': |
| 497 raise Exception('Test exception.') | 499 raise Exception('Test exception.') |
| 498 | 500 |
| 499 def install_cert(self, overwrite_cert=False): | 501 def install_cert(self, overwrite_cert=False): |
| 500 pass | 502 pass |
| OLD | NEW |