def test_add_friend_with_two_users(self): user_1 = factory(User).create(lang='ru') user_2 = factory(User).create(lang='ru') user_1.add_friend() self.assertEqual(user_1.friend().id, user_2.id) self.assertEqual(user_2.friend().id, user_1.id)
def test_del_friend(self): user_1 = factory(User).create() user_2 = factory(User).create() self.__make_friends(user_1, user_2) user_1.del_friend() self.assertEqual(user_1.friend(), None)
def test_event_new_message_set_ru_language(self, n1_send_message): user_id = 1 user_chat_id = 10 lang = 'ru' factory(User).create(id=user_id, chat_id=user_chat_id) self.__run_bot('message/new', { 'sender_id': user_id, 'content': '2', }) n1_send_message.assert_called_once_with(user_chat_id, locales[lang]['message_help'], mock.ANY)
def test_search(self): factory(User).create(lang='ru') self.__run_command('поиск') self.send_message_mock.assert_has_calls([ mock.call(mock.ANY, 'message_friend_search'), mock.call(mock.ANY, 'message_friend_found'), mock.call(mock.ANY, 'message_friend_found_user'), ]) self.assertEqual(self.user.status, User.statuses['active']) self.assertEqual(self.user.friend().status, User.statuses['idle'])
def test_event_user_unfollow_with_friend(self, n1_send_message): user_1 = factory(User).create() user_2 = factory(User).create() factory(Chat).create( user_1=user_1.id, user_2=user_2.id ) self.__run_bot('user/unfollow', { 'id': user_1.id, }) n1_send_message.assert_called_once_with(user_2.chat_id, 'message_friend_gone', mock.ANY)
def test_event_user_unfollow(self): user = factory(User).create(status=User.statuses['active']) self.__run_bot('user/unfollow', { 'id': user.id, }) user_to_check = User.find(user.id) self.assertEqual(user_to_check.status, User.statuses['not_active'])
def test_event_new_message_with_friend(self, n1_send_message): user_2_chat_id = 10 user_1 = factory(User).create(lang='ru') user_2 = factory(User).create(chat_id=user_2_chat_id, lang='ru') factory(Chat).create( user_1=user_1.id, user_2=user_2.id ) self.__run_bot('message/new', { 'sender_id': user_1.id, 'content': 'Hello', 'type': 'text/plain', }) check_content = locales[user_2.lang]['text_friend'] + ': ' + 'Hello' n1_send_message.assert_called_once_with(user_2_chat_id, check_content, 'text/plain')
def test_event_new_message_with_no_language(self, n1_send_message): user_id = 1 user_chat_id = 10 user = factory(User).create(id=user_id, chat_id=user_chat_id) self.__run_bot('message/new', { 'sender_id': user_id, 'content': 'text', }) n1_send_message.assert_called_once_with(user_chat_id, locales[user.lang]['message_choose_language'], mock.ANY)
def test_event_close_idle_chats(self, n1_send_message): user_1_chat_id = 1 user_2_chat_id = 2 user_1 = factory(User).create(chat_id = user_1_chat_id) user_2 = factory(User).create(chat_id = user_2_chat_id) chat_1 = factory(Chat).create( user_1=user_1.id, user_2=user_2.id, started_at='2000-01-01 00:00:00' ) self.__run_bot('cron/close_idle_chats') n1_send_message.assert_has_calls([ mock.call(user_1_chat_id, 'message_chat_close_friend', mock.ANY), mock.call(user_2_chat_id, 'message_chat_close_user', mock.ANY) ]) self.assertEqual(Chat.find(chat_1.id), None)
def test_event_new_message_with_no_friend(self, n1_send_message): user_chat_id = 10 user = factory(User).create(chat_id=user_chat_id, lang='ru', status=User.statuses['idle']) self.__run_bot('message/new', { 'sender_id': user.id, 'content': '', }) user_to_check = User.find_or_fail(user.id) self.assertEqual(user_to_check.status, User.statuses['active']) n1_send_message.assert_called_once_with(user_chat_id, locales[user.lang]['message_no_friend'], mock.ANY)
def test_add_friend_with_different_users(self): active_user_1 = factory(User).create(status=User.statuses['active'], lang='ru') active_user_2 = factory(User).create(status=User.statuses['active'], lang='ru') factory(User).make(status=User.statuses['idle'], lang='ru') factory(User).make(status=User.statuses['not_active'], lang='ru') active_user_1.add_friend() self.assertEqual(active_user_1.friend().id, active_user_2.id)
def __make_friends(user_1, user_2): factory(Chat).create(user_1=user_1.id, user_2=user_2.id)
def setUp(self): db.begin_transaction() self.user = factory(User).create(lang='ru') self.send_message_mock = mock.Mock()
def test_set_status_active(self): user = factory(User).create(status=User.statuses['idle']) user.set_status('active') self.assertEqual(user.status, User.statuses['active'])
def test_add_friend_with_one_user(self): user_1 = factory(User).create() self.assertFalse(user_1.add_friend())
def test_friend(self): user = factory(User).create() self.assertEqual(user.friend(), None)
def test_set_status_wrong(self): user = factory(User).create(status=User.statuses['idle']) user.set_status('status_that_does_not_exist') self.assertEqual(user.status, User.statuses['idle'])