Ejemplo n.º 1
0
def generic_job(bot, id):
    """Generic bot that initiates a coach."""
    with db.transaction():
        job = Job.get(id=id)
        job.user.state = job.state
        job.user.active_coach = job.coach
        job.user.save()
        bot.sendMessage(job.user.telegram_id, text=job.text)
Ejemplo n.º 2
0
def generic_job(bot, id):
    """Generic bot that initiates a coach."""
    with db.transaction():
        job = Job.get(id=id)
        job.user.state = job.state
        job.user.active_coach = job.coach
        job.user.save()
        bot.sendMessage(job.user.telegram_id, text=job.text)
Ejemplo n.º 3
0
    def test_handle(self, bot, menu_update, test_db, tguser, updater):
        """Test display of main menu."""
        with test_database(test_db, [User, Record], fail_silently=True):
            with db.transaction():
                user, created = User.tg_get_or_create(tguser)
                user.state = menu_update.states[0]
                user.save()

            coach = Menu(bot, db, tguser, updater.job_queue)
            msgs = coach.handle(menu_update)

            assert len(msgs) > 0
Ejemplo n.º 4
0
    def test_handle(self, bot, menu_update, test_db, tguser, updater):
        """Test display of main menu."""
        with test_database(test_db, [User, Record], fail_silently=True):
            with db.transaction():
                user, created = User.tg_get_or_create(tguser)
                user.state = menu_update.states[0]
                user.save()

            coach = Menu(bot, db, tguser, updater.job_queue)
            msgs = coach.handle(menu_update)

            assert len(msgs) > 0
Ejemplo n.º 5
0
    def test_diary_entry(self, bot, test_db, tguser, updater):
        """Test diary entry from main menu."""
        diary_entry = "My secret diary."

        with test_database(test_db, [User, Record], fail_silently=True):
            with db.transaction():
                user, created = User.tg_get_or_create(tguser)
                user.state = Menu.AWAITING_DIARY_ENTRY
                user.save()

            coach = Menu(bot, db, tguser, updater.job_queue)
            msgs = coach.handle(custom_update(msg=diary_entry))

            assert len(msgs) == 1

            rec = Record.get(Record.content == diary_entry)
            assert isinstance(rec, Record)
Ejemplo n.º 6
0
    def test_diary_entry(self, bot, test_db, tguser, updater):
        """Test diary entry from main menu."""
        diary_entry = "My secret diary."

        with test_database(test_db, [User, Record], fail_silently=True):
            with db.transaction():
                user, created = User.tg_get_or_create(tguser)
                user.state = Menu.AWAITING_DIARY_ENTRY
                user.save()

            coach = Menu(bot, db, tguser, updater.job_queue)
            msgs = coach.handle(custom_update(msg=diary_entry))

            assert len(msgs) == 1

            rec = Record.get(Record.content == diary_entry)
            assert isinstance(rec, Record)
Ejemplo n.º 7
0
    def test_handle(self, bot, setup_update, test_db, updater):
        """Test setup handler."""
        with test_database(test_db, [User], fail_silently=True):
            with db.transaction():
                user, created = User.tg_get_or_create(
                    setup_update.message.from_user)
                user.state = setup_update.states[0]
                user.save()

            coach = Setup(bot, test_db, setup_update.message.from_user, updater.job_queue)
            messages = coach.handle(setup_update)

            user, created = User.tg_get_or_create(
                setup_update.message.from_user)

            assert len(messages) > 0
            assert user.state == setup_update.states[1]
Ejemplo n.º 8
0
    def test_handle(self, bot, setup_update, test_db, updater):
        """Test setup handler."""
        with test_database(test_db, [User], fail_silently=True):
            with db.transaction():
                user, created = User.tg_get_or_create(
                    setup_update.message.from_user)
                user.state = setup_update.states[0]
                user.save()

            coach = Setup(bot, test_db, setup_update.message.from_user,
                          updater.job_queue)
            messages = coach.handle(setup_update)

            user, created = User.tg_get_or_create(
                setup_update.message.from_user)

            assert len(messages) > 0
            assert user.state == setup_update.states[1]
Ejemplo n.º 9
0
    def test_handle_inline(self, bot, coach_query, test_db, updater):
        """Test setup handler."""
        query = coach_query.callback_query
        with test_database(test_db, [User], fail_silently=True):
            with db.transaction():
                user, created = User.get_or_create(
                    telegram_id=query.message.from_user.id,
                    name='Pepe',
                    chat_id=query.message.from_user.id)
                user.state = coach_query.states[0]
                user.save()

            coach = Setup(bot, test_db, query.message.from_user, updater.job_queue)
            messages = coach.handle(coach_query)

            user = User.get(User.telegram_id == user.telegram_id)

            assert len(messages) > 0
            assert user.state == coach_query.states[1]
Ejemplo n.º 10
0
    def test_handle_inline(self, bot, coach_query, test_db, updater):
        """Test setup handler."""
        query = coach_query.callback_query
        with test_database(test_db, [User], fail_silently=True):
            with db.transaction():
                user, created = User.get_or_create(
                    telegram_id=query.message.from_user.id,
                    name='Pepe',
                    chat_id=query.message.from_user.id)
                user.state = coach_query.states[0]
                user.save()

            coach = Setup(bot, test_db, query.message.from_user,
                          updater.job_queue)
            messages = coach.handle(coach_query)

            user = User.get(User.telegram_id == user.telegram_id)

            assert len(messages) > 0
            assert user.state == coach_query.states[1]