Ejemplo n.º 1
0
    def setUp(self):
        self.user_session = UserSession('1488228')

        self.user_session.to_waiting_pizza_type()

        DialogEngine.process_message(self.user_session, Options.pizza_big)

        DialogEngine.process_message(self.user_session, Options.payment_card)
Ejemplo n.º 2
0
    def test_order_verifying_verify_choice(self):
        message = DialogEngine.process_message(self.user_session,
                                               Options.order_verify)

        self.assertEqual(message, Messages.order_created)

        self.assertTrue(self.user_session.is_initial())
Ejemplo n.º 3
0
    def test_order_verifying_decline_choice(self):
        messages = DialogEngine.process_message(self.user_session,
                                                Options.order_decline)

        self.assertListEqual(messages,
                             [Messages.restart_order, Messages.choose_pizza])

        self.assertTrue(self.user_session.is_waiting_pizza_type())
Ejemplo n.º 4
0
    def test_payment_choosing_wrong_choice(self):
        previous_state = self.user_session.state

        message = DialogEngine.process_message(self.user_session,
                                               'любой неверный выбор')

        self.assertEqual(message, Messages.error)

        self.assertEqual(previous_state, self.user_session.state)
Ejemplo n.º 5
0
    def test_pizza_choosing_big_pizza_choice(self):
        message = DialogEngine.process_message(self.user_session,
                                               Options.pizza_big)

        self.assertEqual(message, Messages.choose_payment)

        self.assertTrue(self.user_session.is_waiting_payment_method())

        self.assertEqual(self.user_session.pizza_type, PizzaType.big)
Ejemplo n.º 6
0
    def test_order_verifying_wrong_choice(self):
        previous_state = self.user_session.state

        message = DialogEngine.process_message(self.user_session,
                                               'любой текст')

        self.assertEqual(message, Messages.error)

        self.assertEqual(self.user_session.state, previous_state)
Ejemplo n.º 7
0
def handle_text(message):
    message_text = message.text

    chat_id = str(message.chat.id)

    session = get_user_session(chat_id)

    answer_messages = DialogEngine.process_message(session, message_text)

    send_messages(chat_id, answer_messages)
Ejemplo n.º 8
0
    def test_payment_choosing_card_choice(self):
        message = DialogEngine.process_message(self.user_session,
                                               Options.payment_card)

        self.assertEqual(
            message,
            Messages.verify_order_msg(PizzaType.big, PaymentMethod.card))

        self.assertTrue(self.user_session.is_verifying_order())

        self.assertEqual(self.user_session.payment_method, PaymentMethod.card)
Ejemplo n.º 9
0
    def test_init_dialog(self):
        messages = DialogEngine.process_message(
            self.user_session, 'любое сообщение для начала диалога')

        self.assertEqual(len(messages),
                         2,
                         msg='в первом состоянии должно быть два сообщения')

        self.assertListEqual(messages, [Messages.hello, Messages.choose_pizza])

        self.assertTrue(self.user_session.is_waiting_pizza_type())
Ejemplo n.º 10
0
def handle_commands(message):
    chat_id = str(message.chat.id)

    session = get_user_session(chat_id)

    if session.state == 'initial':
        messages = DialogEngine.process_message(session, 'initial')

        send_messages(chat_id, messages)

    else:
        bot.reply_to(
            message,
            "Я - бот для заказа пиццы. Чтобы сделать заказ, следуй моим инструкциям"
        )