Exemple #1
0
 def test_no_pattern(self):
     """Handler should not operate if it does not have a pattern."""
     pattern = getattr(AdditionPatternHandler, 'pattern')
     delattr(AdditionPatternHandler, 'pattern')
     try:
         with self.assertRaises(HandlerError):
             msg = IncomingMessage(self.connection, '1 plus 2')
             AdditionPatternHandler.dispatch(self.router, msg)
     finally:
         setattr(AdditionPatternHandler, 'pattern', pattern)
Exemple #2
0
 def test_no_pattern(self):
     """Handler should not operate if it does not have a pattern."""
     pattern = getattr(AdditionPatternHandler, 'pattern')
     delattr(AdditionPatternHandler, 'pattern')
     try:
         with self.assertRaises(HandlerError):
             msg = IncomingMessage(self.connection, '1 plus 2')
             AdditionPatternHandler.dispatch(self.router, msg)
     finally:
         setattr(AdditionPatternHandler, 'pattern', pattern)
Exemple #3
0
 def _check_dispatch(self, text, correct_response):
     msg = IncomingMessage(self.connection, text)
     retVal = AdditionPatternHandler.dispatch(self.router, msg)
     if correct_response is not None:
         self.assertTrue(retVal)
         self.assertEqual(len(msg.responses), 1)
         self.assertEqual(msg.responses[0]['text'], correct_response)
     else:
         self.assertFalse(retVal)
         self.assertEqual(len(msg.responses), 0)
Exemple #4
0
 def _check_dispatch(self, text, correct_response):
     msg = IncomingMessage(self.connection, text)
     retVal = AdditionPatternHandler.dispatch(self.router, msg)
     if correct_response is not None:
         self.assertTrue(retVal)
         self.assertEqual(len(msg.responses), 1)
         self.assertEqual(msg.responses[0]['text'], correct_response)
     else:
         self.assertFalse(retVal)
         self.assertEqual(len(msg.responses), 0)