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

Proposed by Arsene Rei
Status: Merged
Approved by: Duncan McGreggor
Approved revision: 141
Merged at revision: 130
Proposed branch: lp:~dreamhosters/txaws/921352-get-bucket-versioning-method
Merge into: lp:txaws
Diff against target: 212 lines (+164/-1)
4 files modified
txaws/s3/client.py (+21/-1)
txaws/s3/model.py (+19/-0)
txaws/s3/tests/test_client.py (+110/-0)
txaws/testing/payload.py (+14/-0)
To merge this branch: bzr merge lp:~dreamhosters/txaws/921352-get-bucket-versioning-method
Reviewer Review Type Date Requested Status
Duncan McGreggor Approve
Review via email: mp+90552@code.launchpad.net

Description of the change

Add GET Bucket versioning functionality

To post a comment you must log in.
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

[1] So, I was going to suggest not to use modeling for this one, since it's so simple... but it seems that Amazon has defined another element that needs to be added to the module: MfaDelete (self.mfa_delete is the attribute name I'd use).

I was going to suggest that you should only set the mfa_delete attr if root.findtext("MfaDelete") returned a value... but that would make working with this particular model more cumbersome. So:
 * mfa_delete = "Disabled" means the bucket has been configured with MfaDelete and it's disabled
 * mfa_delete = "Enabled" means the bucket has been configured with MfaDelete and it's enabled
 * mfa_delete = None means the bucket has not been configured with MfaDelete

That should probably go in the model's docstring ;-)

[2] For this, you'll want to add another payload example with "<MfaDelete>Enabled</MfaDelete>" in it. There's no need to also include an example Disabled in it, since no different/additional logic in the Python code is being exercised with that.

review: Needs Fixing
138. By Arsene Rei

remove test_get_bucket_versioning_config_suspended

As oubiwann pointed out, no additional logic in Python code is being exercised.

139. By Arsene Rei

add mfa_delete argument to VersioningConfiguration

* add corresponding test

140. By Arsene Rei

make pep8 fix

141. By Arsene Rei

update test docstring

Revision history for this message
Duncan McGreggor (oubiwann) wrote :

