mirror of https://github.com/zulip/zulip.git
tests: Remove get_user_profile_by_email from most tests.
This commit is contained in:
parent
e809faa37d
commit
e53d1c3885
|
@ -34,6 +34,7 @@ from zerver.lib.test_helpers import (
|
|||
|
||||
from zerver.models import (
|
||||
get_stream,
|
||||
get_user,
|
||||
get_user_profile_by_email,
|
||||
get_realm_by_email_domain,
|
||||
Client,
|
||||
|
@ -215,6 +216,7 @@ class ZulipTestCase(TestCase):
|
|||
prospero='prospero@zulip.com',
|
||||
othello='othello@zulip.com',
|
||||
AARON='AARON@zulip.com',
|
||||
aaron='aaron@zulip.com',
|
||||
ZOE='ZOE@zulip.com',
|
||||
)
|
||||
|
||||
|
@ -224,6 +226,23 @@ class ZulipTestCase(TestCase):
|
|||
espuser="espuser@mit.edu",
|
||||
)
|
||||
|
||||
# Non-registered test users
|
||||
nonreg_user_map = dict(
|
||||
test='test@zulip.com',
|
||||
test1='test1@zulip.com',
|
||||
alice='alice@zulip.com',
|
||||
newuser='newuser@zulip.com',
|
||||
bob='bob@zulip.com',
|
||||
cordelia='cordelia@zulip.com',
|
||||
newguy='newguy@zulip.com',
|
||||
me='me@zulip.com',
|
||||
)
|
||||
|
||||
def nonreg_user(self, name):
|
||||
# type: (str) -> UserProfile
|
||||
email = self.nonreg_user_map[name]
|
||||
return get_user(email, get_realm_by_email_domain(email))
|
||||
|
||||
def example_user(self, name):
|
||||
# type: (str) -> UserProfile
|
||||
email = self.example_user_map[name]
|
||||
|
@ -234,6 +253,10 @@ class ZulipTestCase(TestCase):
|
|||
email = self.mit_user_map[name]
|
||||
return get_user_profile_by_email(email)
|
||||
|
||||
def nonreg_email(self, name):
|
||||
# type: (str) -> str
|
||||
return self.nonreg_user_map[name]
|
||||
|
||||
def example_email(self, name):
|
||||
# type: (str) -> str
|
||||
return self.example_user_map[name]
|
||||
|
|
|
@ -33,6 +33,7 @@ from zerver.lib.actions import (
|
|||
from zerver.models import (
|
||||
get_recipient,
|
||||
get_stream,
|
||||
get_user,
|
||||
get_user_profile_by_email,
|
||||
Client,
|
||||
Message,
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.test import TestCase
|
|||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from zerver.models import (
|
||||
get_client, get_realm, get_recipient, get_stream, get_user_profile_by_email,
|
||||
get_client, get_realm, get_recipient, get_stream, get_user,
|
||||
Message, RealmDomain, Recipient, UserMessage, UserPresence, UserProfile,
|
||||
Realm,
|
||||
)
|
||||
|
@ -340,6 +340,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
self.assertEqual(events[0]["message"]["display_recipient"], "Denmark")
|
||||
|
||||
class EventsRegisterTest(ZulipTestCase):
|
||||
|
||||
def setUp(self):
|
||||
# type: () -> None
|
||||
super(EventsRegisterTest, self).setUp()
|
||||
|
@ -1506,8 +1507,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
|||
|
||||
def test_max_message_id_with_no_history(self):
|
||||
# type: () -> None
|
||||
email = 'aaron@zulip.com'
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('aaron')
|
||||
# Delete all historical messages for this user
|
||||
UserMessage.objects.filter(user_profile=user_profile).delete()
|
||||
result = fetch_initial_state_data(user_profile, None, "")
|
||||
|
|
|
@ -31,7 +31,7 @@ from zerver.lib.test_classes import (
|
|||
from zerver.models import (
|
||||
MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH,
|
||||
Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment, RealmDomain,
|
||||
get_realm, get_stream, get_user_profile_by_email,
|
||||
get_realm, get_realm_by_email_domain, get_stream, get_system_bot, get_user,
|
||||
Reaction, sew_messages_and_reactions, flush_per_request_caches
|
||||
)
|
||||
|
||||
|
@ -166,7 +166,7 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
def create_user(self, email):
|
||||
# type: (Text) -> UserProfile
|
||||
self.register(email, 'test')
|
||||
return get_user_profile_by_email(email)
|
||||
return get_user(email, get_realm_by_email_domain(email))
|
||||
|
||||
@override_settings(CROSS_REALM_BOT_EMAILS=['feedback@zulip.com',
|
||||
'support@3.example.com'])
|
||||
|
@ -204,7 +204,7 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
user1a = self.create_user(user1a_email)
|
||||
user2 = self.create_user(user2_email)
|
||||
self.create_user(user3_email)
|
||||
feedback_bot = get_user_profile_by_email(feedback_email)
|
||||
feedback_bot = get_system_bot(feedback_email)
|
||||
support_bot = self.create_user(support_email)
|
||||
|
||||
# Users can PM themselves
|
||||
|
@ -298,10 +298,11 @@ class PersonalMessagesTest(ZulipTestCase):
|
|||
Newly created users are auto-subbed to the ability to receive
|
||||
personals.
|
||||
"""
|
||||
self.register("test@zulip.com", "test")
|
||||
user_profile = get_user_profile_by_email('test@zulip.com')
|
||||
test_email = self.nonreg_email('test')
|
||||
self.register(test_email, "test")
|
||||
user_profile = self.nonreg_user('test')
|
||||
old_messages_count = message_stream_count(user_profile)
|
||||
self.send_message("test@zulip.com", "test@zulip.com", Recipient.PERSONAL)
|
||||
self.send_message(test_email, test_email, Recipient.PERSONAL)
|
||||
new_messages_count = message_stream_count(user_profile)
|
||||
self.assertEqual(new_messages_count, old_messages_count + 1)
|
||||
|
||||
|
@ -327,13 +328,14 @@ class PersonalMessagesTest(ZulipTestCase):
|
|||
If you send a personal to yourself, only you see it.
|
||||
"""
|
||||
old_user_profiles = list(UserProfile.objects.all())
|
||||
self.register("test1@zulip.com", "test1")
|
||||
test_email = self.nonreg_email('test1')
|
||||
self.register(test_email, "test1")
|
||||
|
||||
old_messages = []
|
||||
for user_profile in old_user_profiles:
|
||||
old_messages.append(message_stream_count(user_profile))
|
||||
|
||||
self.send_message("test1@zulip.com", "test1@zulip.com", Recipient.PERSONAL)
|
||||
self.send_message(test_email, test_email, Recipient.PERSONAL)
|
||||
|
||||
new_messages = []
|
||||
for user_profile in old_user_profiles:
|
||||
|
@ -341,7 +343,7 @@ class PersonalMessagesTest(ZulipTestCase):
|
|||
|
||||
self.assertEqual(old_messages, new_messages)
|
||||
|
||||
user_profile = get_user_profile_by_email("test1@zulip.com")
|
||||
user_profile = self.nonreg_user('test1')
|
||||
recipient = Recipient.objects.get(type_id=user_profile.id, type=Recipient.PERSONAL)
|
||||
self.assertEqual(most_recent_message(user_profile).recipient, recipient)
|
||||
|
||||
|
@ -351,8 +353,9 @@ class PersonalMessagesTest(ZulipTestCase):
|
|||
Send a private message from `sender_email` to `receiver_email` and check
|
||||
that only those two parties actually received the message.
|
||||
"""
|
||||
sender = get_user_profile_by_email(sender_email)
|
||||
receiver = get_user_profile_by_email(receiver_email)
|
||||
realm = get_realm('zulip') # Assume realm is always 'zulip'
|
||||
sender = get_user(sender_email, realm)
|
||||
receiver = get_user(receiver_email, realm)
|
||||
|
||||
sender_messages = message_stream_count(sender)
|
||||
receiver_messages = message_stream_count(receiver)
|
||||
|
@ -981,13 +984,12 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
|
||||
def test_send_message_as_superuser_to_domain_that_dont_exist(self):
|
||||
# type: () -> None
|
||||
email = "emailgateway@zulip.com"
|
||||
user = get_user_profile_by_email(email)
|
||||
user = get_system_bot(settings.EMAIL_GATEWAY_BOT)
|
||||
password = "test_password"
|
||||
user.set_password(password)
|
||||
user.is_api_super_user = True
|
||||
user.save()
|
||||
self.login(email, password)
|
||||
self.login(user.email, password)
|
||||
result = self.client_post("/json/messages", {"type": "stream",
|
||||
"to": "Verona",
|
||||
"client": "test suite",
|
||||
|
@ -1047,7 +1049,7 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
|
||||
def test_send_message_irc_mirror(self):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
self.login(self.example_email('hamlet'))
|
||||
bot_info = {
|
||||
'full_name': 'IRC bot',
|
||||
'short_name': 'irc',
|
||||
|
@ -1056,10 +1058,10 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
self.assert_json_success(result)
|
||||
|
||||
email = "irc-bot@zulip.testserver"
|
||||
user = get_user_profile_by_email(email)
|
||||
user = get_user(email, get_realm('zulip'))
|
||||
user.is_api_super_user = True
|
||||
user.save()
|
||||
user = get_user_profile_by_email(email)
|
||||
user = get_user(email, get_realm('zulip'))
|
||||
self.subscribe_to_stream(email, "#IRCland", realm=user.realm)
|
||||
result = self.client_post("/api/v1/messages",
|
||||
{"type": "stream",
|
||||
|
@ -1549,6 +1551,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
user = self.mit_user('starnine')
|
||||
sender = self.mit_user('sipbtest')
|
||||
new_user_email = 'bob_the_new_user@mit.edu'
|
||||
new_user_realm = get_realm("zephyr")
|
||||
|
||||
recipients = [user.email, new_user_email]
|
||||
|
||||
|
@ -1570,7 +1573,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
self.assertIn(user.email, realm_emails)
|
||||
self.assertIn(new_user_email, realm_emails)
|
||||
|
||||
bob = get_user_profile_by_email(new_user_email)
|
||||
bob = get_user(new_user_email, new_user_realm)
|
||||
self.assertTrue(bob.is_mirror_dummy)
|
||||
|
||||
@mock.patch('DNS.dnslookup', return_value=[['sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh']])
|
||||
|
@ -1606,7 +1609,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
sender = self.example_user('hamlet')
|
||||
user = sender
|
||||
|
||||
recipients = ['alice@zulip.com', 'bob@irc.zulip.com', 'cordelia@zulip.com']
|
||||
recipients = [self.nonreg_email('alice'), 'bob@irc.zulip.com', self.nonreg_email('cordelia')]
|
||||
|
||||
# Now make the request.
|
||||
request = self.Request()
|
||||
|
@ -1623,10 +1626,10 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
|
||||
realm_users = UserProfile.objects.filter(realm=sender.realm)
|
||||
realm_emails = {user.email for user in realm_users}
|
||||
self.assertIn('alice@zulip.com', realm_emails)
|
||||
self.assertIn(self.nonreg_email('alice'), realm_emails)
|
||||
self.assertIn('bob@irc.zulip.com', realm_emails)
|
||||
|
||||
bob = get_user_profile_by_email('bob@irc.zulip.com')
|
||||
bob = get_user('bob@irc.zulip.com', sender.realm)
|
||||
self.assertTrue(bob.is_mirror_dummy)
|
||||
|
||||
def test_jabber_mirror(self):
|
||||
|
@ -1636,7 +1639,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
sender = self.example_user('hamlet')
|
||||
user = sender
|
||||
|
||||
recipients = ['alice@zulip.com', 'bob@zulip.com', 'cordelia@zulip.com']
|
||||
recipients = [self.nonreg_email('alice'), self.nonreg_email('bob'), self.nonreg_email('cordelia')]
|
||||
|
||||
# Now make the request.
|
||||
request = self.Request()
|
||||
|
@ -1653,10 +1656,10 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
|
||||
realm_users = UserProfile.objects.filter(realm=sender.realm)
|
||||
realm_emails = {user.email for user in realm_users}
|
||||
self.assertIn('alice@zulip.com', realm_emails)
|
||||
self.assertIn('bob@zulip.com', realm_emails)
|
||||
self.assertIn(self.nonreg_email('alice'), realm_emails)
|
||||
self.assertIn(self.nonreg_email('bob'), realm_emails)
|
||||
|
||||
bob = get_user_profile_by_email('bob@zulip.com')
|
||||
bob = get_user(self.nonreg_email('bob'), sender.realm)
|
||||
self.assertTrue(bob.is_mirror_dummy)
|
||||
|
||||
class StarTests(ZulipTestCase):
|
||||
|
@ -1793,14 +1796,14 @@ class StarTests(ZulipTestCase):
|
|||
"""
|
||||
New messages aren't starred.
|
||||
"""
|
||||
test_email = "hamlet@zulip.com"
|
||||
test_email = self.example_email('hamlet')
|
||||
self.login(test_email)
|
||||
content = "Test message for star"
|
||||
self.send_message(test_email, "Verona", Recipient.STREAM,
|
||||
content=content)
|
||||
|
||||
sent_message = UserMessage.objects.filter(
|
||||
user_profile=get_user_profile_by_email(test_email)
|
||||
user_profile=self.example_user('hamlet')
|
||||
).order_by("id").reverse()[0]
|
||||
self.assertEqual(sent_message.message.content, content)
|
||||
self.assertFalse(sent_message.flags.starred)
|
||||
|
@ -1857,7 +1860,7 @@ class AttachmentTest(ZulipTestCase):
|
|||
class LogDictTest(ZulipTestCase):
|
||||
def test_to_log_dict(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
email = self.example_email('hamlet')
|
||||
stream_name = 'Denmark'
|
||||
topic_name = 'Copenhagen'
|
||||
content = 'find me some good coffee shops'
|
||||
|
@ -1877,7 +1880,7 @@ class LogDictTest(ZulipTestCase):
|
|||
self.assertEqual(dct['sender_realm_str'], 'zulip')
|
||||
self.assertEqual(dct['sender_email'], 'hamlet@zulip.com')
|
||||
self.assertEqual(dct['sender_full_name'], 'King Hamlet')
|
||||
self.assertEqual(dct['sender_id'], get_user_profile_by_email(email).id)
|
||||
self.assertEqual(dct['sender_id'], self.example_user('hamlet').id)
|
||||
self.assertEqual(dct['sender_short_name'], 'hamlet')
|
||||
self.assertEqual(dct['sending_client'], 'test suite')
|
||||
self.assertEqual(dct['subject'], 'Copenhagen')
|
||||
|
|
|
@ -8,13 +8,13 @@ from mock import patch
|
|||
from typing import Any, Dict
|
||||
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import get_user_profile_by_email
|
||||
from zerver.models import get_realm, get_user
|
||||
from zerver.lib.actions import do_set_muted_topics
|
||||
|
||||
class MutedTopicsTests(ZulipTestCase):
|
||||
def test_json_set(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
|
||||
url = '/api/v1/users/me/subscriptions/muted_topics'
|
||||
|
@ -22,7 +22,7 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
result = self.client_post(url, data, **self.api_auth(email))
|
||||
self.assert_json_success(result)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertEqual(ujson.loads(user.muted_topics), [["stream", "topic"]])
|
||||
|
||||
url = '/api/v1/users/me/subscriptions/muted_topics'
|
||||
|
@ -30,12 +30,12 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
result = self.client_post(url, data, **self.api_auth(email))
|
||||
self.assert_json_success(result)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertEqual(ujson.loads(user.muted_topics), [["stream2", "topic2"]])
|
||||
|
||||
def test_add_muted_topic(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
|
||||
url = '/api/v1/users/me/subscriptions/muted_topics'
|
||||
|
@ -43,7 +43,7 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
result = self.client_patch(url, data, **self.api_auth(email))
|
||||
self.assert_json_success(result)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertIn([u'Verona', u'Verona3'], ujson.loads(user.muted_topics))
|
||||
|
||||
def test_remove_muted_topic(self):
|
||||
|
@ -58,7 +58,7 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
result = self.client_patch(url, data, **self.api_auth(email))
|
||||
|
||||
self.assert_json_success(result)
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertNotIn([[u'Verona', u'Verona3']], ujson.loads(user.muted_topics))
|
||||
|
||||
def test_muted_topic_add_invalid(self):
|
||||
|
|
|
@ -12,7 +12,7 @@ from sqlalchemy.sql import compiler # type: ignore
|
|||
|
||||
from zerver.models import (
|
||||
Realm, Recipient, Stream, Subscription, UserProfile, Attachment,
|
||||
get_display_recipient, get_recipient, get_realm, get_stream, get_user_profile_by_email,
|
||||
get_display_recipient, get_recipient, get_realm, get_stream, get_user,
|
||||
Reaction
|
||||
)
|
||||
from zerver.lib.message import (
|
||||
|
@ -481,7 +481,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
A request for old messages with a narrow by pm-with only returns
|
||||
conversations with that user.
|
||||
"""
|
||||
me = 'hamlet@zulip.com'
|
||||
me = self.example_email('hamlet')
|
||||
|
||||
def dr_emails(dr):
|
||||
# type: (Union[Text, List[Dict[str, Any]]]) -> Text
|
||||
|
@ -492,7 +492,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
self.send_message(me,
|
||||
['iago@zulip.com', 'cordelia@zulip.com'],
|
||||
Recipient.HUDDLE)
|
||||
personals = [m for m in get_user_messages(get_user_profile_by_email(me))
|
||||
personals = [m for m in get_user_messages(self.example_user('hamlet'))
|
||||
if m.recipient.type == Recipient.PERSONAL or
|
||||
m.recipient.type == Recipient.HUDDLE]
|
||||
for personal in personals:
|
||||
|
@ -535,7 +535,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
A request for old messages with a narrow by stream only returns
|
||||
messages for that stream.
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
self.login(self.example_email('hamlet'))
|
||||
# We need to subscribe to a stream and then send a message to
|
||||
# it to ensure that we actually have a stream message in this
|
||||
# narrow view.
|
||||
|
|
|
@ -22,7 +22,6 @@ from zerver.models import (
|
|||
receives_online_notifications,
|
||||
get_client,
|
||||
Recipient,
|
||||
get_user_profile_by_email,
|
||||
Stream,
|
||||
)
|
||||
from zerver.lib import push_notifications as apn
|
||||
|
@ -251,7 +250,7 @@ class PushNotificationTest(BouncerTestCase):
|
|||
)
|
||||
|
||||
self.sending_client = get_client('test')
|
||||
self.sender = get_user_profile_by_email('hamlet@zulip.com')
|
||||
self.sender = self.example_user('hamlet')
|
||||
|
||||
def tearDown(self):
|
||||
# type: () -> None
|
||||
|
@ -338,7 +337,7 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||
|
||||
def test_disabled_notifications(self):
|
||||
# type: () -> None
|
||||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||
user_profile = self.example_user('hamlet')
|
||||
user_profile.enable_online_email_notifications = False
|
||||
user_profile.enable_online_push_notifications = False
|
||||
user_profile.enable_offline_email_notifications = False
|
||||
|
@ -348,7 +347,7 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||
|
||||
def test_read_message(self):
|
||||
# type: () -> None
|
||||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||
user_profile = self.example_user('hamlet')
|
||||
message = self.get_message(Recipient.PERSONAL, type_id=1)
|
||||
UserMessage.objects.create(
|
||||
user_profile=user_profile,
|
||||
|
@ -361,7 +360,7 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||
|
||||
def test_send_notifications_to_bouncer(self):
|
||||
# type: () -> None
|
||||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||
user_profile = self.example_user('hamlet')
|
||||
message = self.get_message(Recipient.PERSONAL, type_id=1)
|
||||
UserMessage.objects.create(
|
||||
user_profile=user_profile,
|
||||
|
@ -548,16 +547,15 @@ class TestGetAPNsPayload(PushNotificationTest):
|
|||
class TestGetGCMPayload(PushNotificationTest):
|
||||
def test_get_gcm_payload(self):
|
||||
# type: () -> None
|
||||
email = "hamlet@zulip.com"
|
||||
stream = Stream.objects.filter(name='Verona').get()
|
||||
message = self.get_message(Recipient.STREAM, stream.id)
|
||||
message.content = 'a' * 210
|
||||
message.save()
|
||||
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
payload = apn.get_gcm_payload(user_profile, message)
|
||||
expected = {
|
||||
"user": email,
|
||||
"user": user_profile.email,
|
||||
"event": "message",
|
||||
"alert": "New mention from King Hamlet",
|
||||
"zulip_message_id": message.id,
|
||||
|
@ -575,12 +573,11 @@ class TestGetGCMPayload(PushNotificationTest):
|
|||
|
||||
def test_get_gcm_payload_personal(self):
|
||||
# type: () -> None
|
||||
email = "hamlet@zulip.com"
|
||||
message = self.get_message(Recipient.PERSONAL, 1)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
payload = apn.get_gcm_payload(user_profile, message)
|
||||
expected = {
|
||||
"user": email,
|
||||
"user": user_profile.email,
|
||||
"event": "message",
|
||||
"alert": "New private message from King Hamlet",
|
||||
"zulip_message_id": message.id,
|
||||
|
|
|
@ -8,7 +8,7 @@ from six import string_types
|
|||
from zerver.lib.test_helpers import tornado_redirected_to_list, get_display_recipient, \
|
||||
get_test_image_file
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import get_realm, get_user_profile_by_email, Recipient, UserMessage
|
||||
from zerver.models import get_realm, Recipient, UserMessage
|
||||
|
||||
class ReactionEmojiTest(ZulipTestCase):
|
||||
def test_missing_emoji(self):
|
||||
|
@ -216,25 +216,24 @@ class ReactionEventTest(ZulipTestCase):
|
|||
Recipients of the message receive the reaction event
|
||||
and event contains relevant data
|
||||
"""
|
||||
pm_sender = 'hamlet@zulip.com'
|
||||
pm_recipient = 'othello@zulip.com'
|
||||
pm_sender = self.example_user('hamlet')
|
||||
pm_recipient = self.example_user('othello')
|
||||
reaction_sender = pm_recipient
|
||||
|
||||
result = self.client_post("/api/v1/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"to": pm_recipient},
|
||||
**self.api_auth(pm_sender))
|
||||
"to": pm_recipient.email},
|
||||
**self.api_auth(pm_sender.email))
|
||||
self.assert_json_success(result)
|
||||
content = ujson.loads(result.content)
|
||||
pm_id = content['id']
|
||||
|
||||
expected_recipient_emails = set([pm_sender, pm_recipient])
|
||||
expected_recipient_ids = set([get_user_profile_by_email(email).id for email in expected_recipient_emails])
|
||||
expected_recipient_ids = set([pm_sender.id, pm_recipient.id])
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
result = self.client_put('/api/v1/messages/%s/emoji_reactions/smile' % (pm_id,),
|
||||
**self.api_auth(reaction_sender))
|
||||
**self.api_auth(reaction_sender.email))
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(len(events), 1)
|
||||
|
||||
|
@ -242,7 +241,7 @@ class ReactionEventTest(ZulipTestCase):
|
|||
event_user_ids = set(events[0]['users'])
|
||||
|
||||
self.assertEqual(expected_recipient_ids, event_user_ids)
|
||||
self.assertEqual(event['user']['email'], reaction_sender)
|
||||
self.assertEqual(event['user']['email'], reaction_sender.email)
|
||||
self.assertEqual(event['type'], 'reaction')
|
||||
self.assertEqual(event['op'], 'add')
|
||||
self.assertEqual(event['emoji_name'], 'smile')
|
||||
|
@ -254,29 +253,28 @@ class ReactionEventTest(ZulipTestCase):
|
|||
Recipients of the message receive the reaction event
|
||||
and event contains relevant data
|
||||
"""
|
||||
pm_sender = 'hamlet@zulip.com'
|
||||
pm_recipient = 'othello@zulip.com'
|
||||
pm_sender = self.example_user('hamlet')
|
||||
pm_recipient = self.example_user('othello')
|
||||
reaction_sender = pm_recipient
|
||||
|
||||
result = self.client_post("/api/v1/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"to": pm_recipient},
|
||||
**self.api_auth(pm_sender))
|
||||
"to": pm_recipient.email},
|
||||
**self.api_auth(pm_sender.email))
|
||||
self.assert_json_success(result)
|
||||
content = ujson.loads(result.content)
|
||||
pm_id = content['id']
|
||||
|
||||
expected_recipient_emails = set([pm_sender, pm_recipient])
|
||||
expected_recipient_ids = set([get_user_profile_by_email(email).id for email in expected_recipient_emails])
|
||||
expected_recipient_ids = set([pm_sender.id, pm_recipient.id])
|
||||
|
||||
add = self.client_put('/api/v1/messages/%s/emoji_reactions/smile' % (pm_id,),
|
||||
**self.api_auth(reaction_sender))
|
||||
**self.api_auth(reaction_sender.email))
|
||||
self.assert_json_success(add)
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
result = self.client_delete('/api/v1/messages/%s/emoji_reactions/smile' % (pm_id,),
|
||||
**self.api_auth(reaction_sender))
|
||||
**self.api_auth(reaction_sender.email))
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(len(events), 1)
|
||||
|
||||
|
@ -284,7 +282,7 @@ class ReactionEventTest(ZulipTestCase):
|
|||
event_user_ids = set(events[0]['users'])
|
||||
|
||||
self.assertEqual(expected_recipient_ids, event_user_ids)
|
||||
self.assertEqual(event['user']['email'], reaction_sender)
|
||||
self.assertEqual(event['user']['email'], reaction_sender.email)
|
||||
self.assertEqual(event['type'], 'reaction')
|
||||
self.assertEqual(event['op'], 'remove')
|
||||
self.assertEqual(event['emoji_name'], 'smile')
|
||||
|
|
|
@ -15,13 +15,12 @@ from zerver.lib.actions import (
|
|||
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.test_helpers import tornado_redirected_to_list
|
||||
from zerver.models import get_realm, get_user_profile_by_email, Realm
|
||||
from zerver.models import get_realm, Realm, UserProfile
|
||||
|
||||
|
||||
class RealmTest(ZulipTestCase):
|
||||
def assert_user_profile_cache_gets_new_name(self, email, new_realm_name):
|
||||
# type: (Text, Text) -> None
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
def assert_user_profile_cache_gets_new_name(self, user_profile, new_realm_name):
|
||||
# type: (UserProfile, Text) -> None
|
||||
self.assertEqual(user_profile.realm.name, new_realm_name)
|
||||
|
||||
def test_do_set_realm_name_caching(self):
|
||||
|
@ -34,7 +33,7 @@ class RealmTest(ZulipTestCase):
|
|||
new_name = u'Zed You Elle Eye Pea'
|
||||
do_set_realm_property(realm, 'name', new_name)
|
||||
self.assertEqual(get_realm(realm.string_id).name, new_name)
|
||||
self.assert_user_profile_cache_gets_new_name('hamlet@zulip.com', new_name)
|
||||
self.assert_user_profile_cache_gets_new_name(self.example_user('hamlet'), new_name)
|
||||
|
||||
def test_update_realm_name_events(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -11,7 +11,7 @@ from zerver.lib.actions import do_change_is_admin, \
|
|||
from zerver.lib.domains import validate_domain
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import email_allowed_for_realm, get_realm, \
|
||||
get_realm_by_email_domain, get_user_profile_by_email, \
|
||||
get_realm_by_email_domain, \
|
||||
GetRealmByDomainException, RealmDomain
|
||||
|
||||
import ujson
|
||||
|
|
|
@ -10,7 +10,7 @@ from typing import Any, Dict
|
|||
from zerver.lib.initial_password import initial_password
|
||||
from zerver.lib.sessions import get_session_dict_user
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import get_user_profile_by_email
|
||||
from zerver.models import get_realm, get_user
|
||||
|
||||
class ChangeSettingsTest(ZulipTestCase):
|
||||
|
||||
|
@ -99,7 +99,7 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
# give them the courtesy of an error reason.
|
||||
self.assert_json_success(json_result)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertEqual(user.full_name, full_name)
|
||||
|
||||
# Now try a too-long name
|
||||
|
@ -203,13 +203,13 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
"""
|
||||
Test changing the default language of the user.
|
||||
"""
|
||||
email = "hamlet@zulip.com"
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
german = "de"
|
||||
data = dict(default_language=ujson.dumps(german))
|
||||
result = self.client_patch("/json/settings/display", data)
|
||||
self.assert_json_success(result)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.assertEqual(user_profile.default_language, german)
|
||||
|
||||
# Test to make sure invalid languages are not accepted
|
||||
|
@ -218,7 +218,7 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
data = dict(default_language=ujson.dumps(invalid_lang))
|
||||
result = self.client_patch("/json/settings/display", data)
|
||||
self.assert_json_error(result, "Invalid language '%s'" % (invalid_lang,))
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.assertNotEqual(user_profile.default_language, invalid_lang)
|
||||
|
||||
def test_change_timezone(self):
|
||||
|
@ -226,13 +226,13 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
"""
|
||||
Test changing the timezone of the user.
|
||||
"""
|
||||
email = "hamlet@zulip.com"
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
usa_pacific = 'US/Pacific'
|
||||
data = dict(timezone=ujson.dumps(usa_pacific))
|
||||
result = self.client_patch("/json/settings/display", data)
|
||||
self.assert_json_success(result)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.assertEqual(user_profile.timezone, usa_pacific)
|
||||
|
||||
# Test to make sure invalid timezones are not accepted
|
||||
|
@ -241,7 +241,7 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
data = dict(timezone=ujson.dumps(invalid_timezone))
|
||||
result = self.client_patch("/json/settings/display", data)
|
||||
self.assert_json_error(result, "Invalid timezone '%s'" % (invalid_timezone,))
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.assertNotEqual(user_profile.timezone, invalid_timezone)
|
||||
|
||||
def test_change_emojiset(self):
|
||||
|
@ -249,13 +249,13 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
"""
|
||||
Test changing the emojiset.
|
||||
"""
|
||||
email = "hamlet@zulip.com"
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
emojiset = 'apple'
|
||||
data = dict(emojiset=ujson.dumps(emojiset))
|
||||
result = self.client_patch("/json/settings/display", data)
|
||||
self.assert_json_success(result)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.assertEqual(user_profile.emojiset, emojiset)
|
||||
|
||||
# Test to make sure invalid emojisets are not accepted
|
||||
|
@ -264,7 +264,7 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||
data = dict(emojiset=ujson.dumps(invalid_emojiset))
|
||||
result = self.client_patch("/json/settings/display", data)
|
||||
self.assert_json_error(result, "Invalid emojiset '%s'" % (invalid_emojiset,))
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.assertNotEqual(user_profile.emojiset, invalid_emojiset)
|
||||
|
||||
class UserChangesTest(ZulipTestCase):
|
||||
|
@ -278,5 +278,5 @@ class UserChangesTest(ZulipTestCase):
|
|||
self.assert_json_success(result)
|
||||
new_api_key = ujson.loads(result.content)['api_key']
|
||||
self.assertNotEqual(old_api_key, new_api_key)
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertEqual(new_api_key, user.api_key)
|
||||
|
|
|
@ -23,7 +23,7 @@ from zerver.views.registration import confirmation_key, \
|
|||
redirect_and_log_into_subdomain, send_registration_completion_email
|
||||
|
||||
from zerver.models import (
|
||||
get_realm, get_prereg_user_by_email, get_user_profile_by_email,
|
||||
get_realm, get_prereg_user_by_email, get_user,
|
||||
get_unique_open_realm, completely_open, get_recipient,
|
||||
PreregistrationUser, Realm, RealmDomain, Recipient, Message,
|
||||
Referral, ScheduledJob, UserProfile, UserMessage,
|
||||
|
@ -94,15 +94,16 @@ class AddNewUserHistoryTest(ZulipTestCase):
|
|||
"Denmark": {"description": "A Scandinavian country", "invite_only": False},
|
||||
"Verona": {"description": "A city in Italy", "invite_only": False}
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
set_default_streams(get_realm("zulip"), stream_dict)
|
||||
realm = get_realm('zulip')
|
||||
set_default_streams(realm, stream_dict)
|
||||
with patch("zerver.lib.actions.add_new_user_history"):
|
||||
self.register("test@zulip.com", "test")
|
||||
user_profile = get_user_profile_by_email("test@zulip.com")
|
||||
self.register(self.nonreg_email('test'), "test")
|
||||
user_profile = self.nonreg_user('test')
|
||||
|
||||
subs = Subscription.objects.select_related("recipient").filter(
|
||||
user_profile=user_profile, recipient__type=Recipient.STREAM)
|
||||
streams = Stream.objects.filter(id__in=[sub.recipient.type_id for sub in subs])
|
||||
self.send_message("hamlet@zulip.com", streams[0].name, Recipient.STREAM, "test")
|
||||
self.send_message(self.example_email('hamlet'), streams[0].name, Recipient.STREAM, "test")
|
||||
add_new_user_history(user_profile, streams)
|
||||
|
||||
class PasswordResetTest(ZulipTestCase):
|
||||
|
@ -264,10 +265,10 @@ class LoginTest(ZulipTestCase):
|
|||
Site.objects.clear_cache()
|
||||
|
||||
with queries_captured() as queries:
|
||||
self.register("test@zulip.com", "test")
|
||||
self.register(self.nonreg_email('test'), "test")
|
||||
# Ensure the number of queries we make is not O(streams)
|
||||
self.assert_length(queries, 47)
|
||||
user_profile = get_user_profile_by_email('test@zulip.com')
|
||||
user_profile = self.nonreg_user('test')
|
||||
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
|
||||
self.assertFalse(user_profile.enable_stream_desktop_notifications)
|
||||
|
||||
|
@ -281,11 +282,11 @@ class LoginTest(ZulipTestCase):
|
|||
realm.deactivated = True
|
||||
realm.save(update_fields=["deactivated"])
|
||||
|
||||
result = self.register("test@zulip.com", "test")
|
||||
result = self.register(self.nonreg_email('test'), "test")
|
||||
self.assert_in_response("has been deactivated", result)
|
||||
|
||||
with self.assertRaises(UserProfile.DoesNotExist):
|
||||
get_user_profile_by_email('test@zulip.com')
|
||||
self.nonreg_user('test')
|
||||
|
||||
def test_login_deactivated(self):
|
||||
# type: () -> None
|
||||
|
@ -312,12 +313,12 @@ class LoginTest(ZulipTestCase):
|
|||
"""
|
||||
You can log in even if your password contain non-ASCII characters.
|
||||
"""
|
||||
email = "test@zulip.com"
|
||||
email = self.nonreg_email('test')
|
||||
password = u"hümbüǵ"
|
||||
|
||||
# Registering succeeds.
|
||||
self.register("test@zulip.com", password)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
self.register(email, password)
|
||||
user_profile = self.nonreg_user('test')
|
||||
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
|
||||
self.logout()
|
||||
self.assertIsNone(get_session_dict_user(self.client.session))
|
||||
|
@ -450,7 +451,7 @@ class InviteUserTest(ZulipTestCase):
|
|||
Test that a new user invited to a stream receives some initial
|
||||
history but only from public streams.
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
self.login(self.example_email('hamlet'))
|
||||
user_profile = self.example_user('hamlet')
|
||||
private_stream_name = "Secret"
|
||||
self.make_stream(private_stream_name, invite_only=True)
|
||||
|
@ -459,12 +460,12 @@ class InviteUserTest(ZulipTestCase):
|
|||
"Public topic", "Public message")
|
||||
secret_msg_id = self.send_message("hamlet@zulip.com", private_stream_name, Recipient.STREAM,
|
||||
"Secret topic", "Secret message")
|
||||
invitee = "alice-test@zulip.com"
|
||||
invitee = self.nonreg_email('alice')
|
||||
self.assert_json_success(self.invite(invitee, [private_stream_name, "Denmark"]))
|
||||
self.assertTrue(find_key_by_email(invitee))
|
||||
|
||||
self.submit_reg_form_for_user("alice-test@zulip.com", "password")
|
||||
invitee_profile = get_user_profile_by_email(invitee)
|
||||
self.submit_reg_form_for_user(invitee, "password")
|
||||
invitee_profile = self.nonreg_user('alice')
|
||||
invitee_msg_ids = [um.message_id for um in
|
||||
UserMessage.objects.filter(user_profile=invitee_profile)]
|
||||
self.assertTrue(public_msg_id in invitee_msg_ids)
|
||||
|
@ -694,16 +695,19 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
|||
def test_invitation_reminder_email(self):
|
||||
# type: () -> None
|
||||
from django.core.mail import outbox
|
||||
current_user_email = "hamlet@zulip.com"
|
||||
|
||||
# All users belong to zulip realm
|
||||
referrer_user = 'hamlet'
|
||||
current_user_email = self.example_email(referrer_user)
|
||||
self.login(current_user_email)
|
||||
invitee = "alice-test@zulip.com"
|
||||
invitee = self.nonreg_email('alice')
|
||||
self.assert_json_success(self.invite(invitee, ["Denmark"]))
|
||||
self.assertTrue(find_key_by_email(invitee))
|
||||
self.check_sent_emails([invitee])
|
||||
|
||||
data = {"email": invitee, "referrer_email": current_user_email}
|
||||
invitee = get_prereg_user_by_email(data["email"])
|
||||
referrer = get_user_profile_by_email(data["referrer_email"])
|
||||
referrer = self.example_user(referrer_user)
|
||||
link = Confirmation.objects.get_link_for_object(invitee, host=referrer.realm.host)
|
||||
context = common_context(referrer)
|
||||
context.update({
|
||||
|
@ -882,7 +886,7 @@ class RealmCreationTest(ZulipTestCase):
|
|||
realm = get_realm(string_id)
|
||||
self.assertIsNotNone(realm)
|
||||
self.assertEqual(realm.string_id, string_id)
|
||||
self.assertEqual(get_user_profile_by_email(email).realm, realm)
|
||||
self.assertEqual(get_user(email, realm).realm, realm)
|
||||
|
||||
# Check defaults
|
||||
self.assertEqual(realm.org_type, Realm.COMMUNITY)
|
||||
|
@ -964,7 +968,7 @@ class RealmCreationTest(ZulipTestCase):
|
|||
realm = get_realm(string_id)
|
||||
self.assertIsNotNone(realm)
|
||||
self.assertEqual(realm.string_id, string_id)
|
||||
self.assertEqual(get_user_profile_by_email(email).realm, realm)
|
||||
self.assertEqual(get_user(email, realm).realm, realm)
|
||||
|
||||
self.assertEqual(realm.name, realm_name)
|
||||
self.assertEqual(realm.subdomain, string_id)
|
||||
|
@ -1016,7 +1020,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
Check if the default language of new user is the default language
|
||||
of the realm.
|
||||
"""
|
||||
email = "newguy@zulip.com"
|
||||
email = self.nonreg_email('newguy')
|
||||
password = "newpassword"
|
||||
timezone = "US/Mountain"
|
||||
realm = get_realm('zulip')
|
||||
|
@ -1038,7 +1042,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
result = self.submit_reg_form_for_user(email, password, timezone=timezone)
|
||||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.nonreg_user('newguy')
|
||||
self.assertEqual(user_profile.default_language, realm.default_language)
|
||||
self.assertEqual(user_profile.timezone, timezone)
|
||||
from django.core.mail import outbox
|
||||
|
@ -1085,7 +1089,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
password_auth_enabled is False.
|
||||
"""
|
||||
|
||||
email = "newuser@zulip.com"
|
||||
email = self.nonreg_email('newuser')
|
||||
|
||||
result = self.client_post('/accounts/home/', {'email': email})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
|
@ -1111,7 +1115,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
|
||||
# User should now be logged in.
|
||||
self.assertEqual(result.status_code, 302)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.nonreg_user('newuser')
|
||||
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
|
||||
|
||||
def test_signup_without_full_name(self):
|
||||
|
@ -1837,15 +1841,14 @@ class LoginOrAskForRegistrationTestCase(ZulipTestCase):
|
|||
# type: () -> None
|
||||
request = POSTRequestMock({}, None)
|
||||
setattr(request, 'session', self.client.session)
|
||||
email = 'hamlet@zulip.com'
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
user_profile.backend = 'zproject.backends.GitHubAuthBackend'
|
||||
full_name = 'Hamlet'
|
||||
invalid_subdomain = False
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
|
||||
response = login_or_register_remote_user(
|
||||
request,
|
||||
email,
|
||||
user_profile.email,
|
||||
user_profile,
|
||||
full_name=full_name,
|
||||
invalid_subdomain=invalid_subdomain)
|
||||
|
@ -1859,15 +1862,14 @@ class LoginOrAskForRegistrationTestCase(ZulipTestCase):
|
|||
request = POSTRequestMock({}, None)
|
||||
setattr(request, 'session', self.client.session)
|
||||
setattr(request, 'get_host', lambda: 'localhost')
|
||||
email = 'hamlet@zulip.com'
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
user_profile.backend = 'zproject.backends.GitHubAuthBackend'
|
||||
full_name = 'Hamlet'
|
||||
invalid_subdomain = False
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=False):
|
||||
response = login_or_register_remote_user(
|
||||
request,
|
||||
email,
|
||||
user_profile.email,
|
||||
user_profile,
|
||||
full_name=full_name,
|
||||
invalid_subdomain=invalid_subdomain)
|
||||
|
|
|
@ -4,8 +4,9 @@ from __future__ import print_function
|
|||
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from zerver.lib.test_helpers import (
|
||||
get_user_profile_by_email,
|
||||
most_recent_message,
|
||||
)
|
||||
|
||||
|
@ -14,7 +15,8 @@ from zerver.lib.test_classes import (
|
|||
)
|
||||
|
||||
from zerver.models import (
|
||||
UserProfile,
|
||||
get_system_bot,
|
||||
UserProfile
|
||||
)
|
||||
|
||||
import ujson
|
||||
|
@ -32,7 +34,7 @@ class TutorialTests(ZulipTestCase):
|
|||
email = user.email
|
||||
self.login(email)
|
||||
|
||||
welcome_bot = get_user_profile_by_email("welcome-bot@zulip.com")
|
||||
welcome_bot = get_system_bot(settings.WELCOME_BOT)
|
||||
|
||||
raw_params = dict(
|
||||
type='stream',
|
||||
|
@ -69,7 +71,7 @@ class TutorialTests(ZulipTestCase):
|
|||
|
||||
def test_tutorial_status(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
|
||||
cases = [
|
||||
|
@ -81,5 +83,5 @@ class TutorialTests(ZulipTestCase):
|
|||
params = fix_params(raw_params)
|
||||
result = self.client_post('/json/tutorial_status', params)
|
||||
self.assert_json_success(result)
|
||||
user = get_user_profile_by_email(email)
|
||||
user = self.example_user('hamlet')
|
||||
self.assertEqual(user.tutorial_status, expected_db_status)
|
||||
|
|
|
@ -9,7 +9,7 @@ from zerver.lib.test_helpers import tornado_redirected_to_list, get_display_reci
|
|||
from zerver.lib.test_classes import (
|
||||
ZulipTestCase,
|
||||
)
|
||||
from zerver.models import get_user_profile_by_email
|
||||
from zerver.models import get_realm, get_user
|
||||
|
||||
class TypingNotificationOperatorTest(ZulipTestCase):
|
||||
def test_missing_parameter(self):
|
||||
|
@ -61,16 +61,17 @@ class TypingNotificationRecipientsTest(ZulipTestCase):
|
|||
"""
|
||||
Sending typing notification to a single recipient is successful
|
||||
"""
|
||||
sender = 'hamlet@zulip.com'
|
||||
recipient = 'othello@zulip.com'
|
||||
expected_recipient_emails = set([sender, recipient])
|
||||
expected_recipient_ids = set([get_user_profile_by_email(email).id for email in expected_recipient_emails])
|
||||
sender = self.example_user('hamlet')
|
||||
recipient = self.example_user('othello')
|
||||
expected_recipients = set([sender, recipient])
|
||||
expected_recipient_emails = set([user.email for user in expected_recipients])
|
||||
expected_recipient_ids = set([user.id for user in expected_recipients])
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
result = self.client_post('/api/v1/typing', {'to': recipient,
|
||||
result = self.client_post('/api/v1/typing', {'to': recipient.email,
|
||||
'op': 'start'},
|
||||
**self.api_auth(sender))
|
||||
**self.api_auth(sender.email))
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(len(events), 1)
|
||||
|
||||
|
@ -81,7 +82,7 @@ class TypingNotificationRecipientsTest(ZulipTestCase):
|
|||
|
||||
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
||||
self.assertEqual(expected_recipient_ids, event_user_ids)
|
||||
self.assertEqual(event['sender']['email'], sender)
|
||||
self.assertEqual(event['sender']['email'], sender.email)
|
||||
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
||||
self.assertEqual(event['type'], 'typing')
|
||||
self.assertEqual(event['op'], 'start')
|
||||
|
@ -91,15 +92,16 @@ class TypingNotificationRecipientsTest(ZulipTestCase):
|
|||
"""
|
||||
Sending typing notification to a single recipient is successful
|
||||
"""
|
||||
sender = 'hamlet@zulip.com'
|
||||
recipient = ['othello@zulip.com', 'cordelia@zulip.com']
|
||||
expected_recipient_emails = set(recipient) | set([sender])
|
||||
expected_recipient_ids = set([get_user_profile_by_email(email).id for email in expected_recipient_emails])
|
||||
sender = self.example_user('hamlet')
|
||||
recipient = [self.example_user('othello'), self.example_user('cordelia')]
|
||||
expected_recipients = set(recipient) | set([sender])
|
||||
expected_recipient_emails = set([user.email for user in expected_recipients])
|
||||
expected_recipient_ids = set([user.id for user in expected_recipients])
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
result = self.client_post('/api/v1/typing', {'to': ujson.dumps(recipient),
|
||||
result = self.client_post('/api/v1/typing', {'to': ujson.dumps([user.email for user in recipient]),
|
||||
'op': 'start'},
|
||||
**self.api_auth(sender))
|
||||
**self.api_auth(sender.email))
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(len(events), 1)
|
||||
|
||||
|
@ -110,7 +112,7 @@ class TypingNotificationRecipientsTest(ZulipTestCase):
|
|||
|
||||
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
||||
self.assertEqual(expected_recipient_ids, event_user_ids)
|
||||
self.assertEqual(event['sender']['email'], sender)
|
||||
self.assertEqual(event['sender']['email'], sender.email)
|
||||
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
||||
self.assertEqual(event['type'], 'typing')
|
||||
self.assertEqual(event['op'], 'start')
|
||||
|
@ -152,16 +154,17 @@ class TypingStartedNotificationTest(ZulipTestCase):
|
|||
Sending typing notification to another user
|
||||
is successful.
|
||||
"""
|
||||
sender = 'hamlet@zulip.com'
|
||||
recipient = 'othello@zulip.com'
|
||||
expected_recipient_emails = set([sender, recipient])
|
||||
expected_recipient_ids = set([get_user_profile_by_email(email).id for email in expected_recipient_emails])
|
||||
sender = self.example_user('hamlet')
|
||||
recipient = self.example_user('othello')
|
||||
expected_recipients = set([sender, recipient])
|
||||
expected_recipient_emails = set([user.email for user in expected_recipients])
|
||||
expected_recipient_ids = set([user.id for user in expected_recipients])
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
result = self.client_post('/api/v1/typing', {'to': recipient,
|
||||
result = self.client_post('/api/v1/typing', {'to': recipient.email,
|
||||
'op': 'start'},
|
||||
**self.api_auth(sender))
|
||||
**self.api_auth(sender.email))
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(len(events), 1)
|
||||
|
||||
|
@ -173,7 +176,7 @@ class TypingStartedNotificationTest(ZulipTestCase):
|
|||
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
||||
self.assertEqual(expected_recipient_ids, event_user_ids)
|
||||
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
||||
self.assertEqual(event['sender']['email'], sender)
|
||||
self.assertEqual(event['sender']['email'], sender.email)
|
||||
self.assertEqual(event['type'], 'typing')
|
||||
self.assertEqual(event['op'], 'start')
|
||||
|
||||
|
@ -215,16 +218,17 @@ class StoppedTypingNotificationTest(ZulipTestCase):
|
|||
Sending stopped typing notification to another user
|
||||
is successful.
|
||||
"""
|
||||
sender = 'hamlet@zulip.com'
|
||||
recipient = 'othello@zulip.com'
|
||||
expected_recipient_emails = set([sender, recipient])
|
||||
expected_recipient_ids = set([get_user_profile_by_email(email).id for email in expected_recipient_emails])
|
||||
sender = self.example_user('hamlet')
|
||||
recipient = self.example_user('othello')
|
||||
expected_recipients = set([sender, recipient])
|
||||
expected_recipient_emails = set([user.email for user in expected_recipients])
|
||||
expected_recipient_ids = set([user.id for user in expected_recipients])
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
result = self.client_post('/api/v1/typing', {'to': recipient,
|
||||
result = self.client_post('/api/v1/typing', {'to': recipient.email,
|
||||
'op': 'stop'},
|
||||
**self.api_auth(sender))
|
||||
**self.api_auth(sender.email))
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(len(events), 1)
|
||||
|
||||
|
@ -236,6 +240,6 @@ class StoppedTypingNotificationTest(ZulipTestCase):
|
|||
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
||||
self.assertEqual(expected_recipient_ids, event_user_ids)
|
||||
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
||||
self.assertEqual(event['sender']['email'], sender)
|
||||
self.assertEqual(event['sender']['email'], sender.email)
|
||||
self.assertEqual(event['type'], 'typing')
|
||||
self.assertEqual(event['op'], 'stop')
|
||||
|
|
|
@ -18,7 +18,7 @@ from zerver.lib.upload import sanitize_name, S3UploadBackend, \
|
|||
upload_message_image, delete_message_image, LocalUploadBackend, \
|
||||
ZulipUploadBackend
|
||||
import zerver.lib.upload
|
||||
from zerver.models import Attachment, Recipient, get_user_profile_by_email, \
|
||||
from zerver.models import Attachment, Recipient, get_user, \
|
||||
get_old_unclaimed_attachments, Message, UserProfile, Stream, Realm, \
|
||||
RealmDomain, get_realm
|
||||
from zerver.lib.actions import do_delete_old_unclaimed_attachments
|
||||
|
@ -462,10 +462,10 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
def test_cross_realm_file_access(self):
|
||||
# type: () -> None
|
||||
|
||||
def create_user(email):
|
||||
def create_user(email, realm_id):
|
||||
# type: (Text) -> UserProfile
|
||||
self.register(email, 'test')
|
||||
return get_user_profile_by_email(email)
|
||||
return get_user(email, get_realm(realm_id))
|
||||
|
||||
user1_email = 'user1@uploadtest.example.com'
|
||||
user2_email = 'test-og-bot@zulip.com'
|
||||
|
@ -485,9 +485,9 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
deployment = Deployment.objects.filter()[0]
|
||||
deployment.realms.add(r1)
|
||||
|
||||
create_user(user1_email)
|
||||
create_user(user2_email)
|
||||
create_user(user3_email)
|
||||
create_user(user1_email, 'uploadtest.example.com')
|
||||
create_user(user2_email, 'zulip')
|
||||
create_user(user3_email, 'uploadtest.example.com')
|
||||
|
||||
# Send a message from @zulip.com -> @uploadtest.example.com
|
||||
self.login(user2_email, 'test')
|
||||
|
|
|
@ -21,7 +21,7 @@ from zerver.lib.test_runner import slow
|
|||
|
||||
from zerver.models import UserProfile, Recipient, \
|
||||
Realm, RealmDomain, UserActivity, \
|
||||
get_user_profile_by_email, get_realm, get_client, get_stream, \
|
||||
get_user, get_realm, get_client, get_stream, \
|
||||
Message, get_context_for_message
|
||||
|
||||
from zerver.lib.avatar import avatar_url
|
||||
|
@ -236,7 +236,8 @@ class AdminCreateUserTest(ZulipTestCase):
|
|||
result = self.client_post("/json/users", valid_params)
|
||||
self.assert_json_success(result)
|
||||
|
||||
new_user = get_user_profile_by_email('romeo@zulip.net')
|
||||
# Romeo is a newly registered user
|
||||
new_user = get_user('romeo@zulip.net', get_realm('zulip'))
|
||||
self.assertEqual(new_user.full_name, 'Romeo Montague')
|
||||
self.assertEqual(new_user.short_name, 'Romeo')
|
||||
|
||||
|
@ -287,17 +288,17 @@ class ActivateTest(ZulipTestCase):
|
|||
# type: () -> None
|
||||
"""This test helps ensure that our URL patterns for /users/me URLs
|
||||
handle email addresses starting with "me" correctly."""
|
||||
self.register("me@zulip.com", "testpassword")
|
||||
self.register(self.nonreg_email('me'), "testpassword")
|
||||
self.login('iago@zulip.com')
|
||||
|
||||
result = self.client_delete('/json/users/me@zulip.com')
|
||||
self.assert_json_success(result)
|
||||
user = get_user_profile_by_email('me@zulip.com')
|
||||
user = self.nonreg_user('me')
|
||||
self.assertFalse(user.is_active)
|
||||
|
||||
result = self.client_post('/json/users/me@zulip.com/reactivate')
|
||||
result = self.client_post('/json/users/{email}/reactivate'.format(email=self.nonreg_email('me')))
|
||||
self.assert_json_success(result)
|
||||
user = get_user_profile_by_email('me@zulip.com')
|
||||
user = self.nonreg_user('me')
|
||||
self.assertTrue(user.is_active)
|
||||
|
||||
def test_api_with_nonexistent_user(self):
|
||||
|
@ -346,12 +347,13 @@ class GetProfileTest(ZulipTestCase):
|
|||
result = self.client_post("/json/users/me/pointer", {"pointer": pointer})
|
||||
self.assert_json_success(result)
|
||||
|
||||
def common_get_profile(self, email):
|
||||
def common_get_profile(self, user_id):
|
||||
# type: (str) -> Dict[Text, Any]
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
self.send_message(email, "Verona", Recipient.STREAM, "hello")
|
||||
# Assumes all users are example users in realm 'zulip'
|
||||
user_profile = self.example_user(user_id)
|
||||
self.send_message(user_profile.email, "Verona", Recipient.STREAM, "hello")
|
||||
|
||||
result = self.client_get("/api/v1/users/me", **self.api_auth(email))
|
||||
result = self.client_get("/api/v1/users/me", **self.api_auth(user_profile.email))
|
||||
|
||||
max_id = most_recent_message(user_profile).id
|
||||
|
||||
|
@ -407,7 +409,7 @@ class GetProfileTest(ZulipTestCase):
|
|||
"""
|
||||
Ensure GET /users/me returns a max message id and returns successfully
|
||||
"""
|
||||
json = self.common_get_profile("othello@zulip.com")
|
||||
json = self.common_get_profile("othello")
|
||||
self.assertEqual(json["pointer"], -1)
|
||||
|
||||
def test_profile_with_pointer(self):
|
||||
|
@ -416,17 +418,17 @@ class GetProfileTest(ZulipTestCase):
|
|||
Ensure GET /users/me returns a proper pointer id after the pointer is updated
|
||||
"""
|
||||
|
||||
id1 = self.send_message("othello@zulip.com", "Verona", Recipient.STREAM)
|
||||
id2 = self.send_message("othello@zulip.com", "Verona", Recipient.STREAM)
|
||||
id1 = self.send_message(self.example_email("othello"), "Verona", Recipient.STREAM)
|
||||
id2 = self.send_message(self.example_email("othello"), "Verona", Recipient.STREAM)
|
||||
|
||||
json = self.common_get_profile("hamlet@zulip.com")
|
||||
json = self.common_get_profile("hamlet")
|
||||
|
||||
self.common_update_pointer("hamlet@zulip.com", id2)
|
||||
json = self.common_get_profile("hamlet@zulip.com")
|
||||
self.common_update_pointer(self.example_email("hamlet"), id2)
|
||||
json = self.common_get_profile("hamlet")
|
||||
self.assertEqual(json["pointer"], id2)
|
||||
|
||||
self.common_update_pointer("hamlet@zulip.com", id1)
|
||||
json = self.common_get_profile("hamlet@zulip.com")
|
||||
self.common_update_pointer(self.example_email("hamlet"), id1)
|
||||
json = self.common_get_profile("hamlet")
|
||||
self.assertEqual(json["pointer"], id2) # pointer does not move backwards
|
||||
|
||||
result = self.client_post("/json/users/me/pointer", {"pointer": 99999999})
|
||||
|
|
Loading…
Reference in New Issue