mirror of https://github.com/zulip/zulip.git
Eliminate get_user_profile_by_email from test_classes.
This commit is contained in:
parent
d1ff4293a5
commit
b9bc1c2b33
|
@ -33,7 +33,7 @@ from zerver.lib.test_helpers import (
|
|||
from zerver.models import (
|
||||
get_stream,
|
||||
get_user,
|
||||
get_user_profile_by_email,
|
||||
get_user,
|
||||
get_realm,
|
||||
Client,
|
||||
Message,
|
||||
|
@ -349,8 +349,8 @@ class ZulipTestCase(TestCase):
|
|||
else:
|
||||
raise AssertionError("Couldn't find a confirmation email.")
|
||||
|
||||
def api_auth(self, identifier):
|
||||
# type: (Text) -> Dict[str, Text]
|
||||
def api_auth(self, identifier, realm="zulip"):
|
||||
# type: (Text, Text) -> Dict[str, Text]
|
||||
"""
|
||||
identifier: Can be an email or a remote server uuid.
|
||||
"""
|
||||
|
@ -360,7 +360,7 @@ class ZulipTestCase(TestCase):
|
|||
if is_remote_server(identifier):
|
||||
api_key = get_remote_server_by_uuid(identifier).api_key
|
||||
else:
|
||||
api_key = get_user_profile_by_email(identifier).api_key
|
||||
api_key = get_user(identifier, get_realm(realm)).api_key
|
||||
API_KEYS[identifier] = api_key
|
||||
|
||||
credentials = "%s:%s" % (identifier, api_key)
|
||||
|
@ -379,9 +379,10 @@ class ZulipTestCase(TestCase):
|
|||
)
|
||||
return [cast(Text, get_display_recipient(sub.recipient)) for sub in subs]
|
||||
|
||||
def send_personal_message(self, from_email, to_email, content="test content"):
|
||||
# type: (Text, Text, Text) -> int
|
||||
sender = get_user_profile_by_email(from_email)
|
||||
def send_personal_message(self, from_email, to_email, content="test content",
|
||||
sender_realm="zulip"):
|
||||
# type: (Text, Text, Text, Text) -> int
|
||||
sender = get_user(from_email, get_realm(sender_realm))
|
||||
|
||||
recipient_list = [to_email]
|
||||
(sending_client, _) = Client.objects.get_or_create(name="test suite")
|
||||
|
@ -391,9 +392,10 @@ class ZulipTestCase(TestCase):
|
|||
content
|
||||
)
|
||||
|
||||
def send_huddle_message(self, from_email, to_emails, content="test content"):
|
||||
# type: (Text, List[Text], Text) -> int
|
||||
sender = get_user_profile_by_email(from_email)
|
||||
def send_huddle_message(self, from_email, to_emails, content="test content",
|
||||
sender_realm="zulip"):
|
||||
# type: (Text, List[Text], Text, Text) -> int
|
||||
sender = get_user(from_email, get_realm(sender_realm))
|
||||
|
||||
assert(len(to_emails) >= 2)
|
||||
|
||||
|
@ -404,10 +406,10 @@ class ZulipTestCase(TestCase):
|
|||
content
|
||||
)
|
||||
|
||||
def send_stream_message(self, sender_email, stream_name,
|
||||
content="test content", topic_name="test"):
|
||||
# type: (Text, Text, Text, Text) -> int
|
||||
sender = get_user_profile_by_email(sender_email)
|
||||
def send_stream_message(self, sender_email, stream_name, content="test content",
|
||||
topic_name="test", sender_realm="zulip"):
|
||||
# type: (Text, Text, Text, Text, Text) -> int
|
||||
sender = get_user(sender_email, get_realm(sender_realm))
|
||||
|
||||
(sending_client, _) = Client.objects.get_or_create(name="test suite")
|
||||
|
||||
|
@ -564,7 +566,7 @@ class ZulipTestCase(TestCase):
|
|||
'invite_only': ujson.dumps(invite_only)}
|
||||
post_data.update(extra_post_data)
|
||||
kw = kwargs.copy()
|
||||
kw.update(self.api_auth(email))
|
||||
kw.update(self.api_auth(email, realm=kwargs.get('subdomain', 'zulip')))
|
||||
result = self.client_post("/api/v1/users/me/subscriptions", post_data,
|
||||
**kw)
|
||||
return result
|
||||
|
|
|
@ -212,11 +212,11 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
support_bot = self.create_user(support_email)
|
||||
|
||||
# Users can PM themselves
|
||||
self.send_personal_message(user1_email, user1_email)
|
||||
self.send_personal_message(user1_email, user1_email, sender_realm="1.example.com")
|
||||
assert_message_received(user1, user1)
|
||||
|
||||
# Users on the same realm can PM each other
|
||||
self.send_personal_message(user1_email, user1a_email)
|
||||
self.send_personal_message(user1_email, user1a_email, sender_realm="1.example.com")
|
||||
assert_message_received(user1a, user1)
|
||||
|
||||
# Cross-realm bots in the zulip.com realm can PM any realm
|
||||
|
@ -230,13 +230,13 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
assert_message_received(user2, feedback_bot)
|
||||
|
||||
# All users can PM cross-realm bots in the zulip.com realm
|
||||
self.send_personal_message(user1_email, feedback_email)
|
||||
self.send_personal_message(user1_email, feedback_email, sender_realm="1.example.com")
|
||||
assert_message_received(feedback_bot, user1)
|
||||
|
||||
# Users can PM cross-realm bots on non-zulip realms.
|
||||
# (The support bot represents some theoretical bot that we may
|
||||
# create in the future that does not have zulip.com as its realm.)
|
||||
self.send_personal_message(user1_email, support_email)
|
||||
self.send_personal_message(user1_email, support_email, sender_realm="1.example.com")
|
||||
assert_message_received(support_bot, user1)
|
||||
|
||||
# Allow sending PMs to two different cross-realm bots simultaneously.
|
||||
|
@ -244,34 +244,38 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
# already individually send PMs to cross-realm bots, we shouldn't
|
||||
# prevent them from sending multiple bots at once. We may revisit
|
||||
# this if it's a nuisance for huddles.)
|
||||
self.send_huddle_message(user1_email, [feedback_email, support_email])
|
||||
self.send_huddle_message(user1_email, [feedback_email, support_email],
|
||||
sender_realm="1.example.com")
|
||||
assert_message_received(feedback_bot, user1)
|
||||
assert_message_received(support_bot, user1)
|
||||
|
||||
# Prevent old loophole where I could send PMs to other users as long
|
||||
# as I copied a cross-realm bot from the same realm.
|
||||
with assert_invalid_email():
|
||||
self.send_huddle_message(user1_email, [user3_email, support_email])
|
||||
self.send_huddle_message(user1_email, [user3_email, support_email],
|
||||
sender_realm="1.example.com")
|
||||
|
||||
# Users on three different realms can't PM each other,
|
||||
# even if one of the users is a cross-realm bot.
|
||||
with assert_invalid_email():
|
||||
self.send_huddle_message(user1_email, [user2_email, feedback_email])
|
||||
self.send_huddle_message(user1_email, [user2_email, feedback_email],
|
||||
sender_realm="1.example.com")
|
||||
|
||||
with assert_invalid_email():
|
||||
self.send_huddle_message(feedback_email, [user1_email, user2_email])
|
||||
|
||||
# Users on the different realms can not PM each other
|
||||
with assert_invalid_email():
|
||||
self.send_personal_message(user1_email, user2_email)
|
||||
self.send_personal_message(user1_email, user2_email, sender_realm="1.example.com")
|
||||
|
||||
# Users on non-zulip realms can't PM "ordinary" Zulip users
|
||||
with assert_invalid_email():
|
||||
self.send_personal_message(user1_email, "hamlet@zulip.com")
|
||||
self.send_personal_message(user1_email, "hamlet@zulip.com", sender_realm="1.example.com")
|
||||
|
||||
# Users on three different realms can not PM each other
|
||||
with assert_invalid_email():
|
||||
self.send_huddle_message(user1_email, [user2_email, user3_email])
|
||||
self.send_huddle_message(user1_email, [user2_email, user3_email],
|
||||
sender_realm="1.example.com")
|
||||
|
||||
class ExtractedRecipientsTest(TestCase):
|
||||
def test_extract_recipients(self) -> None:
|
||||
|
|
|
@ -691,8 +691,8 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
lambda_stream_d_name = u"\u03bb-stream.d"
|
||||
self.subscribe(self.mit_user("starnine"), lambda_stream_d_name)
|
||||
|
||||
self.send_stream_message(self.mit_email("starnine"), u"\u03bb-stream")
|
||||
self.send_stream_message(self.mit_email("starnine"), u"\u03bb-stream.d")
|
||||
self.send_stream_message(self.mit_email("starnine"), u"\u03bb-stream", sender_realm="zephyr")
|
||||
self.send_stream_message(self.mit_email("starnine"), u"\u03bb-stream.d", sender_realm="zephyr")
|
||||
|
||||
narrow = [dict(operator='stream', operand=u'\u03bb-stream')]
|
||||
result = self.get_and_check_messages(dict(num_after=2,
|
||||
|
@ -720,17 +720,16 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
# it to ensure that we actually have a stream message in this
|
||||
# narrow view.
|
||||
self.subscribe(mit_user_profile, "Scotland")
|
||||
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"\u03bb-topic")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"\u03bb-topic.d")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"\u03bb-topic.d.d")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"\u03bb-topic.d.d.d")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"\u03bb-topic.d.d.d.d")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"\u03bb-topic",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"\u03bb-topic.d",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"\u03bb-topic.d.d",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"\u03bb-topic.d.d.d",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"\u03bb-topic.d.d.d.d",
|
||||
sender_realm="zephyr")
|
||||
|
||||
narrow = [dict(operator='topic', operand=u'\u03bb-topic')]
|
||||
result = self.get_and_check_messages(
|
||||
|
@ -758,20 +757,20 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
self.login(email, realm=mit_user_profile.realm)
|
||||
self.subscribe(mit_user_profile, "Scotland")
|
||||
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u".d.d")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"PERSONAL")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u'(instance "").d')
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u".d.d.d")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u"personal.d")
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u'(instance "")')
|
||||
self.send_stream_message(email, "Scotland",
|
||||
topic_name=u".d.d.d.d")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u".d.d",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"PERSONAL",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u'(instance "").d',
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u".d.d.d",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u"personal.d",
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u'(instance "")',
|
||||
sender_realm="zephyr")
|
||||
self.send_stream_message(email, "Scotland", topic_name=u".d.d.d.d",
|
||||
sender_realm="zephyr")
|
||||
|
||||
narrow = [dict(operator='topic', operand=u'personal.d.d')]
|
||||
result = self.get_and_check_messages(
|
||||
|
|
|
@ -106,7 +106,7 @@ class PushBouncerNotificationTest(BouncerTestCase):
|
|||
realm.save()
|
||||
|
||||
result = self.client_post(endpoint, {'token': token, 'token_kind': token_kind},
|
||||
**self.api_auth(self.example_email("hamlet")))
|
||||
**self.api_auth(self.example_email("hamlet"), realm=""))
|
||||
self.assert_json_error(result, "Must validate with valid Zulip server API key")
|
||||
|
||||
def test_register_remote_push_user_paramas(self) -> None:
|
||||
|
|
|
@ -39,7 +39,8 @@ class TestRetentionLib(ZulipTestCase):
|
|||
# send messages from mit.edu realm and change messages pub date
|
||||
sender = self.mit_user('espuser')
|
||||
recipient = self.mit_user('starnine')
|
||||
msgs_ids = [self.send_personal_message(sender.email, recipient.email) for i in
|
||||
msgs_ids = [self.send_personal_message(sender.email, recipient.email,
|
||||
sender_realm='zephyr') for i in
|
||||
range(message_quantity)]
|
||||
mit_messages = self._change_messages_pub_date(msgs_ids, pub_date)
|
||||
return mit_messages
|
||||
|
|
|
@ -1790,7 +1790,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
streams_to_sub,
|
||||
dict(principals=ujson.dumps([user1.email, user2.email])),
|
||||
)
|
||||
self.assert_length(queries, 39)
|
||||
self.assert_length(queries, 40)
|
||||
|
||||
self.assert_length(events, 7)
|
||||
for ev in [x for x in events if x['event']['type'] not in ('message', 'stream')]:
|
||||
|
@ -2029,7 +2029,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
# Make sure Zephyr mirroring realms such as MIT do not get
|
||||
# any tornado subscription events
|
||||
self.assert_length(events, 0)
|
||||
self.assert_length(queries, 8)
|
||||
self.assert_length(queries, 9)
|
||||
|
||||
def test_bulk_subscribe_many(self) -> None:
|
||||
|
||||
|
@ -2045,7 +2045,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
dict(principals=ujson.dumps([self.test_email])),
|
||||
)
|
||||
# Make sure we don't make O(streams) queries
|
||||
self.assert_length(queries, 19)
|
||||
self.assert_length(queries, 20)
|
||||
|
||||
def test_subscriptions_add_for_principal(self) -> None:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue