#NEWLINE# def assertMessageCount( self , response = None , **kwargs ) : #NEWLINE# #INDENT# 'Asserts that the specified number of messages have been attached\n        for various message types. Usage would look like\n        ``self.assertMessageCount(success=1)``.\n        ' #NEWLINE# temp_req = self . client . request ( ** { #NEWLINE# #INDENT# 'wsgi.input' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# temp_req . COOKIES = self . client . cookies #NEWLINE# storage = default_storage ( temp_req ) #NEWLINE# messages = [ ] #NEWLINE# if ( response is None ) : #NEWLINE# #INDENT# if ( 'messages' in self . client . cookies ) : #NEWLINE# #INDENT# message_cookie = self . client . cookies [ 'messages' ] . value #NEWLINE# messages = storage . _decode ( message_cookie ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( hasattr ( response , 'context' ) and ( 'messages' in response . context ) ) : #NEWLINE# #INDENT# messages = response . context [ 'messages' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( hasattr ( response , '_request' ) and hasattr ( response . _request , '_messages' ) ) : #NEWLINE# #INDENT# messages = response . _request . _messages . _queued_messages #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( not any ( kwargs . values ( ) ) ) and ( not messages ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( any ( kwargs . values ( ) ) and ( not messages ) ) : #NEWLINE# #INDENT# error_msg = 'Messages were expected, but none were set.' #NEWLINE# assert ( 0 == sum ( kwargs . values ( ) ) ) , error_msg #NEWLINE# #UNINDENT# for ( msg_type , count ) in kwargs . items ( ) : #NEWLINE# #INDENT# msgs = [ force_text ( m . message ) for m in messages if ( msg_type in m . tags ) ] #NEWLINE# assert ( len ( msgs ) == count ) , ( '%s messages not as expected: %s' % ( msg_type . title ( ) , ', ' . join ( msgs ) ) )