txaws-dev team mailing list archive
-
txaws-dev team
-
Mailing list archive
-
Message #00071
[Merge] lp:~oubiwann/txaws/919538-grantee-email-uri into lp:txaws
Duncan McGreggor has proposed merging lp:~oubiwann/txaws/919538-grantee-email-uri into lp:txaws.
Requested reviews:
txAWS Developers (txaws-dev)
Related bugs:
Bug #919538 in txAWS: "s3 ACL Grantee class is missing support for by-email and by-uri"
https://bugs.launchpad.net/txaws/+bug/919538
For more details, see:
https://code.launchpad.net/~oubiwann/txaws/919538-grantee-email-uri/+merge/89519
--
https://code.launchpad.net/~oubiwann/txaws/919538-grantee-email-uri/+merge/89519
Your team txAWS Developers is requested to review the proposed merge of lp:~oubiwann/txaws/919538-grantee-email-uri into lp:txaws.
=== modified file 'txaws/s3/acls.py'
--- txaws/s3/acls.py 2011-03-26 12:51:56 +0000
+++ txaws/s3/acls.py 2012-01-21 08:01:24 +0000
@@ -99,17 +99,36 @@
return buffer
-class Grantee(Owner):
+class Grantee(XMLMixin):
+
+ def __init__(self, id="", display_name="", email_address="", uri=""):
+ if id or display_name:
+ msg = "Both 'id' and 'display_name' must be provided."
+ if not (id and display_name):
+ raise ValueError(msg)
+ self.id = id
+ self.display_name = display_name
+ self.email_address = email_address
+ self.uri = uri
def _to_xml(self, buffer=None, indent=0):
if buffer is None:
buffer = []
ws = " " * (indent * 2)
+ if self.id and self.display_name:
+ xsi_type = "CanonicalUser"
+ value = ("%s <ID>%s</ID>\n"
+ "%s <DisplayName>%s</DisplayName>\n" % (
+ ws, self.id, ws, self.display_name))
+ elif self.email_address:
+ xsi_type = "AmazonCustomerByEmail"
+ value = "%s <EmailAddress>%s</EmailAddress>\n" % (
+ ws, self.email_address)
+ elif self.uri:
+ xsi_type = "Group"
+ value = "%s <URI>%s</URI>\n" % (ws, self.uri)
buffer.append("%s<Grantee "
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
- ' xsi:type="CanonicalUser">\n'
- "%s <ID>%s</ID>\n"
- "%s <DisplayName>%s</DisplayName>\n"
- "%s</Grantee>\n" % (ws, ws, self.id, ws,
- self.display_name, ws))
+ ' xsi:type="%s">\n'
+ "%s%s</Grantee>\n" % (ws, xsi_type, value, ws))
return buffer
=== modified file 'txaws/s3/tests/test_acls.py'
--- txaws/s3/tests/test_acls.py 2011-03-26 12:50:41 +0000
+++ txaws/s3/tests/test_acls.py 2012-01-21 08:01:24 +0000
@@ -17,7 +17,15 @@
</Owner>
""")
- def test_grantee_to_xml(self):
+ def test_grantee_canonical_missing_parameter(self):
+ self.assertRaises(
+ ValueError, acls.Grantee,
+ {'id': '8a6925ce4adf588a4f21c32aa379004fef'})
+ self.assertRaises(
+ ValueError, acls.Grantee,
+ {'display_name': 'BucketOwnersEmail@xxxxxxxxxx'})
+
+ def test_grantee_canonical_to_xml(self):
grantee = acls.Grantee(id='8a6925ce4adf588a4f21c32aa379004fef',
display_name='BucketOwnersEmail@xxxxxxxxxx')
xml_bytes = grantee.to_xml()
@@ -28,6 +36,25 @@
</Grantee>
""")
+ def test_grantee_email_to_xml(self):
+ grantee = acls.Grantee(email_address="BucketOwnersEmail@xxxxxxxxxx")
+ xml_bytes = grantee.to_xml()
+ self.assertEquals(xml_bytes, """\
+<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AmazonCustomerByEmail">
+ <EmailAddress>BucketOwnersEmail@xxxxxxxxxx</EmailAddress>
+</Grantee>
+""")
+
+ def test_grantee_uri_to_xml(self):
+ grantee = acls.Grantee(
+ uri='http://acs.amazonaws.com/groups/global/AuthenticatedUsers')
+ xml_bytes = grantee.to_xml()
+ self.assertEquals(xml_bytes, """\
+<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
+ <URI>http://acs.amazonaws.com/groups/global/AuthenticatedUsers</URI>
+</Grantee>
+""")
+
def test_grant_to_xml(self):
grantee = acls.Grantee(id='8a6925ce4adf588a4f21c32aa379004fef',
display_name='BucketOwnersEmail@xxxxxxxxxx')