예제 #1
0
 def test_get_messages_limit(self):
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     # добавляем сообщения в цикле
     for i in range(5):
         text = 'msg_{}_{}'.format(tools.generate_random_string(7), i)
         func.send_text(self.api, self.team_uid, group_jid, text)
     limit = 3
     params = {'limit': limit}
     resp = self.api.get_messages(self.team_uid, group_jid, params).json()
     assert 'error' not in resp['result']
     assert len(resp['result']['messages']) == limit
예제 #2
0
 def test_get_messages_date_to_past(self):
     date_to = datetime.datetime.now() + datetime.timedelta(days=-1)
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # добавляем участников к группе
     group_jid = func.add_group(self.api, team_uid)['jid']
     # добавляем сообщения
     text = f'msg_{tools.generate_random_string(7)}'
     func.send_text(self.api, team_uid, group_jid, text)
     params = {
         'date_to': date_to,
     }
     resp = self.api.get_filtered_messages(team_uid, params).json()
     assert 'error' not in resp
     assert not resp['result']['objects']
예제 #3
0
 def test_get_messages(self):
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     # добавляем сообщения в цикле
     exp_msg = {}
     for i in range(5):
         # эта магия с i для того, чтобы ключи словаря exp_msg совпадали с ключами в resp т.к. в ответе есть всегда 2 дефолтных сообщения
         i = i + 2
         text = 'msg_{}_{}'.format(tools.generate_random_string(7), i)
         exp_msg[i] = text
         func.send_text(self.api, self.team_uid, group_jid, text)
     resp = self.api.get_messages(self.team_uid, group_jid).json()
     assert 'error' not in resp['result']
     assert len(resp['result']['messages']) == 7
     num = 6
     while num > 1:
         assert resp['result']['messages'][num]['content']['text'] == exp_msg[num]
         num = num - 1
예제 #4
0
 def test_get_filtered_messages_limit_offset(self):
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     exp_text = ''
     for i in range(5):
         text = 'msg_{}_{}'.format(tools.generate_random_string(7), i)
         func.send_text(self.api, self.team_uid, group_jid, text)
         # запоминаем текст сообщения
         if i == 0:
             exp_text = text
     params = {
         'limit': 1,
         'offset': 4,
     }
     resp = self.api.get_filtered_messages(self.team_uid, params).json()
     assert 'error' not in resp['result']
     assert len(resp['result']['objects']) == 1
     assert resp['result']['objects'][0]['content']['text'] == exp_text
예제 #5
0
 def test_get_messages_exact(self):
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     text = tools.generate_random_string(7)
     message_id = func.send_text(self.api, self.team_uid, group_jid, text)['message_id']
     params = {'exact': message_id}
     resp = self.api.get_messages(self.team_uid, group_jid, params).json()
     assert 'error' not in resp['result']
     assert len(resp['result']['messages']) == 1
     assert resp['result']['messages'][0]['content']['text'] == text
예제 #6
0
 def test_add_invalid_reaction(self):
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api,
                                 self.team_uid,
                                 self.group_jid,
                                 text=text)['message_id']
     resp = self.api.add_edit_reaction(self.team_uid, message_id,
                                       ':-)').json()
     assert resp['error'] == const.NOT_FOUND
예제 #7
0
 def test_get_messages_important(self):
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     group_jid = func.add_group(self.api, team_uid)['jid']
     func.send_text(self.api, team_uid, group_jid, 'hello')
     msg_data = {'text': 'important_message',
                 'important': True}
     #msg_data = json.dumps(msg_data)
     resp = self.api.send_msg_text(team_uid, group_jid, msg_data).json()
     tools.print_formatted_json(resp, ensure_ascii=False)
     params = {
         'important': 'true',
     }
     resp = self.api.get_filtered_messages(team_uid, params).json()
     tools.print_formatted_json(resp, ensure_ascii=False)
     assert 'error' not in resp
     assert len(resp['result']['objects']) == 1
     assert resp['result']['objects'][0]['important']
예제 #8
0
 def test_delete_reaction_owner_message_without_reactions(self):
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api,
                                 self.team_uid,
                                 self.group_jid,
                                 text=text)['message_id']
     resp = self.api.delete_my_reaction(self.team_uid, message_id,
                                        self.reaction3).json()
     assert 'error' not in resp
     assert resp['result'] is None
