Extract StubBotTestCase.make_request_message().
This de-duplicates some code and also makes it a bit easier in the future to override how we create messages.
This commit is contained in:
parent
5686d603ef
commit
7bc79a8911
|
@ -103,16 +103,25 @@ class StubBotTestCase(TestCase):
|
||||||
bot.handle_message(message, bot_handler)
|
bot.handle_message(message, bot_handler)
|
||||||
return bot_handler.unique_response()
|
return bot_handler.unique_response()
|
||||||
|
|
||||||
def verify_reply(self, request, response):
|
def make_request_message(self, content):
|
||||||
# type: (str, str) -> None
|
# type: (str) -> Dict[str, Any]
|
||||||
|
'''
|
||||||
bot, bot_handler = self._get_handlers()
|
This is mostly used internally but
|
||||||
|
tests can override this behavior by
|
||||||
|
mocking/subclassing.
|
||||||
|
'''
|
||||||
message = dict(
|
message = dict(
|
||||||
|
display_recipient='foo_stream',
|
||||||
sender_email='foo@example.com',
|
sender_email='foo@example.com',
|
||||||
sender_full_name='Foo Test User',
|
sender_full_name='Foo Test User',
|
||||||
content=request,
|
content=content,
|
||||||
)
|
)
|
||||||
|
return message
|
||||||
|
|
||||||
|
def verify_reply(self, request, response):
|
||||||
|
# type: (str, str) -> None
|
||||||
|
bot, bot_handler = self._get_handlers()
|
||||||
|
message = self.make_request_message(request)
|
||||||
bot_handler.reset_transcript()
|
bot_handler.reset_transcript()
|
||||||
bot.handle_message(message, bot_handler)
|
bot.handle_message(message, bot_handler)
|
||||||
reply = bot_handler.unique_reply()
|
reply = bot_handler.unique_reply()
|
||||||
|
@ -125,12 +134,7 @@ class StubBotTestCase(TestCase):
|
||||||
bot, bot_handler = self._get_handlers()
|
bot, bot_handler = self._get_handlers()
|
||||||
|
|
||||||
for (request, expected_response) in conversation:
|
for (request, expected_response) in conversation:
|
||||||
message = dict(
|
message = self.make_request_message(request)
|
||||||
display_recipient='foo_stream',
|
|
||||||
sender_email='foo@example.com',
|
|
||||||
sender_full_name='Foo Test User',
|
|
||||||
content=request,
|
|
||||||
)
|
|
||||||
bot_handler.reset_transcript()
|
bot_handler.reset_transcript()
|
||||||
bot.handle_message(message, bot_handler)
|
bot.handle_message(message, bot_handler)
|
||||||
response = bot_handler.unique_response()
|
response = bot_handler.unique_response()
|
||||||
|
@ -142,11 +146,7 @@ class StubBotTestCase(TestCase):
|
||||||
self.assertNotEqual(bot.usage(), '')
|
self.assertNotEqual(bot.usage(), '')
|
||||||
|
|
||||||
def test_bot_responds_to_empty_message(self) -> None:
|
def test_bot_responds_to_empty_message(self) -> None:
|
||||||
message = dict(
|
message = self.make_request_message('')
|
||||||
sender_email='foo@example.com',
|
|
||||||
display_recipient='foo',
|
|
||||||
content='',
|
|
||||||
)
|
|
||||||
|
|
||||||
# get_response will fail if we don't respond at all
|
# get_response will fail if we don't respond at all
|
||||||
response = self.get_response(message)
|
response = self.get_response(message)
|
||||||
|
|
Loading…
Reference in a new issue