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.
5 """Subclass of CloudBucket used for testing."""
10 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
14 class MockCloudBucket(cloud_bucket.BaseCloudBucket):
15 """Subclass of CloudBucket used for testing."""
18 """Initializes the MockCloudBucket with its datastore.
21 An instance of MockCloudBucket.
26 """Clears the MockCloudBucket's datastore."""
30 def UploadFile(self, path, contents, content_type):
31 self.datastore[path] = contents
34 def DownloadFile(self, path):
35 if self.datastore.has_key(path):
36 return self.datastore[path]
38 raise cloud_bucket.FileNotFoundError
41 def UpdateFile(self, path, contents):
42 if not self.FileExists(path):
43 raise cloud_bucket.FileNotFoundError
44 self.UploadFile(path, contents, '')
47 def RemoveFile(self, path):
48 if self.datastore.has_key(path):
49 self.datastore.pop(path)
52 def FileExists(self, path):
53 return self.datastore.has_key(path)
56 def GetImageURL(self, path):
57 if self.datastore.has_key(path):
60 raise cloud_bucket.FileNotFoundError
63 def GetAllPaths(self, prefix):
64 return (item[0] for item in self.datastore.items()
65 if item[0].startswith(prefix))