From 9721b6b7451a9d361b42d9e364e1a4c6b404cfe5 Mon Sep 17 00:00:00 2001 From: nordstromj Date: Thu, 15 Jan 2015 09:25:33 -0800 Subject: Added tests demonstrating functionality of cors, tagging, and notification. --- test.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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 = '\ + \ + *\ + POST\ + 3000\ + Authorization\ + \ + ' + 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 = '\ + \ + \ + Project\ + Project 1\ + \ + \ + ' + 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 = '' + 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 tag is default + if __name__ == '__main__': unittest.main() -- cgit v1.2.1