Merge lp:~therve/txaws/post-support into lp:txaws

Proposed by Thomas Herve
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 72
Merged at revision: 69
Proposed branch: lp:~therve/txaws/post-support
Merge into: lp:txaws
Diff against target: 86 lines (+40/-6)
3 files modified
txaws/ec2/client.py (+11/-3)
txaws/ec2/tests/test_client.py (+24/-0)
txaws/service.py (+5/-3)
To merge this branch: bzr merge lp:~therve/txaws/post-support
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Review via email: mp+39316@code.launchpad.net
To post a comment you must log in.
lp:~therve/txaws/post-support updated
70. By Thomas Herve

Simplify submit

Revision history for this message
Robert Collins (lifeless) wrote :

Looks ok at first glance. Does ec2 accept it?

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Great branch, +1!

review: Approve
lp:~therve/txaws/post-support updated
71. By Thomas Herve

Blank line

72. By Thomas Herve

Update docstring

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

@Robert: it does

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txaws/ec2/client.py'
2--- txaws/ec2/client.py 2010-09-08 22:00:50 +0000
3+++ txaws/ec2/client.py 2010-10-25 21:08:07 +0000
4@@ -836,7 +836,15 @@
5 @return: A deferred from get_page
6 """
7 self.sign()
8- url = "%s?%s" % (self.endpoint.get_uri(),
9- self.get_canonical_query_params())
10- d = self.get_page(url, method=self.endpoint.method)
11+ url = self.endpoint.get_uri()
12+ method = self.endpoint.method
13+ params = self.get_canonical_query_params()
14+ kwargs = {"method": method}
15+ if method == "POST":
16+ kwargs["headers"] = {
17+ "Content-Type": "application/x-www-form-urlencoded"}
18+ kwargs["postdata"] = params
19+ else:
20+ url += "?%s" % params
21+ d = self.get_page(url, **kwargs)
22 return d.addErrback(ec2_error_wrapper)
23
24=== modified file 'txaws/ec2/tests/test_client.py'
25--- txaws/ec2/tests/test_client.py 2010-09-08 22:00:50 +0000
26+++ txaws/ec2/tests/test_client.py 2010-10-25 21:08:07 +0000
27@@ -64,6 +64,30 @@
28 ec2 = client.EC2Client()
29 self.assertNotEqual(None, ec2.creds)
30
31+ def test_post_method(self):
32+ """
33+ If the method of the endpoint is POST, the parameters are passed in the
34+ body.
35+ """
36+ self.addCleanup(setattr, client.Query, "get_page",
37+ client.Query.get_page)
38+
39+ def get_page(query, url, *args, **kwargs):
40+ self.assertEquals(args, ())
41+ self.assertEquals(
42+ kwargs["headers"],
43+ {"Content-Type": "application/x-www-form-urlencoded"})
44+ self.assertIn("postdata", kwargs)
45+ self.assertEquals(kwargs["method"], "POST")
46+ return succeed(payload.sample_describe_instances_result)
47+
48+ client.Query.get_page = get_page
49+
50+ creds = AWSCredentials("foo", "bar")
51+ endpoint = AWSServiceEndpoint(uri=EC2_ENDPOINT_US, method="POST")
52+ ec2 = client.EC2Client(creds=creds, endpoint=endpoint)
53+ return ec2.describe_instances()
54+
55 def test_init_no_creds_non_available_errors(self):
56 self.assertRaises(ValueError, client.EC2Client)
57
58
59=== modified file 'txaws/service.py'
60--- txaws/service.py 2009-11-27 20:37:56 +0000
61+++ txaws/service.py 2010-10-25 21:08:07 +0000
62@@ -74,10 +74,12 @@
63 associated creds will be used against a collection of services.
64 @param uri: an endpoint URI that, if provided, will override the region
65 parameter.
66+ @param method: The method argument forwarded to L{AWSServiceEndpoint}.
67 """
68 # XXX update unit test to check for both ec2 and s3 endpoints
69 def __init__(self, creds=None, access_key="", secret_key="",
70- region=REGION_US, uri="", ec2_uri="", s3_uri=""):
71+ region=REGION_US, uri="", ec2_uri="", s3_uri="",
72+ method="GET"):
73 if not creds:
74 creds = AWSCredentials(access_key, secret_key)
75 self.creds = creds
76@@ -91,8 +93,8 @@
77 if not s3_uri:
78 s3_uri = S3_ENDPOINT
79 self._clients = {}
80- self.ec2_endpoint = AWSServiceEndpoint(uri=ec2_uri)
81- self.s3_endpoint = AWSServiceEndpoint(uri=s3_uri)
82+ self.ec2_endpoint = AWSServiceEndpoint(uri=ec2_uri, method=method)
83+ self.s3_endpoint = AWSServiceEndpoint(uri=s3_uri, method=method)
84
85 def get_client(self, cls, purge_cache=False, *args, **kwds):
86 """

Subscribers

People subscribed via source and target branches

to all changes: