tests: Avoid lambdas in import test.

This commit is contained in:
Steve Howell 2021-12-07 16:25:26 +00:00 committed by Tim Abbott
parent 54a6c82282
commit 5892748c7b
1 changed files with 33 additions and 23 deletions

View File

@ -800,19 +800,20 @@ class ImportExportTest(ZulipTestCase):
assert orig_realm_result assert orig_realm_result
self.assertEqual(orig_realm_result, imported_realm_result) self.assertEqual(orig_realm_result, imported_realm_result)
# test users def get_admin_bot_emails(r: Realm) -> Set[str]:
assert_realm_values( return {user.email for user in r.get_admin_users_and_bots()}
lambda r: {user.email for user in r.get_admin_users_and_bots()},
)
assert_realm_values( assert_realm_values(get_admin_bot_emails)
lambda r: {user.email for user in r.get_active_users()},
)
# test stream def get_active_emails(r: Realm) -> Set[str]:
assert_realm_values( return {user.email for user in r.get_active_users()}
lambda r: {stream.name for stream in get_active_streams(r)},
) assert_realm_values(get_active_emails)
def get_active_stream_names(r: Realm) -> Set[str]:
return {stream.name for stream in get_active_streams(r)}
assert_realm_values(get_active_stream_names)
# test recipients # test recipients
def get_recipient_stream(r: Realm) -> Recipient: def get_recipient_stream(r: Realm) -> Recipient:
@ -821,8 +822,15 @@ class ImportExportTest(ZulipTestCase):
def get_recipient_user(r: Realm) -> Recipient: def get_recipient_user(r: Realm) -> Recipient:
return UserProfile.objects.get(full_name="Iago", realm=r).recipient return UserProfile.objects.get(full_name="Iago", realm=r).recipient
assert_realm_values(lambda r: get_recipient_stream(r).type) def get_stream_recipient_type(r: Realm) -> int:
assert_realm_values(lambda r: get_recipient_user(r).type) return get_recipient_stream(r).type
assert_realm_values(get_stream_recipient_type)
def get_user_recipient_type(r: Realm) -> int:
return get_recipient_user(r).type
assert_realm_values(get_user_recipient_type)
# test subscription # test subscription
def get_subscribers(recipient: Recipient) -> Set[str]: def get_subscribers(recipient: Recipient) -> Set[str]:
@ -830,13 +838,15 @@ class ImportExportTest(ZulipTestCase):
users = {sub.user_profile.email for sub in subscriptions} users = {sub.user_profile.email for sub in subscriptions}
return users return users
assert_realm_values( def get_stream_subscribers(r: Realm) -> Set[str]:
lambda r: get_subscribers(get_recipient_stream(r)), return get_subscribers(get_recipient_stream(r))
)
assert_realm_values( assert_realm_values(get_stream_subscribers)
lambda r: get_subscribers(get_recipient_user(r)),
) def get_user_subscribers(r: Realm) -> Set[str]:
return get_subscribers(get_recipient_user(r))
assert_realm_values(get_user_subscribers)
# test custom profile fields # test custom profile fields
def get_custom_profile_field_names(r: Realm) -> Set[str]: def get_custom_profile_field_names(r: Realm) -> Set[str]:
@ -987,10 +997,10 @@ class ImportExportTest(ZulipTestCase):
assert_realm_values(get_muted_users) assert_realm_values(get_muted_users)
# test usergroups def get_user_group_names(r: Realm) -> Set[str]:
assert_realm_values( return {group.name for group in UserGroup.objects.filter(realm=r)}
lambda r: {group.name for group in UserGroup.objects.filter(realm=r)},
) assert_realm_values(get_user_group_names)
def get_user_membership(r: Realm) -> Set[str]: def get_user_membership(r: Realm) -> Set[str]:
usergroup = UserGroup.objects.get(realm=r, name="hamletcharacters") usergroup = UserGroup.objects.get(realm=r, name="hamletcharacters")