txaws-dev team mailing list archive
-
txaws-dev team
-
Mailing list archive
-
Message #00018
[Merge] lp:~therve/txaws/post-support into lp:txaws
Thomas Herve has proposed merging lp:~therve/txaws/post-support into lp:txaws.
Requested reviews:
txAWS Developers (txaws-dev)
Related bugs:
#666487 ec2 client doesn't really support POST
https://bugs.launchpad.net/bugs/666487
--
https://code.launchpad.net/~therve/txaws/post-support/+merge/39316
Your team txAWS Developers is requested to review the proposed merge of lp:~therve/txaws/post-support into lp:txaws.
=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py 2010-09-08 22:00:50 +0000
+++ txaws/ec2/client.py 2010-10-25 20:56:43 +0000
@@ -836,7 +836,14 @@
@return: A deferred from get_page
"""
self.sign()
- url = "%s?%s" % (self.endpoint.get_uri(),
- self.get_canonical_query_params())
- d = self.get_page(url, method=self.endpoint.method)
+ url = self.endpoint.get_uri()
+ method = self.endpoint.method
+ if method == "POST":
+ data = self.get_canonical_query_params()
+ headers = {"Content-Type": "application/x-www-form-urlencoded"}
+ d = self.get_page(
+ url, method=method, postdata=data, headers=headers)
+ else:
+ url += "?%s" % (self.get_canonical_query_params(),)
+ d = self.get_page(url, method=method)
return d.addErrback(ec2_error_wrapper)
=== modified file 'txaws/ec2/tests/test_client.py'
--- txaws/ec2/tests/test_client.py 2010-09-08 22:00:50 +0000
+++ txaws/ec2/tests/test_client.py 2010-10-25 20:56:43 +0000
@@ -64,6 +64,31 @@
ec2 = client.EC2Client()
self.assertNotEqual(None, ec2.creds)
+ def test_post_method(self):
+ """
+ If the method of the endpoint is POST, the parameters are passed in the
+ body.
+ """
+ self.addCleanup(setattr, client.Query, "get_page",
+ client.Query.get_page)
+
+ def get_page(query, url, *args, **kwargs):
+ self.assertEquals(args, ())
+ self.assertEquals(
+ kwargs["headers"],
+ {"Content-Type": "application/x-www-form-urlencoded"})
+ self.assertIn("postdata", kwargs)
+ self.assertEquals(kwargs["method"], "POST")
+ return succeed(payload.sample_describe_instances_result)
+
+ client.Query.get_page = get_page
+
+
+ creds = AWSCredentials("foo", "bar")
+ endpoint = AWSServiceEndpoint(uri=EC2_ENDPOINT_US, method="POST")
+ ec2 = client.EC2Client(creds=creds, endpoint=endpoint)
+ return ec2.describe_instances()
+
def test_init_no_creds_non_available_errors(self):
self.assertRaises(ValueError, client.EC2Client)
=== modified file 'txaws/service.py'
--- txaws/service.py 2009-11-27 20:37:56 +0000
+++ txaws/service.py 2010-10-25 20:56:43 +0000
@@ -77,7 +77,8 @@
"""
# XXX update unit test to check for both ec2 and s3 endpoints
def __init__(self, creds=None, access_key="", secret_key="",
- region=REGION_US, uri="", ec2_uri="", s3_uri=""):
+ region=REGION_US, uri="", ec2_uri="", s3_uri="",
+ method="GET"):
if not creds:
creds = AWSCredentials(access_key, secret_key)
self.creds = creds
@@ -91,8 +92,8 @@
if not s3_uri:
s3_uri = S3_ENDPOINT
self._clients = {}
- self.ec2_endpoint = AWSServiceEndpoint(uri=ec2_uri)
- self.s3_endpoint = AWSServiceEndpoint(uri=s3_uri)
+ self.ec2_endpoint = AWSServiceEndpoint(uri=ec2_uri, method=method)
+ self.s3_endpoint = AWSServiceEndpoint(uri=s3_uri, method=method)
def get_client(self, cls, purge_cache=False, *args, **kwds):
"""