Пример #1
0
    def test_bot_sending_published_bulletins(self, client):
        " sending_published_bulletins -> start_bulletin_reading "

        (_, account) = self.create_user_account()
        chat_user = self.create_chat_user(account)

        bot = TelegramBot(account.id)
        bot.bot = Mock()
        bot.handle_message(self.get_telegram_message(text=account.welcome_answer_2_option_1))
        assert bot.bot.sendMessage.call_args[0][1] == account.up_to_date_message

        bulletin = self.create_bulletin(account, is_published=True)
        story = self.create_story(bulletin, lead='start-story')
        self.create_fragment_answer(story, action='c', text='read it')

        bot.bot.reset_mock()
        bot.sending_published_bulletins()

        assert bot.bot.sendMessage.call_args[0][1] == 'start-story'
        assert bot.bot.sendMessage.call_args[1]['reply_markup']['keyboard'] == [['read it']]

        chat_user.reload()
        chat_user.state == ChatUser.STATE_WAITING_ANSWER
Пример #2
0
    def test_bot_sending_published_bulletins2(self, client):
        " sending_published_bulletins -> switch_next_bulletin "

        (_, account) = self.create_user_account()

        bulletin1 = self.create_bulletin(account, title='bulletin1', is_published=True)
        story1 = self.create_story(bulletin1, lead='story1')
        self.create_fragment_answer(story1, action='n', text='next')
        self.create_fragment_paragraph(story1, text='paragraph1')
        story2 = self.create_story(bulletin1, lead='story2')
        self.create_fragment_answer(story2, action='n', text='next')
        self.create_fragment_paragraph(story2, text='paragraph2')

        bulletin2 = self.create_bulletin(account, title='bulletin2', is_published=True)
        story3 = self.create_story(bulletin2, lead='story3')
        self.create_fragment_answer(story3, action='n', text='next')
        self.create_fragment_paragraph(story3, text='paragraph3')

        self.create_chat_user(account)

        bot = TelegramBot(account.id)
        bot.bot = Mock()
        bot.handle_message(self.get_telegram_message(text=account.welcome_answer_2_option_1))
        assert bot.bot.sendMessage.call_args[0][1] == 'story1'

        bot.bot.reset_mock()
        bot.sending_published_bulletins()
        assert bot.bot.sendMessage.call_args is None

        bot.sending_published_bulletins()
        assert bot.bot.sendMessage.call_args is None

        bot.sending_published_bulletins()
        assert bot.bot.sendMessage.call_args is None

        bot.sending_published_bulletins()
        assert bot.bot.sendMessage.call_args[0][1] == 'story3'