290
290
TXAWSTestCase.setUp(self)
291
self.creds = AWSCredentials('foo', 'bar')
291
self.creds = AWSCredentials("foo", "bar")
292
292
self.endpoint = AWSServiceEndpoint(uri=EC2_ENDPOINT_US)
294
294
def test_init_minimum(self):
295
query = client.Query('DescribeInstances', self.creds, self.endpoint)
296
self.assertTrue('Timestamp' in query.params)
297
del query.params['Timestamp']
295
query = client.Query("DescribeInstances", self.creds, self.endpoint)
296
self.assertTrue("Timestamp" in query.params)
297
del query.params["Timestamp"]
298
298
self.assertEqual(
299
{'AWSAccessKeyId': 'foo',
300
'Action': 'DescribeInstances',
301
'SignatureMethod': 'HmacSHA1',
302
'SignatureVersion': '2',
303
'Version': '2008-12-01'},
299
{"AWSAccessKeyId": "foo",
300
"Action": "DescribeInstances",
301
"SignatureMethod": "HmacSHA1",
302
"SignatureVersion": "2",
303
"Version": "2008-12-01"},
306
306
def test_init_requires_action(self):
310
310
self.assertRaises(TypeError, client.Query, None)
312
312
def test_init_other_args_are_params(self):
313
query = client.Query('DescribeInstances', self.creds, self.endpoint,
314
{'InstanceId.0': '12345'},
313
query = client.Query("DescribeInstances", self.creds, self.endpoint,
314
{"InstanceId.0": "12345"},
315
315
time_tuple=(2007,11,12,13,14,15,0,0,0))
316
316
self.assertEqual(
317
{'AWSAccessKeyId': 'foo',
318
'Action': 'DescribeInstances',
319
'InstanceId.0': '12345',
320
'SignatureMethod': 'HmacSHA1',
321
'SignatureVersion': '2',
322
'Timestamp': '2007-11-12T13:14:15Z',
323
'Version': '2008-12-01'},
317
{"AWSAccessKeyId": "foo",
318
"Action": "DescribeInstances",
319
"InstanceId.0": "12345",
320
"SignatureMethod": "HmacSHA1",
321
"SignatureVersion": "2",
322
"Timestamp": "2007-11-12T13:14:15Z",
323
"Version": "2008-12-01"},
326
326
def test_sorted_params(self):
327
query = client.Query('DescribeInstances', self.creds, self.endpoint,
327
query = client.Query("DescribeInstances", self.creds, self.endpoint,
329
329
time_tuple=(2007,11,12,13,14,15,0,0,0))
330
330
self.assertEqual([
331
('AWSAccessKeyId', 'foo'),
332
('Action', 'DescribeInstances'),
333
('SignatureMethod', 'HmacSHA1'),
334
('SignatureVersion', '2'),
335
('Timestamp', '2007-11-12T13:14:15Z'),
336
('Version', '2008-12-01'),
331
("AWSAccessKeyId", "foo"),
332
("Action", "DescribeInstances"),
333
("SignatureMethod", "HmacSHA1"),
334
("SignatureVersion", "2"),
335
("Timestamp", "2007-11-12T13:14:15Z"),
336
("Version", "2008-12-01"),
338
338
], query.sorted_params())
340
340
def test_encode_unreserved(self):
341
all_unreserved = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
342
'abcdefghijklmnopqrstuvwxyz0123456789-_.~')
343
query = client.Query('DescribeInstances', self.creds, self.endpoint)
341
all_unreserved = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
342
"abcdefghijklmnopqrstuvwxyz0123456789-_.~")
343
query = client.Query("DescribeInstances", self.creds, self.endpoint)
344
344
self.assertEqual(all_unreserved, query.encode(all_unreserved))
346
346
def test_encode_space(self):
347
"""This may be just 'url encode', but the AWS manual isn't clear."""
348
query = client.Query('DescribeInstances', self.creds, self.endpoint)
349
self.assertEqual('a%20space', query.encode('a space'))
347
"""This may be just "url encode", but the AWS manual isn't clear."""
348
query = client.Query("DescribeInstances", self.creds, self.endpoint)
349
self.assertEqual("a%20space", query.encode("a space"))
351
351
def test_canonical_query(self):
352
query = client.Query('DescribeInstances', self.creds, self.endpoint,
353
{'fu n': 'g/ames', 'argwithnovalue':'',
354
'InstanceId.1': 'i-1234'},
352
query = client.Query("DescribeInstances", self.creds, self.endpoint,
353
{"fu n": "g/ames", "argwithnovalue":"",
354
"InstanceId.1": "i-1234"},
355
355
time_tuple=(2007,11,12,13,14,15,0,0,0))
356
expected_query = ('AWSAccessKeyId=foo&Action=DescribeInstances'
357
'&InstanceId.1=i-1234'
358
'&SignatureMethod=HmacSHA1&SignatureVersion=2&'
359
'Timestamp=2007-11-12T13%3A14%3A15Z&Version=2008-12-01&'
360
'argwithnovalue=&fu%20n=g%2Fames')
356
expected_query = ("AWSAccessKeyId=foo&Action=DescribeInstances"
357
"&InstanceId.1=i-1234"
358
"&SignatureMethod=HmacSHA1&SignatureVersion=2&"
359
"Timestamp=2007-11-12T13%3A14%3A15Z&Version=2008-12-01&"
360
"argwithnovalue=&fu%20n=g%2Fames")
361
361
self.assertEqual(expected_query, query.canonical_query_params())
363
363
def test_signing_text(self):
364
query = client.Query('DescribeInstances', self.creds, self.endpoint,
364
query = client.Query("DescribeInstances", self.creds, self.endpoint,
365
365
time_tuple=(2007,11,12,13,14,15,0,0,0))
366
signing_text = ('GET\n%s\n/\n' % self.endpoint.host +
367
'AWSAccessKeyId=foo&Action=DescribeInstances&'
368
'SignatureMethod=HmacSHA1&SignatureVersion=2&'
369
'Timestamp=2007-11-12T13%3A14%3A15Z&Version=2008-12-01')
366
signing_text = ("GET\n%s\n/\n" % self.endpoint.host +
367
"AWSAccessKeyId=foo&Action=DescribeInstances&"
368
"SignatureMethod=HmacSHA1&SignatureVersion=2&"
369
"Timestamp=2007-11-12T13%3A14%3A15Z&Version=2008-12-01")
370
370
self.assertEqual(signing_text, query.signing_text())
372
372
def test_sign(self):
373
query = client.Query('DescribeInstances', self.creds, self.endpoint,
373
query = client.Query("DescribeInstances", self.creds, self.endpoint,
374
374
time_tuple=(2007,11,12,13,14,15,0,0,0))
376
self.assertEqual('JuCpwFA2H4OVF3Ql/lAQs+V6iMc=',
377
query.params['Signature'])
376
self.assertEqual("JuCpwFA2H4OVF3Ql/lAQs+V6iMc=",
377
query.params["Signature"])
380
380
class TestEBS(TXAWSTestCase):