mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
tests: Add make_client() test helper.
This commit is contained in:
@@ -140,6 +140,11 @@ def queries_captured():
|
|||||||
TimeTrackingCursor.executemany = old_executemany # type: ignore # https://github.com/JukkaL/mypy/issues/1167
|
TimeTrackingCursor.executemany = old_executemany # type: ignore # https://github.com/JukkaL/mypy/issues/1167
|
||||||
|
|
||||||
|
|
||||||
|
def make_client(name):
|
||||||
|
# type: (str) -> Client
|
||||||
|
client, _ = Client.objects.get_or_create(name=name)
|
||||||
|
return client
|
||||||
|
|
||||||
def find_key_by_email(address):
|
def find_key_by_email(address):
|
||||||
# type: (text_type) -> text_type
|
# type: (text_type) -> text_type
|
||||||
from django.core.mail import outbox
|
from django.core.mail import outbox
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from zilencer.models import Deployment
|
|||||||
from zerver.lib.test_helpers import (
|
from zerver.lib.test_helpers import (
|
||||||
ZulipTestCase,
|
ZulipTestCase,
|
||||||
get_user_messages,
|
get_user_messages,
|
||||||
|
make_client,
|
||||||
message_ids, message_stream_count,
|
message_ids, message_stream_count,
|
||||||
most_recent_message,
|
most_recent_message,
|
||||||
queries_captured,
|
queries_captured,
|
||||||
@@ -19,7 +20,7 @@ from zerver.lib.test_helpers import (
|
|||||||
|
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH,
|
MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH,
|
||||||
Client, Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment,
|
Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment,
|
||||||
get_realm, get_stream, get_user_profile_by_email,
|
get_realm, get_stream, get_user_profile_by_email,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -324,7 +325,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||||||
sender_email = 'hamlet@zulip.com'
|
sender_email = 'hamlet@zulip.com'
|
||||||
sender = get_user_profile_by_email(sender_email)
|
sender = get_user_profile_by_email(sender_email)
|
||||||
message_type_name = "stream"
|
message_type_name = "stream"
|
||||||
(sending_client, _) = Client.objects.get_or_create(name="test suite")
|
sending_client = make_client(name="test suite")
|
||||||
stream = 'Denmark'
|
stream = 'Denmark'
|
||||||
subject = 'foo'
|
subject = 'foo'
|
||||||
content = 'whatever'
|
content = 'whatever'
|
||||||
@@ -416,7 +417,7 @@ class MessageDictTest(ZulipTestCase):
|
|||||||
pm_recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
|
pm_recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
|
||||||
stream, _ = create_stream_if_needed(realm, 'devel')
|
stream, _ = create_stream_if_needed(realm, 'devel')
|
||||||
stream_recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
|
stream_recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
|
||||||
sending_client, _ = Client.objects.get_or_create(name="test suite")
|
sending_client = make_client(name="test suite")
|
||||||
|
|
||||||
for i in range(300):
|
for i in range(300):
|
||||||
for recipient in [pm_recipient, stream_recipient]:
|
for recipient in [pm_recipient, stream_recipient]:
|
||||||
@@ -454,7 +455,7 @@ class MessageDictTest(ZulipTestCase):
|
|||||||
sender = get_user_profile_by_email('othello@zulip.com')
|
sender = get_user_profile_by_email('othello@zulip.com')
|
||||||
receiver = get_user_profile_by_email('hamlet@zulip.com')
|
receiver = get_user_profile_by_email('hamlet@zulip.com')
|
||||||
recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
|
recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
|
||||||
sending_client, _ = Client.objects.get_or_create(name="test suite")
|
sending_client = make_client(name="test suite")
|
||||||
message = Message(
|
message = Message(
|
||||||
sender=sender,
|
sender=sender,
|
||||||
recipient=recipient,
|
recipient=recipient,
|
||||||
@@ -1277,7 +1278,7 @@ class CheckMessageTest(ZulipTestCase):
|
|||||||
def test_basic_check_message_call(self):
|
def test_basic_check_message_call(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
sender = get_user_profile_by_email('othello@zulip.com')
|
sender = get_user_profile_by_email('othello@zulip.com')
|
||||||
client, _ = Client.objects.get_or_create(name="test suite")
|
client = make_client(name="test suite")
|
||||||
stream_name = 'integration'
|
stream_name = 'integration'
|
||||||
stream, _ = create_stream_if_needed(get_realm("zulip.com"), stream_name)
|
stream, _ = create_stream_if_needed(get_realm("zulip.com"), stream_name)
|
||||||
message_type_name = 'stream'
|
message_type_name = 'stream'
|
||||||
@@ -1307,7 +1308,7 @@ class CheckMessageTest(ZulipTestCase):
|
|||||||
bot.last_reminder = None
|
bot.last_reminder = None
|
||||||
|
|
||||||
sender = bot
|
sender = bot
|
||||||
client, _ = Client.objects.get_or_create(name="test suite")
|
client = make_client(name="test suite")
|
||||||
stream_name = 'integration'
|
stream_name = 'integration'
|
||||||
stream, _ = create_stream_if_needed(get_realm("zulip.com"), stream_name)
|
stream, _ = create_stream_if_needed(get_realm("zulip.com"), stream_name)
|
||||||
message_type_name = 'stream'
|
message_type_name = 'stream'
|
||||||
|
|||||||
Reference in New Issue
Block a user