← Back to team overview

txaws-dev team mailing list archive

[Merge] lp:~djfroofy/txaws/485535-s3bucketloc into lp:txaws

 

Drew Smathers has proposed merging lp:~djfroofy/txaws/485535-s3bucketloc into lp:txaws with lp:~djfroofy/txaws/640098-amazon-headers as a prerequisite.

Requested reviews:
  txAWS Developers (txaws-dev)
Related bugs:
  #485535 Implement S3 GET Bucket Location
  https://bugs.launchpad.net/bugs/485535

-- 
https://code.launchpad.net/~djfroofy/txaws/485535-s3bucketloc/+merge/35883
Your team txAWS Developers is requested to review the proposed merge of lp:~djfroofy/txaws/485535-s3bucketloc into lp:txaws.
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py	2010-09-17 20:59:45 +0000
+++ txaws/s3/client.py	2010-09-17 20:59:45 +0000
@@ -177,6 +177,19 @@
             name, prefix, marker, max_keys, is_truncated, contents,
             common_prefixes)
 
+
+    def get_bucket_location(self, bucket):
+        query = self.query_factory(
+            action='GET', creds=self.creds, endpoint=self.endpoint,
+            bucket=bucket, object_name='?location')
+        d = query.submit()
+        return d.addCallback(self._parse_bucket_location)
+
+    def _parse_bucket_location(self, xml_bytes):
+        root = XML(xml_bytes)
+        return root.text or '' 
+
+
     def put_object(self, bucket, object_name, data, content_type=None,
                    metadata={}, amz_headers={}):
         """

=== modified file 'txaws/s3/tests/test_client.py'
--- txaws/s3/tests/test_client.py	2010-09-17 20:59:45 +0000
+++ txaws/s3/tests/test_client.py	2010-09-17 20:59:45 +0000
@@ -173,6 +173,33 @@
         s3 = client.S3Client(creds, query_factory=StubQuery)
         d = s3.get_bucket("mybucket")
         return d.addCallback(check_results)
+    
+    def test_get_bucket_location(self):
+
+        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, '?location')
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.sample_get_bucket_location_result)
+
+        def check_results(location_constraint):
+            self.assertEquals(location_constraint, 'EU')
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_location("mybucket")
+        return d.addCallback(check_results)
 
     def test_delete_bucket(self):
 

=== modified file 'txaws/testing/payload.py'
--- txaws/testing/payload.py	2010-07-20 10:15:48 +0000
+++ txaws/testing/payload.py	2010-09-17 20:59:45 +0000
@@ -878,6 +878,11 @@
 </ListBucketResult>
 """ % (version.s3_api,)
 
+sample_get_bucket_location_result = """\
+<?xml version="1.0" encoding="UTF-8"?>
+<LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/";>EU</LocationConstraint>
+"""
+
 sample_s3_signature_mismatch = """\
 <?xml version="1.0" encoding="UTF-8"?>
 <Error>
@@ -903,3 +908,5 @@
   <AWSAccessKeyId>SOMEKEYID</AWSAccessKeyId>
 </Error>
 """
+
+