Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def test_someValuesAreEmpty( self ):
   badDict = self.msg.copy()
   badDict['timestamp'] = ''
   self.assertFalse( isMessageFormatCorrect( badDict ) )
Ejemplo n.º 3
0
 def test_missingKey( self ):
   badDict = self.msg.copy()
   badDict.pop( 'source', None )  # removing one key
   self.assertFalse( isMessageFormatCorrect( badDict ) )
Ejemplo n.º 4
0
 def test_valuesNotStrings ( self ):
   badDict = self.msg.copy()
   badDict['source'] = 10
   self.assertFalse( isMessageFormatCorrect( badDict ) )
Ejemplo n.º 5
0
 def test_success( self ):
   self.assertTrue( isMessageFormatCorrect( self.msg ) )
Ejemplo n.º 6
0
 def test_notDict( self ):
   self.assertFalse( isMessageFormatCorrect( ['a', 2] ) )
Ejemplo n.º 7
0
 def test_someValuesAreEmpty( self ):
   badDict = self.msg.copy()
   badDict['timestamp'] = ''
   self.assertFalse( isMessageFormatCorrect( badDict ) )
Ejemplo n.º 8
0
 def test_valuesNotStrings ( self ):
   badDict = self.msg.copy()
   badDict['source'] = 10
   self.assertFalse( isMessageFormatCorrect( badDict ) )
Ejemplo n.º 9
0
 def test_missingKey( self ):
   badDict = self.msg.copy()
   badDict.pop( 'source', None )  # removing one key
   self.assertFalse( isMessageFormatCorrect( badDict ) )
Ejemplo n.º 10
0
 def test_notDict( self ):
   self.assertFalse( isMessageFormatCorrect( ['a', 2] ) )
Ejemplo n.º 11
0
 def test_success( self ):
   self.assertTrue( isMessageFormatCorrect( self.msg ) )