#NEWLINE# def assertHasMessage( testCase , logger , messageType , fields = None ) : #NEWLINE# #INDENT# "\n    Assert that the given logger has a message of the given type, and the first\n    message found of this type has the given fields.\n\n    This can be used as the assertion function passed to L{validateLogging} or\n    as part of a unit test.\n\n    @param testCase: L{unittest.TestCase} instance.\n\n    @param logger: L{eliot.MemoryLogger} whose messages will be checked.\n\n    @param messageType: L{eliot.MessageType} indicating which message we're\n        looking for.\n\n    @param fields: The first message of the given type found must have a\n        superset of the given C{dict} as its fields. If C{None} then fields are\n        not checked.\n\n    @return: The first found L{LoggedMessage} of the given type, if field\n        validation succeeded.\n\n    @raises AssertionError: No message was found, or the fields were not\n        superset of given fields.\n    " #NEWLINE# if ( fields is None ) : #NEWLINE# #INDENT# fields = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# messages = LoggedMessage . ofType ( logger . messages , messageType ) #NEWLINE# testCase . assertTrue ( messages , ( 'No messages of type %s' % ( logger , ) ) ) #NEWLINE# loggedMessage = messages [ 0 ] #NEWLINE# assertContainsFields ( testCase , loggedMessage . message , fields ) #NEWLINE# return loggedMessage