Looks good! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py 2012-01-27 19:54:27 +0000
+++ txaws/s3/client.py 2012-01-28 00:47:23 +0000
@@ -23,7 +23,7 @@
23from txaws.s3.model import (23from txaws.s3.model import (
24 Bucket, BucketItem, BucketListing, ItemOwner, LifecycleConfiguration,24 Bucket, BucketItem, BucketListing, ItemOwner, LifecycleConfiguration,
25 LifecycleConfigurationRule, NotificationConfiguration, RequestPayment,25 LifecycleConfigurationRule, NotificationConfiguration, RequestPayment,
26 WebsiteConfiguration)26 VersioningConfiguration, WebsiteConfiguration)
27from txaws.s3.exception import S3Error27from txaws.s3.exception import S3Error
28from txaws.service import AWSServiceEndpoint, S3_ENDPOINT28from txaws.service import AWSServiceEndpoint, S3_ENDPOINT
29from txaws.util import XML, calculate_md529from txaws.util import XML, calculate_md5
@@ -253,6 +253,26 @@
253253
254 return NotificationConfiguration(topic, event)254 return NotificationConfiguration(topic, event)
255255
256 def get_bucket_versioning_config(self, bucket):
257 """
258 Get the versioning configuration of a bucket.
259
260 @param bucket: The name of the bucket. @return: A C{Deferred} that
261 will request the bucket's versioning configuration.
262 """
263 query = self.query_factory(
264 action='GET', creds=self.creds, endpoint=self.endpoint,
265 bucket=bucket, object_name='?versioning')
266 return query.submit().addCallback(self._parse_versioning_config)
267
268 def _parse_versioning_config(self, xml_bytes):
269 """Parse a C{VersioningConfiguration} XML document."""
270 root = XML(xml_bytes)
271 mfa_delete = root.findtext("MfaDelete")
272 status = root.findtext("Status")
273
274 return VersioningConfiguration(mfa_delete=mfa_delete, status=status)
275
256 def get_bucket_acl(self, bucket):276 def get_bucket_acl(self, bucket):
257 """277 """
258 Get the access control policy for a bucket.278 Get the access control policy for a bucket.
259279
=== modified file 'txaws/s3/model.py'
--- txaws/s3/model.py 2012-01-27 19:47:22 +0000
+++ txaws/s3/model.py 2012-01-28 00:47:23 +0000
@@ -90,6 +90,25 @@
90 self.event = event90 self.event = event
9191
9292
93class VersioningConfiguration(object):
94 """
95 Container for the bucket versioning configuration.
96
97 According to Amazon:
98
99 C{MfaDelete}: This element is only returned if the bucket has been
100 configured with C{MfaDelete}. If the bucket has never been so configured,
101 this element is not returned. The possible values are None, "Disabled" or
102 "Enabled".
103
104 C{Status}: If the bucket has never been so configured, this element is not
105 returned. The possible values are None, "Suspended" or "Enabled".
106 """
107 def __init__(self, mfa_delete=None, status=None):
108 self.mfa_delete = mfa_delete
109 self.status = status
110
111
93class FileChunk(object):112class FileChunk(object):
94 """113 """
95 An Amazon S3 file chunk.114 An Amazon S3 file chunk.
96115
=== 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-28 00:47:23 +0000
@@ -462,6 +462,116 @@
462 d = s3.get_bucket_notification_config("mybucket")462 d = s3.get_bucket_notification_config("mybucket")
463 return d.addCallback(check_results)463 return d.addCallback(check_results)
464464
465 def test_get_bucket_versioning_config(self):
466 """
467 L{S3Client.get_bucket_versioning_configuration} creates a L{Query} to
468 get a bucket's versioning status. It parses the returned
469 C{VersioningConfiguration} XML document and returns a C{Deferred} that
470 requests the bucket's versioning configuration.
471 """
472
473 class StubQuery(client.Query):
474
475 def __init__(query, action, creds, endpoint, bucket=None,
476 object_name=None):
477 super(StubQuery, query).__init__(action=action, creds=creds,
478 bucket=bucket,
479 object_name=object_name)
480 self.assertEquals(action, "GET")
481 self.assertEqual(creds.access_key, "foo")
482 self.assertEqual(creds.secret_key, "bar")
483 self.assertEqual(query.bucket, "mybucket")
484 self.assertEqual(query.object_name, "?versioning")
485 self.assertEqual(query.data, "")
486 self.assertEqual(query.metadata, {})
487 self.assertEqual(query.amz_headers, {})
488
489 def submit(query, url_context=None):
490 return succeed(payload.sample_s3_get_bucket_versioning_result)
491
492 def check_results(versioning_config):
493 self.assertEquals(versioning_config.status, None)
494
495 creds = AWSCredentials("foo", "bar")
496 s3 = client.S3Client(creds, query_factory=StubQuery)
497 d = s3.get_bucket_versioning_config("mybucket")
498 return d.addCallback(check_results)
499
500 def test_get_bucket_versioning_config_enabled(self):
501 """
502 L{S3Client.get_bucket_versioning_config} creates a L{Query} to get a
503 bucket's versioning configuration. It parses the returned
504 C{VersioningConfiguration} XML document and returns a C{Deferred} that
505 requests the bucket's versioning configuration that has a enabled
506 C{Status}.
507 """
508
509 class StubQuery(client.Query):
510
511 def __init__(query, action, creds, endpoint, bucket=None,
512 object_name=None):
513 super(StubQuery, query).__init__(action=action, creds=creds,
514 bucket=bucket,
515 object_name=object_name)
516 self.assertEquals(action, "GET")
517 self.assertEqual(creds.access_key, "foo")
518 self.assertEqual(creds.secret_key, "bar")
519 self.assertEqual(query.bucket, "mybucket")
520 self.assertEqual(query.object_name, "?versioning")
521 self.assertEqual(query.data, "")
522 self.assertEqual(query.metadata, {})
523 self.assertEqual(query.amz_headers, {})
524
525 def submit(query, url_context=None):
526 return succeed(payload.
527 sample_s3_get_bucket_versioning_enabled_result)
528
529 def check_results(versioning_config):
530 self.assertEquals(versioning_config.status, 'Enabled')
531
532 creds = AWSCredentials("foo", "bar")
533 s3 = client.S3Client(creds, query_factory=StubQuery)
534 d = s3.get_bucket_versioning_config("mybucket")
535 return d.addCallback(check_results)
536
537 def test_get_bucket_versioning_config_mfa_disabled(self):
538 """
539 L{S3Client.get_bucket_versioning_config} creates a L{Query} to get a
540 bucket's versioning configuration. It parses the returned
541 C{VersioningConfiguration} XML document and returns a C{Deferred} that
542 requests the bucket's versioning configuration that has a disabled
543 C{MfaDelete}.
544 """
545
546 class StubQuery(client.Query):
547
548 def __init__(query, action, creds, endpoint, bucket=None,
549 object_name=None):
550 super(StubQuery, query).__init__(action=action, creds=creds,
551 bucket=bucket,
552 object_name=object_name)
553 self.assertEquals(action, "GET")
554 self.assertEqual(creds.access_key, "foo")
555 self.assertEqual(creds.secret_key, "bar")
556 self.assertEqual(query.bucket, "mybucket")
557 self.assertEqual(query.object_name, "?versioning")
558 self.assertEqual(query.data, "")
559 self.assertEqual(query.metadata, {})
560 self.assertEqual(query.amz_headers, {})
561
562 def submit(query, url_context=None):
563 return succeed(
564 payload.
565 sample_s3_get_bucket_versioning_mfa_disabled_result)
566
567 def check_results(versioning_config):
568 self.assertEquals(versioning_config.mfa_delete, 'Disabled')
569
570 creds = AWSCredentials("foo", "bar")
571 s3 = client.S3Client(creds, query_factory=StubQuery)
572 d = s3.get_bucket_versioning_config("mybucket")
573 return d.addCallback(check_results)
574
465 def test_delete_bucket(self):575 def test_delete_bucket(self):
466576
467 class StubQuery(client.Query):577 class StubQuery(client.Query):
468578
=== modified file 'txaws/testing/payload.py'
--- txaws/testing/payload.py 2012-01-27 20:08:20 +0000
+++ txaws/testing/payload.py 2012-01-28 00:47:23 +0000
@@ -1071,3 +1071,17 @@
1071 <Event>s3:ReducedRedundancyLostObject</Event>1071 <Event>s3:ReducedRedundancyLostObject</Event>
1072 </TopicConfiguration>1072 </TopicConfiguration>
1073</NotificationConfiguration>"""1073</NotificationConfiguration>"""
1074
1075sample_s3_get_bucket_versioning_result = """\
1076<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"/>"""
1077
1078sample_s3_get_bucket_versioning_enabled_result = """\
1079<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
1080 <Status>Enabled</Status>
1081</VersioningConfiguration>"""
1082
1083sample_s3_get_bucket_versioning_mfa_disabled_result = """\
1084<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
1085 <Status>Enabled</Status>
1086 <MfaDelete>Disabled</MfaDelete>
1087</VersioningConfiguration>"""

Subscribers

People subscribed via source and target branches