From 600fcd6c52ef7cec56513579e47dff7dbeb0d0f2 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 23 Feb 2020 16:24:41 +0000 Subject: [PATCH] typing tests: Add query_count checks. We should not need so many queries here, although a couple of the queries are just standard things that apply to all requests. I will reduce the number of queries in a later commit. --- zerver/tests/test_typing.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/zerver/tests/test_typing.py b/zerver/tests/test_typing.py index e7cd3fa7a2..22d85e623d 100644 --- a/zerver/tests/test_typing.py +++ b/zerver/tests/test_typing.py @@ -7,7 +7,10 @@ from django.conf import settings from django.core.exceptions import ValidationError from zerver.lib.actions import recipient_for_user_ids -from zerver.lib.test_helpers import tornado_redirected_to_list +from zerver.lib.test_helpers import ( + tornado_redirected_to_list, + queries_captured, +) from zerver.lib.test_classes import ( ZulipTestCase, ) @@ -90,19 +93,19 @@ class TypingNotificationRecipientsTest(ZulipTestCase): expected_recipient_emails = set([user.email for user in expected_recipients]) expected_recipient_ids = set([user.id for user in expected_recipients]) + params = dict( + to=ujson.dumps([recipient_user.id]), + op='start', + ) + events = [] # type: List[Mapping[str, Any]] - with tornado_redirected_to_list(events): - result = self.api_post( - sender.email, - '/api/v1/typing', - { - 'to': ujson.dumps([recipient_user.id]), - 'op': 'start' - } - ) + with queries_captured() as queries: + with tornado_redirected_to_list(events): + result = self.api_post(sender.email, '/api/v1/typing', params) self.assert_json_success(result) self.assertEqual(len(events), 1) + self.assertEqual(len(queries), 8) event = events[0]['event'] event_recipient_emails = set(user['email'] for user in event['recipients']) @@ -156,12 +159,18 @@ class TypingNotificationRecipientsTest(ZulipTestCase): 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[Mapping[str, Any]] - with tornado_redirected_to_list(events): - result = self.api_post(sender.email, '/api/v1/typing', - {'to': ujson.dumps([user.id for user in recipient_users]), - 'op': 'start'}) + + params = dict( + to=ujson.dumps([user.id for user in recipient_users]), + op='start', + ) + + with queries_captured() as queries: + with tornado_redirected_to_list(events): + result = self.api_post(sender.email, '/api/v1/typing', params) self.assert_json_success(result) self.assertEqual(len(events), 1) + self.assertEqual(len(queries), 15) event = events[0]['event'] event_recipient_emails = set(user['email'] for user in event['recipients'])