mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
Use check_send_stream_message in test_not_too_many_queries.
When possible, we want to use direct APIs for sending stream messages. This changes the codepath slightly, by not using forwarded_user_profile, but it doesn't impact the number of queries, and it's a simple check. We also remove a couple "subject" references here.
This commit is contained in:
@@ -50,7 +50,7 @@ from zerver.models import (
|
||||
|
||||
from zerver.lib.actions import (
|
||||
check_message,
|
||||
check_send_message,
|
||||
check_send_stream_message,
|
||||
do_deactivate_user,
|
||||
do_set_realm_property,
|
||||
extract_recipients,
|
||||
@@ -537,27 +537,27 @@ class StreamMessagesTest(ZulipTestCase):
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
|
||||
sender = self.example_user('hamlet')
|
||||
message_type_name = "stream"
|
||||
sending_client = make_client(name="test suite")
|
||||
stream = 'Denmark'
|
||||
subject = 'foo'
|
||||
stream_name = 'Denmark'
|
||||
topic_name = 'foo'
|
||||
content = 'whatever'
|
||||
realm = sender.realm
|
||||
|
||||
def send_message():
|
||||
# type: () -> None
|
||||
check_send_message(sender, sending_client, message_type_name, [stream],
|
||||
subject, content, forwarder_user_profile=sender, realm=realm)
|
||||
|
||||
# To get accurate count of the queries, we should make sure that
|
||||
# caches don't come into play. If we count queries while caches are
|
||||
# filled, we will get a lower count. Caches are not supposed to be
|
||||
# persistent, so our test can also fail if cache is invalidated
|
||||
# during the course of the unit test.
|
||||
flush_per_request_caches()
|
||||
cache_delete(get_stream_cache_key(stream, realm.id))
|
||||
cache_delete(get_stream_cache_key(stream_name, realm.id))
|
||||
with queries_captured() as queries:
|
||||
send_message()
|
||||
check_send_stream_message(
|
||||
sender=sender,
|
||||
client=sending_client,
|
||||
stream_name=stream_name,
|
||||
topic=topic_name,
|
||||
body=content,
|
||||
)
|
||||
|
||||
self.assert_length(queries, 13)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user