def test_convert_slack_workspace_messages(self, mock_get_all_messages: mock.Mock, mock_message: mock.Mock) -> None: os.makedirs('var/test-slack-import', exist_ok=True) added_channels = { 'random': ('c5', 1), 'general': ('c6', 2) } # type: Dict[str, Tuple[str, int]] time = float(timezone_now().timestamp()) zerver_message = [{'id': 1, 'ts': time}, {'id': 5, 'ts': time}] realm = {'zerver_subscription': []} # type: Dict[str, Any] user_list = [] # type: List[Dict[str, Any]] reactions = [{"name": "grinning", "users": ["U061A5N1G"], "count": 1}] attachments = uploads = [] # type: List[Dict[str, Any]] id_list = (2, 4, 0, 1) zerver_usermessage = [{'id': 3}, {'id': 5}, {'id': 6}, {'id': 9}] mock_get_all_messages.side_effect = [zerver_message] mock_message.side_effect = [[ zerver_message[:1], zerver_usermessage[:2], attachments, uploads, reactions[:1], id_list ], [ zerver_message[1:2], zerver_usermessage[2:5], attachments, uploads, reactions[1:1], id_list ]] test_reactions, uploads, zerver_attachment = convert_slack_workspace_messages( './random_path', user_list, 2, {}, {}, added_channels, realm, [], 'domain', 'var/test-slack-import', chunk_size=1) messages_file_1 = os.path.join('var', 'test-slack-import', 'messages-000001.json') self.assertTrue(os.path.exists(messages_file_1)) messages_file_2 = os.path.join('var', 'test-slack-import', 'messages-000002.json') self.assertTrue(os.path.exists(messages_file_2)) with open(messages_file_1) as f: message_json = ujson.load(f) self.assertEqual(message_json['zerver_message'], zerver_message[:1]) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage[:2]) with open(messages_file_2) as f: message_json = ujson.load(f) self.assertEqual(message_json['zerver_message'], zerver_message[1:2]) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage[2:5]) self.assertEqual(test_reactions, reactions)
def test_convert_slack_workspace_messages(self, mock_get_all_messages: mock.Mock, mock_message: mock.Mock) -> None: added_channels = {'random': ('c5', 1), 'general': ('c6', 2)} # type: Dict[str, Tuple[str, int]] zerver_message = [{'id': 1}, {'id': 5}] realm = {'zerver_subscription': []} # type: Dict[str, Any] user_list = [] # type: List[Dict[str, Any]] zerver_usermessage = [{'id': 3}, {'id': 5}, {'id': 6}, {'id': 9}] mock_message.side_effect = [[zerver_message, zerver_usermessage, [], [], []]] message_json, uploads, zerver_attachment = convert_slack_workspace_messages( './random_path', user_list, 2, {}, {}, added_channels, realm, [], 'domain') self.assertEqual(message_json['zerver_message'], zerver_message) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage)
def test_convert_slack_workspace_messages(self, mock_get_all_messages: mock.Mock, mock_message: mock.Mock) -> None: added_channels = {'random': ('c5', 1), 'general': ('c6', 2)} # type: Dict[str, Tuple[str, int]] zerver_message = [{'id': 1}, {'id': 5}] realm = {'zerver_subscription': []} # type: Dict[str, Any] user_list = [] # type: List[Dict[str, Any]] zerver_usermessage = [{'id': 3}, {'id': 5}, {'id': 6}, {'id': 9}] mock_message.side_effect = [[zerver_message, zerver_usermessage, [], [], []]] message_json, uploads, zerver_attachment = convert_slack_workspace_messages( './random_path', user_list, 2, {}, {}, added_channels, realm, [], 'domain') self.assertEqual(message_json['zerver_message'], zerver_message) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage)
def test_convert_slack_workspace_messages(self, mock_get_total_messages_and_usermessages: mock.Mock, mock_get_all_messages: mock.Mock, mock_allocate_ids: mock.Mock, mock_message: mock.Mock) -> None: added_channels = {'random': 1, 'general': 2} zerver_message = [{'id': 1}, {'id': 5}] realm = {'zerver_subscription': []} # type: Dict[str, Any] user_list = [] # type: List[Dict[str, Any]] zerver_usermessage = [{'id': 3}, {'id': 5}, {'id': 6}, {'id': 9}] mock_message.side_effect = [[zerver_message, zerver_usermessage]] message_json = convert_slack_workspace_messages('./random_path', user_list, 2, {}, {}, added_channels, realm) self.assertEqual(message_json['zerver_message'], zerver_message) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage)
def test_convert_slack_workspace_messages( self, mock_get_total_messages_and_usermessages: mock.Mock, mock_get_model_id: mock.Mock, mock_message: mock.Mock) -> None: added_channels = {'random': 1, 'general': 2} zerver_message1 = [{'id': 1}] zerver_message2 = [{'id': 5}] realm = {'zerver_subscription': []} # type: Dict[str, Any] zerver_usermessage1 = [{'id': 3}, {'id': 5}] zerver_usermessage2 = [{'id': 6}, {'id': 9}] mock_message.side_effect = [[zerver_message1, zerver_usermessage1], [zerver_message2, zerver_usermessage2]] message_json = convert_slack_workspace_messages( './random_path', 2, {}, {}, added_channels, realm) self.assertEqual(message_json['zerver_message'], zerver_message1 + zerver_message2) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage1 + zerver_usermessage2)
def test_convert_slack_workspace_messages(self, mock_get_all_messages: mock.Mock, mock_message: mock.Mock) -> None: os.makedirs('var/test-slack-import', exist_ok=True) added_channels = {'random': ('c5', 1), 'general': ('c6', 2)} # type: Dict[str, Tuple[str, int]] time = float(timezone_now().timestamp()) zerver_message = [{'id': 1, 'ts': time}, {'id': 5, 'ts': time}] realm = {'zerver_subscription': []} # type: Dict[str, Any] user_list = [] # type: List[Dict[str, Any]] reactions = [{"name": "grinning", "users": ["U061A5N1G"], "count": 1}] attachments = uploads = [] # type: List[Dict[str, Any]] id_list = (2, 4, 0, 1) zerver_usermessage = [{'id': 3}, {'id': 5}, {'id': 6}, {'id': 9}] mock_get_all_messages.side_effect = [zerver_message] mock_message.side_effect = [[zerver_message[:1], zerver_usermessage[:2], attachments, uploads, reactions[:1], id_list], [zerver_message[1:2], zerver_usermessage[2:5], attachments, uploads, reactions[1:1], id_list]] test_reactions, uploads, zerver_attachment = convert_slack_workspace_messages( './random_path', user_list, 2, {}, {}, added_channels, realm, [], 'domain', 'var/test-slack-import', chunk_size=1) messages_file_1 = os.path.join('var', 'test-slack-import', 'messages-000001.json') self.assertTrue(os.path.exists(messages_file_1)) messages_file_2 = os.path.join('var', 'test-slack-import', 'messages-000002.json') self.assertTrue(os.path.exists(messages_file_2)) with open(messages_file_1) as f: message_json = ujson.load(f) self.assertEqual(message_json['zerver_message'], zerver_message[:1]) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage[:2]) with open(messages_file_2) as f: message_json = ujson.load(f) self.assertEqual(message_json['zerver_message'], zerver_message[1:2]) self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage[2:5]) self.assertEqual(test_reactions, reactions)