Slack importer: Add test for Slack channel mention to Zulip stream mention.

This commit is contained in:
rht 2018-04-06 23:27:48 +01:00 committed by Tim Abbott
parent 630adb406b
commit 7a8655cc50
2 changed files with 18 additions and 13 deletions

View File

@ -277,7 +277,8 @@ class SlackImporter(ZulipTestCase):
zerver_recipient = channel_to_zerver_stream_output[4]
added_recipient = channel_to_zerver_stream_output[5]
test_added_channels = {'feedback': 3, 'general': 1, 'general1': 2, 'random': 0}
test_added_channels = {'feedback': ("C061A0HJG", 3), 'general': ("C061A0YJG", 1),
'general1': ("C061A0YJP", 2), 'random': ("C061A0WJG", 0)}
test_added_recipient = {'feedback': 3, 'general': 1, 'general1': 2, 'random': 0}
# zerver defaultstream already tested in helper functions
@ -311,7 +312,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_stream[0]['invite_only'], False)
self.assertEqual(zerver_stream[0]['realm'], realm_id)
self.assertEqual(zerver_stream[2]['id'],
test_added_channels[zerver_stream[2]['name']])
test_added_channels[zerver_stream[2]['name']][1])
@mock.patch("zerver.lib.slack_data_to_zulip_data.build_zerver_realm", return_value=[{}])
@mock.patch("zerver.lib.slack_data_to_zulip_data.users_to_zerver_userprofile",
@ -407,9 +408,11 @@ class SlackImporter(ZulipTestCase):
zerver_usermessage = [] # type: List[Dict[str, Any]]
zerver_subscription = [] # type: List[Dict[str, Any]]
added_channels = {'random': ('c5', 1), 'general': ('c6', 2)} # type: Dict[str, Tuple[str, int]]
zerver_message, zerver_usermessage, attachment, uploads, \
reaction = channel_message_to_zerver_message(1, user_data, added_users, added_recipient,
all_messages, zerver_subscription, [], 'domain')
all_messages, zerver_subscription, [],
added_channels, 'domain')
# functioning already tested in helper function
self.assertEqual(zerver_usermessage, [])
# subtype: channel_join is filtered
@ -449,7 +452,7 @@ class SlackImporter(ZulipTestCase):
@mock.patch("zerver.lib.slack_data_to_zulip_data.get_all_messages")
def test_convert_slack_workspace_messages(self, mock_get_all_messages: mock.Mock,
mock_message: mock.Mock) -> None:
added_channels = {'random': 1, 'general': 2}
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]

View File

@ -43,7 +43,8 @@ class SlackMessageConversion(ZulipTestCase):
self.assertEqual(len(set(test.keys()) - valid_keys), 0)
slack_user_map = {} # type: Dict[str, int]
users = [{}] # type: List[Dict[str, Any]]
converted = convert_to_zulip_markdown(test['input'], users, slack_user_map)
channel_map = {} # type: Dict[str, Tuple[str, int]]
converted = convert_to_zulip_markdown(test['input'], users, channel_map, slack_user_map)
converted_text = converted[0]
print("Running Slack Message Conversion test: %s" % (name,))
self.assertEqual(converted_text, test['conversion_output'])
@ -65,25 +66,26 @@ class SlackMessageConversion(ZulipTestCase):
{"id": "U09TYF5Sk",
"name": "Jane",
"deleted": True}] # Deleted users don't have 'real_name' key in Slack
message = 'Hi <@U08RGD1RD|john>: How are you?'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, users, slack_user_map)
channel_map = {'general': ('C5Z73A7RA', 137)}
message = 'Hi <@U08RGD1RD|john>: How are you? <#C5Z73A7RA|general>'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, users, channel_map, slack_user_map)
full_name = get_user_full_name(users[1])
self.assertEqual(full_name, 'John Doe')
self.assertEqual(get_user_full_name(users[2]), 'Jane')
self.assertEqual(text, 'Hi @**%s**: How are you?' % (full_name))
self.assertEqual(text, 'Hi @**%s**: How are you? #**general**' % (full_name))
self.assertEqual(mentioned_users, [540])
# multiple mentioning
message = 'Hi <@U08RGD1RD|john>: How are you?<@U0CBK5KAT> asked.'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, users, slack_user_map)
text, mentioned_users, has_link = convert_to_zulip_markdown(message, users, channel_map, slack_user_map)
self.assertEqual(text, 'Hi @**%s**: How are you?@**%s** asked.' %
('John Doe', 'aaron.anzalone'))
self.assertEqual(mentioned_users, [540, 554])
# Check wrong mentioning
message = 'Hi <@U08RGD1RD|jon>: How are you?'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, users, slack_user_map)
text, mentioned_users, has_link = convert_to_zulip_markdown(message, users, channel_map, slack_user_map)
self.assertEqual(text, message)
self.assertEqual(mentioned_users, [])
@ -91,15 +93,15 @@ class SlackMessageConversion(ZulipTestCase):
slack_user_map = {} # type: Dict[str, int]
message = '<http://journals.plos.org/plosone/article>'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, [], slack_user_map)
text, mentioned_users, has_link = convert_to_zulip_markdown(message, [], {}, slack_user_map)
self.assertEqual(text, 'http://journals.plos.org/plosone/article')
self.assertEqual(has_link, True)
message = '<mailto:foo@foo.com>'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, [], slack_user_map)
text, mentioned_users, has_link = convert_to_zulip_markdown(message, [], {}, slack_user_map)
self.assertEqual(text, 'mailto:foo@foo.com')
self.assertEqual(has_link, True)
message = 'random message'
text, mentioned_users, has_link = convert_to_zulip_markdown(message, [], slack_user_map)
text, mentioned_users, has_link = convert_to_zulip_markdown(message, [], {}, slack_user_map)
self.assertEqual(has_link, False)