<s> """<STR_LIT>""" <EOL> import unittest <EOL> import time <EOL> from boto . s3 . connection import S3Connection <EOL> from boto . exception import S3ResponseError <EOL> from boto . s3 . deletemarker import DeleteMarker <EOL> from boto . compat import six <EOL> class S3VersionTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . conn = S3Connection ( ) <EOL> self . bucket_name = '<STR_LIT>' % int ( time . time ( ) ) <EOL> self . bucket = self . conn . create_bucket ( self . bucket_name ) <EOL> def tearDown ( self ) : <EOL> for k in self . bucket . list_versions ( ) : <EOL> self . bucket . delete_key ( k . name , version_id = k . version_id ) <EOL> self . bucket . delete ( ) <EOL> def test_1_versions ( self ) : <EOL> d = self . bucket . get_versioning_status ( ) <EOL> self . assertFalse ( '<STR_LIT>' in d ) <EOL> self . bucket . configure_versioning ( versioning = True ) <EOL> d = self . bucket . get_versioning_status ( ) <EOL> self . assertEqual ( '<STR_LIT>' , d [ '<STR_LIT>' ] ) <EOL> k = self . bucket . new_key ( "<STR_LIT>" ) <EOL> s1 = '<STR_LIT>' <EOL> k . set_contents_from_string ( s1 ) <EOL> v1 = k . version_id <EOL> o1 = k . get_contents_as_string ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertEqual ( s1 , o1 ) <EOL> s2 = '<STR_LIT>' <EOL> k . set_contents_from_string ( s2 ) <EOL> v2 = k . version_id <EOL> k2 = self . bucket . new_key ( "<STR_LIT>" ) <EOL> o2 = k2 . get_contents_as_string ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertEqual ( s2 , o2 ) <EOL> o1 = k . get_contents_as_string ( version_id = v1 ) . decode ( '<STR_LIT:utf-8>' ) <EOL> o2 = k . get_contents_as_string ( version_id = v2 ) . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertEqual ( s1 , o1 ) <EOL> self . assertEqual ( s2 , o2 ) <EOL> rs = self . bucket . get_all_versions ( ) <EOL> self . assertEqual ( v2 , rs [ <NUM_LIT:0> ] . version_id ) <EOL> self . assertEqual ( v1 , rs [ <NUM_LIT:1> ] . version_id ) <EOL> rs = self . bucket . get_all_keys ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( rs ) ) <EOL> self . bucket . delete_key ( '<STR_LIT>' ) <EOL> rs = self . bucket . get_all_versions ( ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( rs ) ) <EOL> self . assertTrue ( isinstance ( rs [ <NUM_LIT:0> ] , DeleteMarker ) ) <EOL> self . bucket . delete_key ( '<STR_LIT>' , version_id = v1 ) <EOL> rs = self . bucket . get_all_versions ( ) <EOL> versions = [ k . version_id for k in rs ] <EOL> self . assertTrue ( v1 not in versions ) <EOL> self . assertTrue ( v2 in versions ) <EOL> self . bucket . configure_versioning ( False ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> d = self . bucket . get_versioning_status ( ) <EOL> self . assertEqual ( '<STR_LIT>' , d [ '<STR_LIT>' ] ) <EOL> def test_latest_version ( self ) : <EOL> self . bucket . configure_versioning ( versioning = True ) <EOL> key_name = "<STR_LIT:key>" <EOL> kv1 = self . bucket . new_key ( key_name ) <EOL> kv1 . set_contents_from_string ( "<STR_LIT>" ) <EOL> listed_kv1 = next ( iter ( self . bucket . get_all_versions ( ) ) ) <EOL> self . assertEqual ( listed_kv1 . name , key_name ) <EOL> self . assertEqual ( listed_kv1 . version_id , kv1 . version_id ) <EOL> self . assertEqual ( listed_kv1 . is_latest , True ) <EOL> kv2 = self . bucket . new_key ( key_name ) <EOL> kv2 . set_contents_from_string ( "<STR_LIT>" ) <EOL> i = iter ( self . bucket . get_all_versions ( ) ) <EOL> listed_kv2 = next ( i ) <EOL> listed_kv1 = next ( i ) <EOL> self . assertEqual ( listed_kv2 . version_id , kv2 . version_id ) <EOL> self . assertEqual ( listed_kv1 . version_id , kv1 . version_id ) <EOL> self . assertEqual ( listed_kv2 . is_latest , True ) <EOL> self . assertEqual ( listed_kv1 . is_latest , False ) <EOL> self . bucket . delete_key ( key_name ) <EOL> i = iter ( self . bucket . get_all_versions ( ) ) <EOL> listed_kv3 = next ( i ) <EOL> listed_kv2 = next ( i ) <EOL> listed_kv1 = next ( i ) <EOL> self . assertNotEqual ( listed_kv3 . version_id , None ) <EOL> self . assertEqual ( listed_kv2 . version_id , kv2 . version_id ) <EOL> self . assertEqual ( listed_kv1 . version_id , kv1 . version_id ) <EOL> self . assertEqual ( listed_kv3 . is_latest , True ) <EOL> self . assertEqual ( listed_kv2 . is_latest , False ) <EOL> self . assertEqual ( listed_kv1 . is_latest , False ) </s>
