tests: Add ZulipTestCase.notification_bot().

This commit is contained in:
Steve Howell 2017-05-08 08:42:50 -07:00 committed by Tim Abbott
parent 3a031f6814
commit 3b2a3601c1
5 changed files with 17 additions and 14 deletions

View File

@ -222,6 +222,10 @@ class ZulipTestCase(TestCase):
email = self.example_user_map[name]
return get_user_profile_by_email(email)
def notification_bot(self):
# type: () -> UserProfile
return get_user_profile_by_email('notification-bot@zulip.com')
def login_with_return(self, email, password=None):
# type: (Text, Optional[Text]) -> HttpResponse
if password is None:

View File

@ -63,7 +63,7 @@ class TestRealmAuditLog(ZulipTestCase):
# type: () -> None
now = timezone_now()
admin = self.example_user('iago')
bot = get_user_profile_by_email("notification-bot@zulip.com")
bot = self.notification_bot()
bot_owner = self.example_user('hamlet')
do_change_bot_owner(bot, bot_owner, admin)
self.assertEqual(RealmAuditLog.objects.filter(event_type='bot_owner_changed',

View File

@ -1614,7 +1614,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
self.assert_length(result['realm_bots'], 0)
# additionally the API key for a random bot is not present in the data
api_key = get_user_profile_by_email('notification-bot@zulip.com').api_key
api_key = self.notification_bot().api_key
self.assertNotIn(api_key, str(result))
# Admin users have access to all bots in the realm_bots field

View File

@ -326,6 +326,9 @@ class HomeTest(ZulipTestCase):
cross_bots = page_params['cross_realm_bots']
self.assertEqual(len(cross_bots), 2)
cross_bots.sort(key=lambda d: d['email'])
notification_bot = self.notification_bot()
self.assertEqual(cross_bots, [
dict(
user_id=get_user_profile_by_email('feedback@zulip.com').id,
@ -335,9 +338,9 @@ class HomeTest(ZulipTestCase):
is_bot=True
),
dict(
user_id=get_user_profile_by_email('notification-bot@zulip.com').id,
user_id=notification_bot.id,
is_admin=False,
email='notification-bot@zulip.com',
email=notification_bot.email,
full_name='Notification Bot',
is_bot=True
),

View File

@ -1336,8 +1336,8 @@ class SubscriptionAPITest(ZulipTestCase):
msg = self.get_second_to_last_message()
self.assertEqual(msg.recipient.type, Recipient.PERSONAL)
self.assertEqual(msg.sender_id,
get_user_profile_by_email('notification-bot@zulip.com').id)
self.assertEqual(msg.sender_id, self.notification_bot().id)
expected_msg = "Hi there! %s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0])
self.assertEqual(msg.content, expected_msg)
@ -1372,8 +1372,7 @@ class SubscriptionAPITest(ZulipTestCase):
msg = self.get_second_to_last_message()
self.assertEqual(msg.recipient.type, Recipient.STREAM)
self.assertEqual(msg.sender_id,
get_user_profile_by_email('notification-bot@zulip.com').id)
self.assertEqual(msg.sender_id, self.notification_bot().id)
expected_msg = "%s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0])
self.assertEqual(msg.content, expected_msg)
@ -1410,8 +1409,7 @@ class SubscriptionAPITest(ZulipTestCase):
msg = self.get_second_to_last_message()
self.assertEqual(msg.recipient.type, Recipient.STREAM)
self.assertEqual(msg.sender_id,
get_user_profile_by_email('notification-bot@zulip.com').id)
self.assertEqual(msg.sender_id, self.notification_bot().id)
stream_id = Stream.objects.latest('id').id
expected_rendered_msg = '<p>%s just created a new stream <a class="stream" data-stream-id="%d" href="/#narrow/stream/%s">#%s</a>.</p>' % (
user.full_name, stream_id, invite_streams[0], invite_streams[0])
@ -1442,8 +1440,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.assert_json_success(result)
msg = self.get_second_to_last_message()
self.assertEqual(msg.sender_id,
get_user_profile_by_email('notification-bot@zulip.com').id)
self.assertEqual(msg.sender_id, self.notification_bot().id)
expected_msg = "%s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0])
self.assertEqual(msg.content, expected_msg)
@ -1535,8 +1532,7 @@ class SubscriptionAPITest(ZulipTestCase):
# verify that the user was sent a message informing them about the subscription
msg = self.get_second_to_last_message()
self.assertEqual(msg.recipient.type, msg.recipient.PERSONAL)
self.assertEqual(msg.sender_id,
get_user_profile_by_email("notification-bot@zulip.com").id)
self.assertEqual(msg.sender_id, self.notification_bot().id)
expected_msg = ("Hi there! We thought you'd like to know that %s just "
"subscribed you to the %sstream #**%s**."
% (self.user_profile.full_name,