#NEWLINE# @ patch_policies #NEWLINE# def test_get_response_headers_with_legacy_data( self ) : #NEWLINE# #INDENT# broker = backend . AccountBroker ( ':memory:' , account = 'a' ) #NEWLINE# now = time . time ( ) #NEWLINE# with mock . patch ( 'time.time' , new = ( lambda : now ) ) : #NEWLINE# #INDENT# broker . initialize ( Timestamp ( now ) . internal ) #NEWLINE# #UNINDENT# ts = ( Timestamp ( t ) . internal for t in itertools . count ( int ( now ) ) ) #NEWLINE# total_containers = 0 #NEWLINE# total_objects = 0 #NEWLINE# total_bytes = 0 #NEWLINE# for policy in POLICIES : #NEWLINE# #INDENT# delete_timestamp = next ( ts ) #NEWLINE# put_timestamp = next ( ts ) #NEWLINE# object_count = int ( policy ) #NEWLINE# bytes_used = ( int ( policy ) * 10 ) #NEWLINE# broker . put_container ( ( 'c-%s' % policy . name ) , put_timestamp , delete_timestamp , object_count , per_policy_container_headers , int ( policy ) ) #NEWLINE# total_containers += 1 #NEWLINE# total_objects += object_count #NEWLINE# total_bytes += bytes_used #NEWLINE# #UNINDENT# expected = HeaderKeyDict ( { #NEWLINE# #INDENT# 'X-Account-Container-Count' : total_containers , #NEWLINE# 'X-Account-Object-Count' : total_objects , #NEWLINE# 'X-Account-Bytes-Used' : total_bytes , #NEWLINE# 'X-Timestamp' : Timestamp ( now ) . normal , #NEWLINE# 'X-PUT-Timestamp' : Timestamp ( now ) . normal , #NEWLINE# #UNINDENT# } ) #NEWLINE# for policy in POLICIES : #NEWLINE# #INDENT# prefix = ( 'X-Account-Storage-Policy-%s-' % policy . name ) #NEWLINE# expected [ ( prefix + 'Object-Count' ) ] = int ( policy ) #NEWLINE# expected [ ( prefix + 'Bytes-Used' ) ] = ( int ( policy ) * 10 ) #NEWLINE# #UNINDENT# orig_policy_stats = broker . get_policy_stats #NEWLINE# def stub_policy_stats( * args , **kwargs ) : #NEWLINE# #INDENT# policy_stats = orig_policy_stats ( * args , ** kwargs ) #NEWLINE# for stats in policy_stats . values ( ) : #NEWLINE# #INDENT# del stats [ 'container_count' ] #NEWLINE# #UNINDENT# return policy_stats #NEWLINE# #UNINDENT# broker . get_policy_stats = stub_policy_stats #NEWLINE# resp_headers = utils . get_response_headers ( broker ) #NEWLINE# per_policy_container_headers = [ h for h in resp_headers if ( h . lower ( ) . startswith ( 'x-account-storage-policy-' ) and h . lower ( ) . endswith ( '-container-count' ) ) ] #NEWLINE# self . assertFalse ( per_policy_container_headers ) #NEWLINE# for ( key , value ) in resp_headers . items ( ) : #NEWLINE# #INDENT# expected_value = expected . pop ( key ) #NEWLINE# self . assertEqual ( expected_value , str ( value ) , ( 'value for %r was %r not %r' % ( key , value , expected_value ) ) ) #NEWLINE# #UNINDENT# self . assertFalse ( expected )