예제 #9
0
 def test_get_reaction_on_message_owner_not_exist_reaction(self):
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api,
                                 self.team_uid,
                                 self.group_jid,
                                 text=text)['message_id']
     self.api.add_edit_reaction(self.team_uid, message_id,
                                self.reaction1).json()
     resp = self.api.get_my_reaction_by_name(self.team_uid, message_id,
                                             self.reaction3).json()
     assert resp['error'] == const.NOT_FOUND
예제 #10
0
 def test_get_messages_type(self, type, text_filename):
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # приглашаем пользователей
     group_jid = func.add_group(self.api, team_uid)['jid']
     # добавляем сообщения
     func.send_text(self.api, team_uid, group_jid, 'hello')
     self.api.send_msg_file(team_uid, group_jid, os.path.join(const.TD_FILES, 'tiger.PNG'))
     self.api.send_msg_file(team_uid, group_jid, os.path.join(const.TD_FILES, 'video.mp4'))
     self.api.send_msg_file(team_uid, group_jid, os.path.join(const.TD_FILES, 'word.docx'))
     params = {
         'type': type,
     }
     resp = self.api.get_filtered_messages(team_uid, params).json()
     assert 'error' not in resp
     assert len(resp['result']['objects']) == 1
     if type == 'plain':
         assert resp['result']['objects'][0]['content']['text'] == text_filename
     else:
         assert resp['result']['objects'][0]['content']['name'] == text_filename
예제 #11
0
 def test_add_reaction_owner(self):
     owner_jid = func.get_my_jid(self.api, self.team_uid)
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api,
                                 self.team_uid,
                                 self.group_jid,
                                 text=text)['message_id']
     resp = self.api.add_edit_reaction(self.team_uid, message_id,
                                       self.reaction1).json()
     assert 'error' not in resp
     assert resp['result']['name'] == self.reaction1
     assert resp['result']['sender'] == owner_jid
예제 #12
0
 def test_get_messages_text(self):
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # приглашаем пользователей
     user1_jid = func.get_my_jid(self.api, team_uid)
     user2_jid = func.add_contact(self.api, team_uid, self.phone2)['jid']
     user3_jid = func.add_contact(self.api, team_uid, self.phone3)['jid']
     # добавляем участников к группе
     group_jid = func.add_group(self.api, team_uid)['jid']
     func.add_member_to_group(self.api, team_uid, group_jid, user2_jid, 'member')
     func.add_member_to_group(self.api, team_uid, group_jid, user3_jid, 'admin')
     # добавляем сообщения
     api2 = auth.login_another_user(self.url, self.phone2, self.code2)
     api3 = auth.login_another_user(self.url, self.phone3, self.code3)
     pattern = 'msg'
     text = f'{pattern}_{tools.generate_random_string(7)}'
     msg1 = f'1_{text}'
     msg2 = f'2_{text}'
     msg3 = 'hello'
     func.send_text(self.api, team_uid, group_jid, msg1)
     func.send_text(api2, team_uid, group_jid, msg2)
     func.send_text(api3, team_uid, group_jid, msg3)
     params = {
         'text': pattern,
     }
     resp = self.api.get_filtered_messages(team_uid, params).json()
     assert 'error' not in resp
     assert len(resp['result']['objects']) == 2
     assert resp['result']['objects'][0]['content']['text'] == msg2
     assert resp['result']['objects'][1]['content']['text'] == msg1
예제 #13
0
 def test_get_messages_chat(self):
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     group_jid_2 = func.add_group(self.api, self.team_uid)['jid']
     group_jid_3 = func.add_group(self.api, self.team_uid)['jid']
     # добавляем сообщения
     text = 'msg_{}'.format(tools.generate_random_string(7))
     func.send_text(self.api, self.team_uid, group_jid, text)
     func.send_text(self.api, self.team_uid, group_jid_2, text)
     func.send_text(self.api, self.team_uid, group_jid_3, text)
     params = {
         'chat': f'{group_jid},{group_jid_2}',
     }
     resp = self.api.get_filtered_messages(self.team_uid, params).json()
     assert 'error' not in resp
     assert tools.is_items_exist_in_list_of_dict(
         resp['result']['objects'],
         'chat',
         group_jid,
     )
     assert tools.is_items_exist_in_list_of_dict(
         resp['result']['objects'],
         'chat',
         group_jid_2,
     )
     assert not tools.is_items_exist_in_list_of_dict(
         resp['result']['objects'],
         'chat',
         group_jid_3,
     )
