slack importer: Cleanup build_avatar.

This commit is contained in:
Rhea Parekh 2018-03-07 18:23:35 +05:30 committed by Tim Abbott
parent 5efe05d5b6
commit f947194e4c
2 changed files with 8 additions and 9 deletions

View File

@ -156,7 +156,7 @@ def users_to_zerver_userprofile(slack_data_dir: str, users: List[ZerverFieldsT],
# ref: https://chat.zulip.org/help/change-your-avatar
avatar_url = build_avatar_url(slack_user_id, user['team_id'],
user['profile']['avatar_hash'])
avatar_list = build_avatar(user_id, realm_id, email, avatar_url, timestamp, avatar_list)
build_avatar(user_id, realm_id, email, avatar_url, timestamp, avatar_list)
# check if user is the admin
realm_admin = get_admin(user)
@ -244,7 +244,7 @@ def build_avatar_url(slack_user_id: str, team_id: str, avatar_hash: str) -> str:
return avatar_url
def build_avatar(zulip_user_id: int, realm_id: int, email: str, avatar_url: str,
timestamp: Any, avatar_list: List[ZerverFieldsT]) -> List[ZerverFieldsT]:
timestamp: Any, avatar_list: List[ZerverFieldsT]) -> None:
avatar = dict(
path=avatar_url, # Save slack's url here, which is used later while processing
realm_id=realm_id,
@ -255,7 +255,6 @@ def build_avatar(zulip_user_id: int, realm_id: int, email: str, avatar_url: str,
s3_path="",
size="")
avatar_list.append(avatar)
return avatar_list
def get_admin(user: ZerverFieldsT) -> bool:
admin = user.get('is_admin', False)

View File

@ -108,12 +108,12 @@ class SlackImporter(ZulipTestCase):
avatar_list = [] # type: List[Dict[str, Any]]
timestamp = int(timezone_now().timestamp())
test_avatar_list = build_avatar(1, 1, 'email', avatar_url, timestamp, avatar_list)
self.assertEqual(test_avatar_list[0]['path'], avatar_url)
self.assertEqual(test_avatar_list[0]['s3_path'], '')
self.assertEqual(test_avatar_list[0]['user_profile_id'], 1)
build_avatar(1, 1, 'email', avatar_url, timestamp, avatar_list)
self.assertEqual(avatar_list[0]['path'], avatar_url)
self.assertEqual(avatar_list[0]['s3_path'], '')
self.assertEqual(avatar_list[0]['user_profile_id'], 1)
avatar_list = process_avatars(test_avatar_list, './avatar_dir', 3)
avatar_list = process_avatars(avatar_list, './avatar_dir', 3)
avatar_hash = user_avatar_path_from_ids(1, 3)
image_path = ('%s/%s.png' % ('./avatar_dir', avatar_hash))
original_image_path = ('%s/%s.original' % ('./avatar_dir', avatar_hash))
@ -489,7 +489,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(message_json['zerver_usermessage'], zerver_usermessage)
@mock.patch("zerver.lib.slack_data_to_zulip_data.build_avatar_url")
@mock.patch("zerver.lib.slack_data_to_zulip_data.build_avatar", return_value = [])
@mock.patch("zerver.lib.slack_data_to_zulip_data.build_avatar")
@mock.patch("zerver.lib.slack_data_to_zulip_data.get_user_data")
def test_slack_import_to_existing_database(self, mock_get_user_data: mock.Mock,
mock_build_avatar_url: mock.Mock,