Index: chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/DependancyInjection/boto_actual_injector.py |
diff --git a/chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/DependancyInjection/boto_actual_injector.py b/chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/DependancyInjection/boto_actual_injector.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..47f9365d8a5e957ef956a0fa6772c1421d1e5d42 |
--- /dev/null |
+++ b/chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/DependancyInjection/boto_actual_injector.py |
@@ -0,0 +1,157 @@ |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Subclass of BotoInjector with actual boto commands.""" |
+ |
+import boto |
+from Tests.BucketManagerTests.DependancyInjection import boto_injector |
+ |
+ |
+class BotoActualInjector(boto_injector.BotoInjector): |
+ """Implements BucketInjector with boto library.""" |
+ |
+ def storage_uri(self, uri_str, default_scheme): |
+ """Returns a boto uri object. |
+ |
+ Args: |
+ uri_str: the uri naming string to connect to. |
+ default_scheme: the type of database to access, in our case: 'gs'. |
+ |
+ Returns: |
+ an instance of boto.storage_uri. |
+ """ |
+ return boto.storage_uri(uri_str, default_scheme) |
+ |
+ def connect(self, uri, key, secret): |
+ """Creates a connection to GCS using a given key and secret. |
+ |
+ Args: |
+ uri: an instance of boto.storage_uri to connect to. |
+ key: the key used to connect to the uri. |
+ secret: the secret used to connect to the uri. |
+ |
+ Returns: |
+ an instance of boto.gs.connection. |
+ """ |
+ return uri.connect(key, secret) |
+ |
+ def get_bucket(self, connection, bucket_name): |
+ """Gets a bucket from a given connection. |
+ |
+ Args: |
+ connection: the connection to retrieve a bucket from. |
+ bucket_name: the name of the bucket to retreive. |
+ |
+ Returns: |
+ an instance of boto.gs.bucket, from which files and folders |
+ can be manipulated. |
+ """ |
+ return connection.get_bucket(bucket_name) |
+ |
+ def get_key(self, bucket): |
+ """Generates a key for a given bucket. |
+ |
+ Args: |
+ bucket: a bucket object to generate a key from. |
+ |
+ Returns: |
+ a key corresponding to a file within the bucket. |
+ """ |
+ return BotoKey(bucket) |
+ |
+ def get_all_keys(self, bucket, prefix): |
+ """Gets all the keys beginning with a prefix in a given bucket. |
+ |
+ Args: |
+ bucket: the bucket to retreive keys from. |
+ prefix: a prefix the a given key must start with to be retrieved. |
+ |
+ Returns: |
+ a list of boto.gs.key objects mapped to the files in the bucket. |
+ """ |
+ return bucket.get_all_keys(prefix=prefix) |
+ |
+ |
+class BotoKey(boto_injector.Key): |
+ """Implements bucket_injector's key class with boto's key.""" |
+ |
+ def __init__(self, bucket): |
+ """Initializes a key with a given bucket. |
+ |
+ Args: |
+ bucket: the bucket from which key will be initialized from. |
+ |
+ Returns: |
+ a boto.gs.key. |
+ """ |
+ self.key = boto.gs.key.Key(bucket) |
+ |
+ def exists(self): |
+ """Returns whether or not a key exists. |
+ |
+ Args: |
+ None. |
+ |
+ Returns: |
+ a boolean representing whether the key exists as a file. |
+ """ |
+ return self.key.exists() |
+ |
+ def set_metadata(self, name, value): |
+ """Sets the meta data of a key. |
+ |
+ Args: |
+ name: the name of the field in the metadata to set. |
+ value: the value to set that field to. |
+ |
+ Returns: |
+ None. |
+ """ |
+ self.key.set_metadata(name, value) |
+ |
+ def set_path(self, path): |
+ """Sets the path that a key points to. |
+ |
+ Args: |
+ path: a path in the bucket to set the key to. |
+ |
+ Returns: |
+ None. |
+ """ |
+ self.key.key = path |
+ |
+ def set_contents_from_string(self, contents): |
+ """Sets the contents of the key, and uploads to GCS. |
+ |
+ Args: |
+ contents: a string to set the contents of the file pointed to by |
+ this key to. |
+ |
+ Returns: |
+ None. |
+ """ |
+ self.key.set_contents_from_string(contents) |
+ |
+ def get_contents_as_string(self): |
+ """Gets the contents of a key from GCS. |
+ |
+ Args: |
+ None. |
+ |
+ Returns: |
+ The contents of the file pointed to by this key. |
+ """ |
+ return self.key.get_contents_as_string() |
+ |
+ def generate_url(self, timeout): |
+ """Returns a url to a GCS file that expires according to timeout. |
+ |
+ Args: |
+ timeout: the amount of time allowed to pass before the generated |
+ url expires. |
+ |
+ Returns: |
+ a string representing a url to a file in the bucket. |
+ """ |
+ return self.key.generate_url(timeout) |