예제 #14
0
 def test_get_messages_unread(self):
     user2_jid = func.add_contact(self.api, self.team_uid, self.phone2)['jid']
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     func.add_member_to_group(self.api, self.team_uid, group_jid, user2_jid, 'admin')
     # добавляем сообщения в цикле
     exp_msg = {}
     for i in range(5):
         # эта магия с i для того, чтобы ключи словаря exp_msg совпадали с ключами в resp т.к. в ответе есть всегда 2 дефолтных сообщения
         i = i + 1
         text = 'msg_{}_{}'.format(tools.generate_random_string(7), i)
         exp_msg[i] = text
         func.send_text(self.api, self.team_uid, group_jid, text)
     auth_cookies = auth.login_with_cookies(self.url, self.phone2, self.code2)
     api2 = API(self.url, auth_cookies, is_token_auth=False)
     params = {'unread': True}
     resp = api2.get_messages(self.team_uid, group_jid, params).json()
     assert 'error' not in resp['result']
     assert len(resp['result']['messages']) == 6
     num = 5
     while num > 0:
         assert resp['result']['messages'][num]['content']['text'] == exp_msg[num]
         num = num - 1
예제 #15
0
 def test_get_messages_chat_type(self):
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # приглашаем пользователей
     user2_jid = func.add_contact(self.api, team_uid, self.phone2)['jid']
     # добавляем участников к группе
     group_jid = func.add_group(self.api, team_uid)['jid']
     func.add_member_to_group(self.api, team_uid, group_jid, user2_jid, 'member')
     # добавляем сообщения
     pattern = 'msg'
     text = f'{pattern}_{tools.generate_random_string(7)}'
     msg1 = f'1_{text}'
     msg2 = f'2_{text}'
     func.send_text(self.api, team_uid, group_jid, msg1)
     func.send_text(self.api, team_uid, user2_jid, msg2)
     params = {
         'chat_type': 'direct',
     }
     resp = self.api.get_filtered_messages(team_uid, params).json()
     assert 'error' not in resp
     assert len(resp['result']['objects']) == 1
     assert resp['result']['objects'][0]['chat_type'] == 'direct'
     assert resp['result']['objects'][0]['content']['text'] == msg2
예제 #16
0
 def test_delete_reaction_owner(self):
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api,
                                 self.team_uid,
                                 self.group_jid,
                                 text=text)['message_id']
     self.api.add_edit_reaction(self.team_uid, message_id,
                                self.reaction1).json()
     resp = self.api.delete_my_reaction(self.team_uid, message_id,
                                        self.reaction1).json()
     resp2 = self.api.get_my_reactions_on_message(self.team_uid,
                                                  message_id).json()
     assert 'error' not in resp
     assert resp['result'] is None
     assert not resp2['result']
예제 #17
0
 def test_get_messages_old_from(self):
     group_jid = func.add_group(self.api, self.team_uid)['jid']
     msg_list = []
     # добавляем сообщения в цикле
     for i in range(3):
         text = 'msg_{}_{}'.format(tools.generate_random_string(7), i)
         msg_list.append(func.send_text(self.api, self.team_uid, group_jid, text)['message_id'])
     params = {'old_from': msg_list[-1]}
     resp = self.api.get_messages(self.team_uid, group_jid, params).json()
     assert 'error' not in resp
     assert tools.is_items_exist_in_list_of_dict(
         resp['result']['messages'], 'message_id', msg_list[0])
     assert tools.is_items_exist_in_list_of_dict(
         resp['result']['messages'], 'message_id', msg_list[1])
     assert not tools.is_items_exist_in_list_of_dict(
         resp['result']['messages'], 'message_id', msg_list[-1])
