コード例 #1
0
    def test_success_AddCarNr(self):
        message = RequestPayloadUT([
            "MESSAGE_REQUEST", "{{" + CMD_ADD_CAR_NR + "}}", "time_12:00",
            "user_id"
        ])
        rq = Request(message)
        # first entering into chat
        # ->incoming() with ViberMessageRequest called
        self.assertTrue(rq.state == 'NEW')
        self.assertTrue(rq.need_input() is False)

        rq.advance()
        self.assertTrue(rq.state == 'IDENTIFY')
        self.assertTrue(rq._user_identified is False)
        self.assertTrue(rq._user_confirmed is False)
        self.assertTrue(rq.need_input() is False)
        self.assertTrue(rq.get_message_out() == TXT_IDENTIFY__NEW_USER)
        self.assertTrue(rq.get_kbd().eq(
            Keyboard([
                Keyboard.cmd_button(CMD_REG_TEL),
                Keyboard.cmd_button(CMD_ADD_NAME),
                Keyboard.cmd_button(CMD_ADD_CAR_NR),
                Keyboard.cmd_button(CMD_ADD_HOME_FLAT_NR)
            ])))

        rq.advance()
        self.assertTrue(rq.state == 'ADD_CAR_NR')
        self.assertTrue(rq._user_identified is False)
        self.assertTrue(rq._user_confirmed is False)
        self.assertTrue(rq.need_input() is True)
        self.assertTrue(rq.get_message_out() == TXT_ADD_CAR_NR)
        self.assertTrue(rq.get_kbd().eq(Keyboard([])))
        message._payload[1] = 'вн1984не'

        rq.advance()
        self.assertTrue(rq.state == 'GOT_CAR_NR')
        self.assertTrue(rq._user_identified is False)
        self.assertTrue(rq._user_confirmed is False)
        self.assertTrue(rq.need_input() is False)
        self.assertTrue(rq.get_message_out() == TXT_GOT_CAR_NR)
        self.assertTrue(rq.get_kbd().eq(KBD_ALL_KEYS))

        rq.advance()
        self.assertTrue(rq.state == 'UPDATE_DB')
        self.assertTrue(rq._user_identified is False)
        self.assertTrue(rq._user_confirmed is False)
        self.assertTrue(rq.need_input() is False)
        self.assertTrue(rq.get_message_out() == TXT_GOT_CAR_NR)
        self.assertTrue(rq.get_kbd().eq(KBD_ALL_KEYS))

        rq.advance()
        self.assertTrue(rq.state == 'DELETE')
        self.assertTrue(rq.get_message_out() == TXT_GOT_CAR_NR)
        self.assertTrue(rq.need_input() is True)
コード例 #2
0
Спасибо. Номер машины {} введен.
"""
TXT_ADD_NAME = """
Введите ваше имя:
"""
TXT_GOT_NAME = """
Спасибо. {}, Ваше имя добавлено.
"""
ERR_TEL_NR = """
Убедитесь в правильности ввода телефона.
"""
ERR_GENERAL = """
Неведомая ошибка.
"""
KBD_ALL_KEYS = Keyboard([
    Keyboard.cmd_button(CMD_REG_TEL),
    Keyboard.cmd_button(CMD_ADD_NAME),
    Keyboard.cmd_button(CMD_ADD_CAR_NR),
    Keyboard.cmd_button(CMD_ADD_HOME_FLAT_NR)
])


# ---
class Request(object):

    # --- validity checks ---
    def is_tel_nr_valid(self):
        print("is_telephone_nr_valid()")
        self._user_telephone = self._payload.text()
        return not re.match(r'[+]380\d{2}\d{7}', self._user_telephone) is None