def sendMessage(self, messageContent, source='unspecified', phase='unspecified', status='info'): """ Sends the message after creating the correct format: including content, timestamp, status, source, phase and the uuid of the pilot. Returns: bool: False in case of any errors, True otherwise """ if not self._isCorrectStatus(status): logging.error('status: ' + str(status) + ' is not correct') return False myUUID = getPilotUUIDFromFile(self.params['FileWithID']) message = generateDict(myUUID, generateTimeStamp(), source, phase, status, messageContent) if not isMessageFormatCorrect(message): logging.warning("Message format is not correct.") return False encodedMsg = encodeMessage(message) self.messageSender.sendMessage(encodedMsg, flag=status) return False
def test_someValuesAreEmpty( self ): badDict = self.msg.copy() badDict['timestamp'] = '' self.assertFalse( isMessageFormatCorrect( badDict ) )
def test_missingKey( self ): badDict = self.msg.copy() badDict.pop( 'source', None ) # removing one key self.assertFalse( isMessageFormatCorrect( badDict ) )
def test_valuesNotStrings ( self ): badDict = self.msg.copy() badDict['source'] = 10 self.assertFalse( isMessageFormatCorrect( badDict ) )
def test_success( self ): self.assertTrue( isMessageFormatCorrect( self.msg ) )
def test_notDict( self ): self.assertFalse( isMessageFormatCorrect( ['a', 2] ) )