mirror of https://github.com/zulip/zulip.git
test-backend: Raise zerver/views/invite.py test coverage to 100%.
This commit is contained in:
parent
cebc67f9b0
commit
f3cd3e8b8d
|
@ -100,7 +100,6 @@ not_yet_fully_covered = {
|
|||
'zerver/views/messages.py',
|
||||
'zerver/views/report.py',
|
||||
'zerver/views/zephyr.py',
|
||||
'zerver/views/invite.py',
|
||||
'zerver/views/home.py',
|
||||
'zerver/views/registration.py',
|
||||
'zerver/views/events_register.py',
|
||||
|
|
|
@ -25,7 +25,8 @@ from zerver.management.commands.deliver_email import send_email_job
|
|||
|
||||
from zerver.lib.actions import (
|
||||
set_default_streams,
|
||||
do_change_is_admin
|
||||
do_change_is_admin,
|
||||
get_stream
|
||||
)
|
||||
|
||||
from zerver.lib.initial_password import initial_password
|
||||
|
@ -378,6 +379,18 @@ class InviteUserTest(ZulipTestCase):
|
|||
self.assert_json_success(result)
|
||||
self.check_sent_emails(invitees)
|
||||
|
||||
def test_bulk_invite_users_invalid_emails(self):
|
||||
# type: () -> None
|
||||
self.login('hamlet@zulip.com')
|
||||
invitees = ['alice@zulip.com', 'bobnoatzulip.com']
|
||||
params = {
|
||||
'invitee_emails': ujson.dumps(invitees),
|
||||
}
|
||||
self.assert_json_error(
|
||||
self.client_post('/json/bulk_invite_users', params),
|
||||
'Some emails did not validate, so we didn\'t send any invitations.')
|
||||
self.check_sent_emails([])
|
||||
|
||||
def test_successful_invite_user(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
|
@ -431,6 +444,28 @@ class InviteUserTest(ZulipTestCase):
|
|||
self.assertTrue(find_key_by_email(email2))
|
||||
self.check_sent_emails([email, email2])
|
||||
|
||||
def test_successful_invite_user_with_notifications_stream(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
A call to /json/invite_users with valid parameters unconditionally
|
||||
subscribes the invitee to the notifications stream if it exists and is
|
||||
public.
|
||||
"""
|
||||
realm = get_realm('zulip')
|
||||
notifications_stream = get_stream('Verona', realm)
|
||||
realm.notifications_stream = notifications_stream
|
||||
realm.save()
|
||||
|
||||
self.login('hamlet@zulip.com')
|
||||
invitee = 'alice-test@zulip.com'
|
||||
self.assert_json_success(self.invite(invitee, ['Denmark']))
|
||||
self.assertTrue(find_key_by_email(invitee))
|
||||
self.check_sent_emails([invitee])
|
||||
|
||||
prereg_user = get_prereg_user_by_email(invitee)
|
||||
streams = list(prereg_user.streams.all())
|
||||
self.assertTrue(notifications_stream in streams)
|
||||
|
||||
def test_invite_user_signup_initial_history(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
|
@ -492,6 +527,11 @@ earl-test@zulip.com""", ["Denmark"]))
|
|||
"Some emails did not validate, so we didn't send any invitations.")
|
||||
self.check_sent_emails([])
|
||||
|
||||
self.assert_json_error(
|
||||
self.invite("", ["Denmark"]),
|
||||
"You must specify at least one email address.")
|
||||
self.check_sent_emails([])
|
||||
|
||||
def test_invalid_stream(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
|
@ -617,6 +657,37 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
|||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
self.assertEqual(user.invites_used, 1)
|
||||
|
||||
def test_refer_friend_no_email(self):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
user.invites_granted = 1
|
||||
user.invites_used = 0
|
||||
user.save()
|
||||
|
||||
self.assert_json_error(
|
||||
self.client_post('/json/refer_friend', dict(email='')),
|
||||
"No email address specified")
|
||||
|
||||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
self.assertEqual(user.invites_used, 0)
|
||||
|
||||
def test_refer_friend_no_invites(self):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
user.invites_granted = 1
|
||||
user.invites_used = 1
|
||||
user.save()
|
||||
|
||||
invitee = "alice-test@zulip.com"
|
||||
self.assert_json_error(
|
||||
self.client_post('/json/refer_friend', dict(email=invitee)),
|
||||
"Insufficient invites")
|
||||
|
||||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
self.assertEqual(user.invites_used, 1)
|
||||
|
||||
def test_invitation_reminder_email(self):
|
||||
# type: () -> None
|
||||
from django.core.mail import outbox
|
||||
|
|
Loading…
Reference in New Issue