Exemple #1
0
 async def test_process__by_contact(self, is_user_phone):
     user = UserFactory()
     tested = PhoneState(user, {})
     tested.contact = InputContact(phone='375292020327',
                                   is_user_phone=is_user_phone)
     await tested.process()
     assert user.phone == '375292020327'
 async def f():
     user = UserFactory()
     ConversationService.add_bot_message(user, 'Hello world!',
                                         'telegram')
     assert ConversationService.filter_by(user=user).count() == 1
     message = ConversationService.filter_by(user=user).first()
     assert message.is_user_message is False
     assert message.messenger == 'telegram'
Exemple #3
0
 def test_consume__navigation(self, value):
     tested = TimeState(UserFactory(), {'state': 'time', })
     tested.value = value
     asyncio.get_event_loop().run_until_complete(
         tested.process()
     )
     assert tested.data['state'] == 'time'
     assert tested.data['timeperiod'] == value
Exemple #4
0
 def test_consume__optimistic(self, patched, value, messager, is_morning, is_evening, expected):
     tested = TimeState(UserFactory(), {})
     tested.value = value
     tested.messager = messager
     asyncio.get_event_loop().run_until_complete(
         tested.process()
     )
     assert tested.data['state'] == 'show'
     assert tested.data['trip_id_list'] == [1]
     patched.assert_called_once_with(expected, is_morning, is_evening)
 async def f():
     user = UserFactory()
     assert ConversationService.filter_by(user=user).count() == 0
     ConversationService.add_user_message(user, 'Hello world!',
                                          {'hello': 'world'},
                                          'telegram')
     assert ConversationService.filter_by(user=user).count() == 1
     message = ConversationService.filter_by(user=user).first()
     assert message.is_user_message
     assert message.messenger == 'telegram'
     assert message.context['hello'] == 'world'
Exemple #6
0
 async def test_process__invalid_text(self, text):
     user = UserFactory()
     tested = PhoneState(user, {})
     tested.text = text
     await tested.process()
     assert tested.message_was_not_recognized
Exemple #7
0
 async def test_process__valid_text(self, text):
     user = UserFactory()
     tested = PhoneState(user, {})
     tested.text = text
     await tested.process()
     assert user.phone == '375292020327'
Exemple #8
0
 def test_consume__back(self):
     tested = TimeState(UserFactory(), {})
     asyncio.get_event_loop().run_until_complete(
         tested.consume(InputMessage(data='back'))
     )
     assert tested.data['state'] == 'timeperiod'