← Back to team overview

txaws-dev team mailing list archive

[Merge] lp:~dreamhosters/txaws/921352-get-bucket-versioning-method into lp:txaws

 

Arsene Rei has proposed merging lp:~dreamhosters/txaws/921352-get-bucket-versioning-method into lp:txaws.

Requested reviews:
  txAWS Technical List (txaws-tech)
Related bugs:
  Bug #921352 in txAWS: "S3: Add GET Bucket versioning method"
  https://bugs.launchpad.net/txaws/+bug/921352

For more details, see:
https://code.launchpad.net/~dreamhosters/txaws/921352-get-bucket-versioning-method/+merge/90552

Add GET Bucket versioning functionality
-- 
https://code.launchpad.net/~dreamhosters/txaws/921352-get-bucket-versioning-method/+merge/90552
Your team txAWS Technical List is requested to review the proposed merge of lp:~dreamhosters/txaws/921352-get-bucket-versioning-method into lp:txaws.
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py	2012-01-27 19:54:27 +0000
+++ txaws/s3/client.py	2012-01-27 23:08:23 +0000
@@ -23,7 +23,7 @@
 from txaws.s3.model import (
     Bucket, BucketItem, BucketListing, ItemOwner, LifecycleConfiguration,
     LifecycleConfigurationRule, NotificationConfiguration, RequestPayment,
-    WebsiteConfiguration)
+    VersioningConfiguration, WebsiteConfiguration)
 from txaws.s3.exception import S3Error
 from txaws.service import AWSServiceEndpoint, S3_ENDPOINT
 from txaws.util import XML, calculate_md5
@@ -253,6 +253,25 @@
 
         return NotificationConfiguration(topic, event)
 
+    def get_bucket_versioning_config(self, bucket):
+        """
+        Get the versioning configuration of a bucket.
+
+        @param bucket: The name of the bucket.  @return: A C{Deferred} that
+        will request the bucket's versioning configuration.
+        """
+        query = self.query_factory(
+            action='GET', creds=self.creds, endpoint=self.endpoint,
+            bucket=bucket, object_name='?versioning')
+        return query.submit().addCallback(self._parse_versioning_config)
+
+    def _parse_versioning_config(self, xml_bytes):
+        """Parse a C{VersioningConfiguration} XML document."""
+        root = XML(xml_bytes)
+        status = root.findtext("Status")
+
+        return VersioningConfiguration(status)
+
     def get_bucket_acl(self, bucket):
         """
         Get the access control policy for a bucket.

=== modified file 'txaws/s3/model.py'
--- txaws/s3/model.py	2012-01-27 19:47:22 +0000
+++ txaws/s3/model.py	2012-01-27 23:08:23 +0000
@@ -90,6 +90,14 @@
         self.event = event
 
 
+class VersioningConfiguration(object):
+    """
+    Container for the bucket versioning configuration.
+    """
+    def __init__(self, status=None):
+        self.status = status
+
+
 class FileChunk(object):
     """
     An Amazon S3 file chunk.

=== modified file 'txaws/s3/tests/test_client.py'
--- txaws/s3/tests/test_client.py	2012-01-27 20:44:11 +0000
+++ txaws/s3/tests/test_client.py	2012-01-27 23:08:23 +0000
@@ -462,6 +462,115 @@
         d = s3.get_bucket_notification_config("mybucket")
         return d.addCallback(check_results)
 
+    def test_get_bucket_versioning_config(self):
+        """
+        L{S3Client.get_bucket_versioning_configuration} creates a L{Query} to
+        get a bucket's versioning status.  It parses the returned
+        C{VersioningConfiguration} XML document and returns a C{Deferred} that
+        requests the bucket's versioning configuration.
+        """
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name)
+                self.assertEquals(action, "GET")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "?versioning")
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.sample_s3_get_bucket_versioning_result)
+
+        def check_results(versioning_config):
+            self.assertEquals(versioning_config.status, None)
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_versioning_config("mybucket")
+        return d.addCallback(check_results)
+
+    def test_get_bucket_versioning_config_enabled(self):
+        """
+        L{S3Client.get_bucket_versioning_config} creates a L{Query} to get a
+        bucket's versioning configuration.  It parses the returned
+        C{VersioningConfiguration} XML document and returns a C{Deferred} that
+        requests the bucket's versioning configuration that has a enabled
+        status.
+        """
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name)
+                self.assertEquals(action, "GET")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "?versioning")
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.
+                               sample_s3_get_bucket_versioning_enabled_result)
+
+        def check_results(versioning_config):
+            self.assertEquals(versioning_config.status, 'Enabled')
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_versioning_config("mybucket")
+        return d.addCallback(check_results)
+
+    def test_get_bucket_versioning_config_suspended(self):
+        """
+        L{S3Client.get_bucket_versioning_config} creates a L{Query} to get a
+        bucket's versioning configuration.  It parses the returned
+        C{VersioningConfiguration} XML document and returns a C{Deferred} that
+        requests the bucket's versioning configuration that has a suspended
+        status.
+        """
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name)
+                self.assertEquals(action, "GET")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "?versioning")
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.
+                               sample_s3_get_bucket_versioning_suspended_result)
+
+        def check_results(versioning_config):
+            self.assertEquals(versioning_config.status, 'Suspended')
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_versioning_config("mybucket")
+        return d.addCallback(check_results)
+
     def test_delete_bucket(self):
 
         class StubQuery(client.Query):

=== modified file 'txaws/testing/payload.py'
--- txaws/testing/payload.py	2012-01-27 20:08:20 +0000
+++ txaws/testing/payload.py	2012-01-27 23:08:23 +0000
@@ -1071,3 +1071,16 @@
        <Event>s3:ReducedRedundancyLostObject</Event>
    </TopicConfiguration>
 </NotificationConfiguration>"""
+
+sample_s3_get_bucket_versioning_result = """\
+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"/>"""
+
+sample_s3_get_bucket_versioning_enabled_result = """\
+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/";>
+  <Status>Enabled</Status>
+</VersioningConfiguration>"""
+
+sample_s3_get_bucket_versioning_suspended_result = """\
+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/";>
+  <Status>Suspended</Status>
+</VersioningConfiguration>"""