Merge lp:~oubiwann/txaws/919538-grantee-email-uri into lp:txaws

Proposed by Duncan McGreggor
Status: Merged
Approved by: Thomas Herve
Approved revision: 112
Merged at revision: 118
Proposed branch: lp:~oubiwann/txaws/919538-grantee-email-uri
Merge into: lp:txaws
Diff against target: 93 lines (+53/-7)
2 files modified
txaws/s3/acls.py (+25/-6)
txaws/s3/tests/test_acls.py (+28/-1)
To merge this branch: bzr merge lp:~oubiwann/txaws/919538-grantee-email-uri
Reviewer Review Type Date Requested Status
Thomas Herve Approve
Review via email: mp+89519@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :

Cool, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txaws/s3/acls.py'
2--- txaws/s3/acls.py 2011-03-26 12:51:56 +0000
3+++ txaws/s3/acls.py 2012-01-21 08:01:24 +0000
4@@ -99,17 +99,36 @@
5 return buffer
6
7
8-class Grantee(Owner):
9+class Grantee(XMLMixin):
10+
11+ def __init__(self, id="", display_name="", email_address="", uri=""):
12+ if id or display_name:
13+ msg = "Both 'id' and 'display_name' must be provided."
14+ if not (id and display_name):
15+ raise ValueError(msg)
16+ self.id = id
17+ self.display_name = display_name
18+ self.email_address = email_address
19+ self.uri = uri
20
21 def _to_xml(self, buffer=None, indent=0):
22 if buffer is None:
23 buffer = []
24 ws = " " * (indent * 2)
25+ if self.id and self.display_name:
26+ xsi_type = "CanonicalUser"
27+ value = ("%s <ID>%s</ID>\n"
28+ "%s <DisplayName>%s</DisplayName>\n" % (
29+ ws, self.id, ws, self.display_name))
30+ elif self.email_address:
31+ xsi_type = "AmazonCustomerByEmail"
32+ value = "%s <EmailAddress>%s</EmailAddress>\n" % (
33+ ws, self.email_address)
34+ elif self.uri:
35+ xsi_type = "Group"
36+ value = "%s <URI>%s</URI>\n" % (ws, self.uri)
37 buffer.append("%s<Grantee "
38 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
39- ' xsi:type="CanonicalUser">\n'
40- "%s <ID>%s</ID>\n"
41- "%s <DisplayName>%s</DisplayName>\n"
42- "%s</Grantee>\n" % (ws, ws, self.id, ws,
43- self.display_name, ws))
44+ ' xsi:type="%s">\n'
45+ "%s%s</Grantee>\n" % (ws, xsi_type, value, ws))
46 return buffer
47
48=== modified file 'txaws/s3/tests/test_acls.py'
49--- txaws/s3/tests/test_acls.py 2011-03-26 12:50:41 +0000
50+++ txaws/s3/tests/test_acls.py 2012-01-21 08:01:24 +0000
51@@ -17,7 +17,15 @@
52 </Owner>
53 """)
54
55- def test_grantee_to_xml(self):
56+ def test_grantee_canonical_missing_parameter(self):
57+ self.assertRaises(
58+ ValueError, acls.Grantee,
59+ {'id': '8a6925ce4adf588a4f21c32aa379004fef'})
60+ self.assertRaises(
61+ ValueError, acls.Grantee,
62+ {'display_name': 'BucketOwnersEmail@amazon.com'})
63+
64+ def test_grantee_canonical_to_xml(self):
65 grantee = acls.Grantee(id='8a6925ce4adf588a4f21c32aa379004fef',
66 display_name='BucketOwnersEmail@amazon.com')
67 xml_bytes = grantee.to_xml()
68@@ -28,6 +36,25 @@
69 </Grantee>
70 """)
71
72+ def test_grantee_email_to_xml(self):
73+ grantee = acls.Grantee(email_address="BucketOwnersEmail@amazon.com")
74+ xml_bytes = grantee.to_xml()
75+ self.assertEquals(xml_bytes, """\
76+<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AmazonCustomerByEmail">
77+ <EmailAddress>BucketOwnersEmail@amazon.com</EmailAddress>
78+</Grantee>
79+""")
80+
81+ def test_grantee_uri_to_xml(self):
82+ grantee = acls.Grantee(
83+ uri='http://acs.amazonaws.com/groups/global/AuthenticatedUsers')
84+ xml_bytes = grantee.to_xml()
85+ self.assertEquals(xml_bytes, """\
86+<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
87+ <URI>http://acs.amazonaws.com/groups/global/AuthenticatedUsers</URI>
88+</Grantee>
89+""")
90+
91 def test_grant_to_xml(self):
92 grantee = acls.Grantee(id='8a6925ce4adf588a4f21c32aa379004fef',
93 display_name='BucketOwnersEmail@amazon.com')

Subscribers

People subscribed via source and target branches

to all changes: