def test_handle_message_invalid_when_subbed(self, send_mock): self.db_mock.user_exists.return_value = True sender_psid = 1234 webhook.handle_message(sender_psid, 'unsupported_message') send_mock.assert_called_once_with( sender_psid, webhook.text_quick_reply_response( msbot.constants.RESP_INVALID_SUBBED, [webhook.INFO_BUTTON]))
def test_handle_message_info_when_subbed(self, send_mock): self.db_mock.user_exists.return_value = True sender_psid = 1234 webhook.handle_message(sender_psid, msbot.constants.INFO_CMD) send_mock.assert_called_once_with( sender_psid, webhook.text_quick_reply_response(msbot.constants.RESP_INFO_PROMPT, webhook.INFO_PROMPT_BUTTONS))
def test_handle_message_sub_when_unsubbed(self, send_mock): self.db_mock.user_exists.return_value = False sender_psid = 1234 webhook.handle_message(sender_psid, msbot.constants.HELLO_CMD) self.db_mock.add_user.assert_called_once_with(sender_psid) send_mock.assert_called_once_with( sender_psid, webhook.text_quick_reply_response(msbot.constants.RESP_SUBBED, [webhook.INFO_BUTTON]))
def test_text_quick_reply_response(self): text = 'test_text' buttons = [ webhook.create_quick_reply_button('test1'), webhook.create_quick_reply_button('test2'), webhook.create_quick_reply_button('test3'), ] self.assertDictEqual(webhook.text_quick_reply_response(text, buttons), { msbot.constants.TEXT: text, msbot.constants.QUICK_REPLIES: buttons, })
def test_handle_message_options_when_subbed_duplicates_on(self, send_mock): self.db_mock.user_exists.return_value = True options_dict = {msbot.constants.DUPLICATES: True} sender_psid = 1234 self.db_mock.get_user_from_id.return_value = User( (sender_psid, 0, 0, json.dumps(options_dict))) webhook.handle_message(sender_psid, msbot.constants.OPTIONS_CMD) send_mock.assert_called_once_with( sender_psid, webhook.text_quick_reply_response( msbot.constants.RESP_OPTIONS_PROMPT.format( duplicate_status=msbot.constants.ON), webhook.OPTIONS_PROMPT_BUTTONS))
def test_handle_message_mode_when_subbed(self, send_mock): self.db_mock.user_exists.return_value = True sender_psid = 1234 self.db_mock.get_user_from_id.return_value = User( ('Alice', 0, 0, json.dumps( {msbot.constants.UPDATE_MODE: msbot.constants.POLL_MODE_CMD}))) text = msbot.constants.RESP_MODE_PROMPT.format( update_mode=msbot.constants.POLL_MODE_CMD) webhook.handle_message(sender_psid, msbot.constants.MODE_CMD) send_mock.assert_called_once_with( sender_psid, webhook.text_quick_reply_response(text, webhook.UPDATE_MODE_BUTTONS))
def test_handle_message_send_when_subbed(self, spoil_mock, send_mock): alice = User(('Alice', 5, 5, '{}')) spoiler1 = Spoiler(('spoila', 'attach1', '2019-01-01', None)) spoiler2 = Spoiler(('spoilb', 'attach2', '2019-01-01', None)) spoiler3 = Spoiler(('spoilc', 'attach3', '2019-01-01', None)) self.db_mock.user_exists.return_value = True self.db_mock.get_user_from_id.return_value = User( ('Alice', 5, 5, '{}')) latest_spoiler = 8 self.db_mock.get_latest_spoiler_id.return_value = latest_spoiler self.db_mock.get_spoilers_later_than.return_value = [] sender_psid = 1234 # no new spoilers webhook.handle_message(sender_psid, msbot.constants.SEND_CMD) send_mock.assert_called_once_with( sender_psid, webhook.text_quick_reply_response( msbot.constants.RESP_UPDATE_UPDATED, [webhook.RECENT_BUTTON])) # new spoilers send_mock.reset_mock() self.db_mock.get_spoilers_later_than.return_value = [ spoiler1, spoiler2, spoiler3, ] webhook.handle_message(sender_psid, msbot.constants.SEND_CMD) calls = [ mock.call(alice, spoiler1), mock.call(alice, spoiler2), mock.call(alice, spoiler3), ] spoil_mock.assert_has_calls(calls, any_order=True) self.assertEqual(spoil_mock.call_count, len(calls)) send_mock.assert_called_once_with( sender_psid, webhook.to_text_response(msbot.constants.RESP_UPDATE_COMPLETE)) self.db_mock.update_user.assert_called_once_with( alice.user_id, last_updated=latest_spoiler, last_spoiled=latest_spoiler)