How to use _check_dispatch method in pandera

Best Python code snippet using pandera_python

handlers.py

Source:handlers.py Github

copy

Full Screen

...20class TestKeywordHandler(RapidTest):21 """Tests for rapidsms.contrib.handlers.handlers.keyword"""22 def setUp(self):23 self.connection = self.create_connection()24 def _check_dispatch(self, text, correct_response):25 msg = IncomingMessage(self.connection, text)26 retVal = EchoKeywordHandler.dispatch(self.router, msg)27 if correct_response is not None:28 self.assertTrue(retVal)29 self.assertEqual(len(msg.responses), 1)30 self.assertEqual(msg.responses[0]['text'], correct_response)31 else:32 self.assertFalse(retVal)33 self.assertEqual(len(msg.responses), 0)34 def test_no_keyword(self):35 """Handler should raise an exception if there is no keyword."""36 keyword = getattr(EchoKeywordHandler, 'keyword')37 delattr(EchoKeywordHandler, 'keyword')38 try:39 with self.assertRaises(HandlerError):40 msg = IncomingMessage(self.connection, 'hello')41 EchoKeywordHandler.dispatch(self.router, msg)42 finally:43 setattr(EchoKeywordHandler, 'keyword', keyword)44 def test_no_match(self):45 """Handler should return nothing if there is no match."""46 self._check_dispatch('no match', None)47 def test_keyword_only(self):48 """Handler should call help() if only keyword is sent."""49 self._check_dispatch('hello', EchoKeywordHandler.HELP_TEXT)50 def test_keyword_and_whitespace(self):51 """Handler should call help() if only whitespace is after keyword."""52 self._check_dispatch('hello ', EchoKeywordHandler.HELP_TEXT)53 def test_keyword_and_one_space(self):54 """Handler should call help() if only one space is after keyword."""55 self._check_dispatch('hello ', EchoKeywordHandler.HELP_TEXT)56 def test_punctuation(self):57 """Handler treats comma colon and semicolon same as whitespace58 between keyword and rest of line"""59 self._check_dispatch('hello,', EchoKeywordHandler.HELP_TEXT)60 self._check_dispatch('hello,,', EchoKeywordHandler.HELP_TEXT)61 self._check_dispatch('hello,world', 'world')62 self._check_dispatch('hello:', EchoKeywordHandler.HELP_TEXT)63 self._check_dispatch('hello::', EchoKeywordHandler.HELP_TEXT)64 self._check_dispatch('hello:world', 'world')65 self._check_dispatch('hello;', EchoKeywordHandler.HELP_TEXT)66 self._check_dispatch('hello;;', EchoKeywordHandler.HELP_TEXT)67 self._check_dispatch('hello;world', 'world')68 self._check_dispatch('hello,;:', EchoKeywordHandler.HELP_TEXT)69 self._check_dispatch('hello,;,;:', EchoKeywordHandler.HELP_TEXT)70 self._check_dispatch('hello;,:,:world', 'world')71 def test_match(self):72 """73 Handler should call handle() if there is non-whitespace text after74 keyword.75 """76 self._check_dispatch('hello world', 'world')77 def test_case_insensitive_match(self):78 """Handler should use case-insensitive match."""79 self._check_dispatch('HeLlO World', 'World')80 def test_intermediate_whitespace(self):81 """All whitespace between keyword and text is ignored"""82 self._check_dispatch('hello world', 'world')83 def test_trailing_whitespace(self):84 """Trailing whitespace should be passed to handler."""85 self._check_dispatch('hello world ', 'world ')86 def test_leading_whitespace(self):87 """Prepended whitespace should not be passed to the handler."""88 self._check_dispatch(' hello world', 'world')89 def test_rest_of_line(self):90 """Everything from the first char that's not space comma colon91 or semicolon is passed to the handler"""92 self._check_dispatch('hello x , : ; sdf ,: ',93 'x , : ; sdf ,: ')94 def test_intermediate_newline(self):95 """A newline in the middle of the text"""96 self._check_dispatch('hello x \n y \n z', 'x \n y \n z')97 def test_newline_just_after_keyword(self):98 """A newline just after the keyword and before the text is ignored"""99 self._check_dispatch('hello \n x y z', 'x y z')100class TestPatternHandler(RapidTest):101 """Tests for rapidsms.contrib.handlers.handlers.pattern"""102 def setUp(self):103 self.connection = self.create_connection()104 def _check_dispatch(self, text, correct_response):105 msg = IncomingMessage(self.connection, text)106 retVal = AdditionPatternHandler.dispatch(self.router, msg)107 if correct_response is not None:108 self.assertTrue(retVal)109 self.assertEqual(len(msg.responses), 1)110 self.assertEqual(msg.responses[0]['text'], correct_response)111 else:112 self.assertFalse(retVal)113 self.assertEqual(len(msg.responses), 0)114 def test_no_pattern(self):115 """Handler should not operate if it does not have a pattern."""116 pattern = getattr(AdditionPatternHandler, 'pattern')117 delattr(AdditionPatternHandler, 'pattern')118 try:119 with self.assertRaises(HandlerError):120 msg = IncomingMessage(self.connection, '1 plus 2')121 AdditionPatternHandler.dispatch(self.router, msg)122 finally:123 setattr(AdditionPatternHandler, 'pattern', pattern)124 def test_no_match(self):125 """Handler should return False if there is no match."""126 self._check_dispatch('no match', None)127 def test_match(self):128 """Handler should return response if there is a match."""129 self._check_dispatch('1 plus 2', '1 + 2 = 3')130 def test_case_insensitive_match(self):131 """Handler pattern is not case sensitive."""132 self._check_dispatch('1 PLUS 2', '1 + 2 = 3')133 def test_leading_whitespace(self):134 """Handler pattern is sensitive to leading whitespace."""135 self._check_dispatch(' 1 plus 2', None)136 def test_trailing_whitespace(self):137 """Handler pattern is sensitive to trailing whitespace."""138 self._check_dispatch('1 plus 2 ', None)139 def test_extra_whitespace(self):140 """Handler pattern is sensitive to extra whitespace."""...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful