Example #1
0
    def test_handle_message_unsub_when_subbed(self, send_mock):
        self.db_mock.user_exists.return_value = True
        sender_psid = 1234

        webhook.handle_message(sender_psid, msbot.constants.GOODBYE_CMD)
        send_mock.assert_called_once_with(
            sender_psid,
            webhook.to_text_response(msbot.constants.RESP_UNSUBBED))
Example #2
0
    def test_handle_message_asap_when_subbed(self, send_mock):
        self.db_mock.user_exists.return_value = True
        sender_psid = 1234

        webhook.handle_message(sender_psid, msbot.constants.ASAP_MODE_CMD)
        self.db_mock.update_user.assert_called_once_with(
            sender_psid,
            options={
                msbot.constants.UPDATE_MODE: msbot.constants.ASAP_MODE_CMD
            })
        send_mock.assert_called_once_with(
            sender_psid,
            webhook.to_text_response(
                msbot.constants.RESP_MODE_COMPLETE.format(
                    update_mode=msbot.constants.ASAP_MODE_CMD)))
Example #3
0
    def test_handle_message_duplicate_when_subbed_toggles_false(
            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.DUPLICATES: False})))

        text = msbot.constants.RESP_DUPLICATE_TOGGLE_COMPLETE.format(
            duplicate_status=msbot.constants.ON)

        webhook.handle_message(sender_psid, msbot.constants.DUPLICATES_CMD)
        self.db_mock.update_user.assert_called_once_with(
            sender_psid, options={msbot.constants.DUPLICATES: True})
        send_mock.assert_called_once_with(
            sender_psid,
            webhook.to_text_response(
                msbot.constants.RESP_DUPLICATE_TOGGLE_COMPLETE.format(
                    duplicate_status=msbot.constants.ON)))
Example #4
0
    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)
Example #5
0
    def test_handle_message_recent_when_subbed(self, spoil_mock, send_mock):
        alice = User(('Alice', 8, 8, '{}'))
        latest_date = '2019-02-02'
        spoiler1 = Spoiler(('spoil1', 'attach1', latest_date, None))
        spoiler2 = Spoiler(('spoil2', 'attach2', latest_date, None))

        self.db_mock.user_exists.return_value = True
        self.db_mock.get_user_from_id.return_value = User(
            ('Alice', 8, 8, '{}'))

        latest_spoiler = 8
        self.db_mock.get_latest_spoiler_id.return_value = latest_spoiler
        self.db_mock.get_latest_spoiler_date.return_value = latest_date
        self.db_mock.get_all_spoilers_on_date.return_value = [
            spoiler1,
            spoiler2,
        ]

        sender_psid = 1234

        # new spoilers
        webhook.handle_message(sender_psid, msbot.constants.RECENT_CMD)
        calls = [
            mock.call(alice, spoiler1),
            mock.call(alice, spoiler2),
        ]

        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_LAST_SPOILER_INFO.format(
                    date_string=latest_date)))
        self.db_mock.update_user.assert_called_once_with(
            alice.user_id,
            last_updated=latest_spoiler,
            last_spoiled=latest_spoiler)
Example #6
0
 def test_to_text_response(self):
     text = 'test_text'
     self.assertDictEqual(webhook.to_text_response(text),
                          {msbot.constants.TEXT: text})