1 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 """Subclass of CloudBucket used for testing.""" 6 7 from tests.rendering_test_manager import cloud_bucket 8 9 10 class MockCloudBucket(cloud_bucket.CloudBucket): 11 """Subclass of CloudBucket used for testing.""" 12 13 def __init__(self): 14 """Initializes the MockCloudBucket with its datastore. 15 16 Returns: 17 An instance of MockCloudBucket. 18 """ 19 self.datastore = {} 20 21 def Reset(self): 22 """Clears the MockCloudBucket's datastore.""" 23 self.datastore = {} 24 25 # override 26 def UploadFile(self, path, contents, content_type): 27 self.datastore[path] = contents 28 29 # override 30 def DownloadFile(self, path): 31 if self.datastore.has_key(path): 32 return self.datastore[path] 33 else: 34 raise cloud_bucket.FileNotFoundError 35 36 # override 37 def RemoveFile(self, path): 38 if self.datastore.has_key(path): 39 self.datastore.pop(path) 40 41 # override 42 def FileExists(self, path): 43 return self.datastore.has_key(path) 44 45 # override 46 def GetURL(self, path): 47 if self.datastore.has_key(path): 48 return path 49 else: 50 raise cloud_bucket.FileNotFoundError 51 52 # override 53 def GetAllPaths(self, prefix): 54 return (item[0] for item in self.datastore.items() 55 if item[0].startswith(prefix)) 56