#!/usr/bin/env python

from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.key import Key
import unittest, time

KEY_ID="0"
SECRET_KEY="9372f58b69b05001"
HOST="127.0.0.1"
PORT=80
data = file("/dev/random").read(1024)


class ParityWithPrototypeTest(unittest.TestCase):
    def setUp(self):
        self.bucket_name = "parity-test"
        self.key_name = "parity-test"
        self.conn = S3Connection(KEY_ID, SECRET_KEY, is_secure=False, 
                                 host=HOST, port=PORT, debug=True, 
                                 calling_format=OrdinaryCallingFormat())


    def test_1_create_bucket(self):
        self.conn.create_bucket(self.bucket_name)

    def test_2_list_buckets(self):
        self.assertIn(self.bucket_name, 
                      [b.name for b in self.conn.get_all_buckets()])        

    def test_3_put_object(self):
        bucket = self.conn.get_bucket(self.bucket_name)
        k = Key(bucket)
        k.key = self.key_name
        k.set_contents_from_string("parity-test")

    def test_4_get_object(self):
        bucket = self.conn.get_bucket(self.bucket_name)
        k = Key(bucket)
        k.key = self.key_name        
        self.assertEqual(k.get_contents_as_string(), "parity-test")

    def test_5_list_bucket(self):
        bucket = self.conn.get_bucket(self.bucket_name)
        self.assertIn(self.key_name,
                      [k.key for k in bucket.get_all_keys()])

    def test_6_delete_object(self):
        bucket = self.conn.get_bucket(self.bucket_name)
        k = Key(bucket)
        k.key = self.key_name                
        k.delete()

    def test_7_list_bucket(self):
        time.sleep(3) # XXX HACK
        bucket = self.conn.get_bucket(self.bucket_name)
        self.assertNotIn(self.key_name,
                         [k.key for k in bucket.get_all_keys()])

    def test_8_delete_bucket(self):
        bucket = self.conn.get_bucket(self.bucket_name)
        bucket.delete()

    def test_9_list_buckets(self):
        self.assertNotIn(self.bucket_name, 
                         [b.name for b in self.conn.get_all_buckets()])                

if __name__ == "__main__":
    unittest.main()

@@ -16,16 +16,59 @@
 python%0A%0A
+from boto.exception import S3ResponseError%0A
 from bot
@@ -175,16 +175,22 @@
 st, time
+, uuid
 %0A%0AKEY_ID
@@ -253,47 +253,8 @@
 =80%0A
-data = file(%22/dev/random%22).read(1024)%0A%0A
 %0Acla
@@ -300,24 +300,25 @@
 tCase):%0A
+%0A
     def 
 setUp(se
@@ -313,151 +313,115 @@
 def 
-setUp(self):%0A        self.bucket_name = %22parity-test%22%0A        self.key_name = %22parity-test%22%0A        self.conn = S3Connection(KEY_ID, SECRET_KEY
+make_connection(self, key_id=KEY_ID, secret_key=SECRET_KEY):%0A        return S3Connection(key_id, secret_key
 , is
@@ -432,29 +432,24 @@
 ure=False, %0A
-     
             
@@ -527,21 +527,16 @@
         
-  
-   
 calling_
@@ -565,18 +565,427 @@
 Format()
+ )       %0A    @classmethod%0A    def setUpClass(self):%0A        self.bucket_name = str(uuid.uuid4())%0A        self.key_name = str(uuid.uuid4())%0A        self.data = file(%22/dev/random%22).read(1024)%0A%0A    def setUp(self):%0A        self.conn = self.make_connection()%0A%0A    def test_0_auth(self):%0A        conn = self.make_connection(%22BAD_ID%22, %22BAD_KEY%22)%0A        self.assertRaises(S3ResponseError, conn.get_canonical_user_id
 )
-%0A
 %0A%0A    de
@@ -1397,29 +1397,25 @@
 _string(
-%22parity-test%22
+self.data
 )%0A%0A    d
@@ -1617,21 +1617,17 @@
 (), 
-%22parity-test%22
+self.data
 )%0A%0A 
@@ -2490,24 +2490,25 @@
 buckets()%5D) 
+%0A
             

test auth, use random data and key/bucket names