summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Tax <paultax@gmail.com>2015-01-17 10:35:23 +0100
committerPaul Tax <paultax@gmail.com>2015-01-17 10:35:23 +0100
commit985f92064e002970cc33acc3c540b7364d5da55b (patch)
treed804bb95eff0311ee73465eb2b0e8312a3e2551e
parent655be7d85942eee46536c89b0af5727fa5734db9 (diff)
parent9721b6b7451a9d361b42d9e364e1a4c6b404cfe5 (diff)
downloadpython-requests-aws-985f92064e002970cc33acc3c540b7364d5da55b.tar.gz
Merge pull request #13 from nordstromj/master
Update of missing API query parameters
-rw-r--r--awsauth.py3
-rw-r--r--test.py53
2 files changed, 55 insertions, 1 deletions
diff --git a/awsauth.py b/awsauth.py
index 85cb2a4..9d598ca 100644
--- a/awsauth.py
+++ b/awsauth.py
@@ -29,7 +29,8 @@ class S3Auth(AuthBase):
'torrent', 'versioning', 'versionId', 'versions', 'website', 'uploads',
'uploadId', 'response-content-type', 'response-content-language',
'response-expires', 'response-cache-control', 'delete', 'lifecycle',
- 'response-content-disposition', 'response-content-encoding'
+ 'response-content-disposition', 'response-content-encoding', 'tagging',
+ 'notification', 'cors'
]
def __init__(self, access_key, secret_key, service_url=None):
diff --git a/test.py b/test.py
index 1d8f6e7..719cd66 100644
--- a/test.py
+++ b/test.py
@@ -2,6 +2,8 @@ import unittest
import os
import requests
from awsauth import S3Auth
+import hashlib
+import base64
TEST_BUCKET = 'testpolpol'
@@ -56,5 +58,56 @@ class TestAWS(unittest.TestCase):
r = requests.delete(url, auth=self.auth)
self.assertEqual(r.status_code, 204)
+ def test_put_get_delete_cors(self):
+ url = 'http://'+ TEST_BUCKET + '.s3.amazonaws.com/?cors'
+ testdata = '<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">\
+ <CORSRule>\
+ <AllowedOrigin>*</AllowedOrigin>\
+ <AllowedMethod>POST</AllowedMethod>\
+ <MaxAgeSeconds>3000</MaxAgeSeconds>\
+ <AllowedHeader>Authorization</AllowedHeader>\
+ </CORSRule>\
+ </CORSConfiguration>'
+ content_md5 = base64.encodestring(hashlib.md5(testdata.strip()).digest()).strip()
+ r = requests.put(url, data=testdata, auth=self.auth, headers={'content-md5': content_md5})
+ self.assertEqual(r.status_code, 200)
+ # Downloading current cors configuration
+ r = requests.get(url, auth=self.auth)
+ self.assertEqual(r.status_code, 200)
+ # Removing removing cors configuration
+ r = requests.delete(url, auth=self.auth)
+ self.assertEqual(r.status_code, 204)
+
+ def test_put_get_delete_tagging(self):
+ url = 'http://'+ TEST_BUCKET + '.s3.amazonaws.com/?tagging'
+ testdata = '<Tagging>\
+ <TagSet>\
+ <Tag>\
+ <Key>Project</Key>\
+ <Value>Project 1</Value>\
+ </Tag>\
+ </TagSet>\
+ </Tagging>'
+ content_md5 = base64.encodestring(hashlib.md5(testdata.strip()).digest()).strip()
+ r = requests.put(url, data=testdata, auth=self.auth, headers={'content-md5': content_md5})
+ self.assertEqual(r.status_code, 204)
+ # Downloading current cors configuration
+ r = requests.get(url, auth=self.auth)
+ self.assertEqual(r.status_code, 200)
+ # Removing removing cors configuration
+ r = requests.delete(url, auth=self.auth)
+ self.assertEqual(r.status_code, 204)
+
+ def test_put_get_notification(self):
+ url = 'http://'+ TEST_BUCKET + '.s3.amazonaws.com/?notification'
+ testdata = '<NotificationConfiguration></NotificationConfiguration>'
+ content_md5 = base64.encodestring(hashlib.md5(testdata.strip()).digest()).strip()
+ r = requests.put(url, data=testdata, auth=self.auth, headers={'content-md5': content_md5})
+ self.assertEqual(r.status_code, 200)
+ # Downloading current cors configuration
+ r = requests.get(url, auth=self.auth)
+ self.assertEqual(r.status_code, 200)
+ # No Delete ?notification API, empty <NotificationConfiguration> tag is default
+
if __name__ == '__main__':
unittest.main()