예제 #18
0
 def test_add_reaction_member(self):
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # добавляем участника
     member_jid = func.add_contact(self.api, team_uid, self.phone2)['jid']
     # добавляем гуппу
     group_jid = func.add_group(self.api, team_uid)['jid']
     # добавляем участника к группе
     func.add_member_to_group(self.api, team_uid, group_jid, member_jid,
                              'member')
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api, team_uid, group_jid,
                                 text=text)['message_id']
     api2 = auth.login_another_user(self.url, self.phone2, self.code2)
     resp = api2.add_edit_reaction(team_uid, message_id,
                                   self.reaction1).json()
     assert 'error' not in resp
     assert resp['result']['name'] == self.reaction1
     assert resp['result']['sender'] == member_jid
예제 #19
0
 def test_get_all_my_reactions_owner(self):
     owner_jid = func.get_my_jid(self.api, self.team_uid)
     reactions = [self.reaction1, self.reaction2, self.reaction3]
     text = f'Hello, my friend {tools.generate_random_string()}'
     message_id = func.send_text(self.api,
                                 self.team_uid,
                                 self.group_jid,
                                 text=text)['message_id']
     for reaction in reactions:
         self.api.add_edit_reaction(self.team_uid, message_id,
                                    reaction).json()
     resp = self.api.get_my_reactions_on_message(self.team_uid,
                                                 message_id).json()
     assert 'error' not in resp
     for reaction in reactions:
         assert tools.is_items_exist_in_list_of_dict(
             resp['result'], 'name', reaction)
     for item in resp['result']:
         assert item['sender'] == owner_jid
예제 #20
0
 def test_get_all_my_reactions_member(self):
     reactions = [self.reaction1, self.reaction2, self.reaction3]
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # добавляем участника
     member_jid = func.add_contact(self.api, team_uid, self.phone2)['jid']
     # добавляем гуппу
     group_jid = func.add_group(self.api, team_uid)['jid']
     # добавляем участника к группе
     func.add_member_to_group(self.api, team_uid, group_jid, member_jid,
                              'member')
     text = f'Hello, my friend {tools.generate_random_string()}'
     api2 = auth.login_another_user(self.url, self.phone2, self.code2)
     message_id = func.send_text(api2, team_uid, group_jid,
                                 text=text)['message_id']
     for reaction in reactions:
         api2.add_edit_reaction(team_uid, message_id, reaction).json()
     resp = api2.get_my_reactions_on_message(team_uid, message_id).json()
     assert 'error' not in resp
     for reaction in reactions:
         assert tools.is_items_exist_in_list_of_dict(
             resp['result'], 'name', reaction)
     for item in resp['result']:
         assert item['sender'] == member_jid
예제 #21
0
 def test_get_messages_sender(self):
     # создаем команду
     team_uid = func.add_team(self.api)['uid']
     # приглашаем пользователей
     user1_jid = func.get_my_jid(self.api, team_uid)
     user2_jid = func.add_contact(self.api, team_uid, self.phone2)['jid']
     user3_jid = func.add_contact(self.api, team_uid, self.phone3)['jid']
     # добавляем участников к группе
     group_jid = func.add_group(self.api, team_uid)['jid']
     func.add_member_to_group(self.api, team_uid, group_jid, user2_jid, 'member')
     func.add_member_to_group(self.api, team_uid, group_jid, user3_jid, 'admin')
     # добавляем сообщения
     api2 = auth.login_another_user(self.url, self.phone2, self.code2)
     api3 = auth.login_another_user(self.url, self.phone3, self.code3)
     text = 'msg_{}'.format(tools.generate_random_string(7))
     func.send_text(self.api, team_uid, group_jid, text)
     func.send_text(api2, team_uid, group_jid, text)
     func.send_text(api3, team_uid, group_jid, text)
     params = {
         'sender': f'{user1_jid},{user2_jid}',
     }
     resp = self.api.get_filtered_messages(team_uid, params).json()
     assert 'error' not in resp
     assert tools.is_items_exist_in_list_of_dict(
         resp['result']['objects'],
         'from',
         user1_jid,
     )
     assert tools.is_items_exist_in_list_of_dict(
         resp['result']['objects'],
         'from',
         user2_jid,
     )
     assert not tools.is_items_exist_in_list_of_dict(
         resp['result']['objects'],
         'from',
         user3_jid,
     )