From 5404edaf0377cded36f95360e940dbb98324c3dd Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 27 Mar 2018 11:53:34 -0700 Subject: [PATCH] tests: Verify database queries for realm administrators. This number is way too high, because of a recent regression. Adding a test here lets us prevent similar regressions in the future and provides an easy way to be sure if we've fixed the issue. --- zerver/tests/test_home.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 43b128c81f28f..fdafd60394526 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -225,6 +225,17 @@ def test_home(self) -> None: realm_bots_actual_keys = sorted([str(key) for key in page_params['realm_bots'][0].keys()]) self.assertEqual(realm_bots_actual_keys, realm_bots_expected_keys) + def test_num_queries_for_realm_admin(self) -> None: + # Verify number of queries for Realm admin isn't much higher than for normal users. + self.login(self.example_email("iago")) + flush_per_request_caches() + with queries_captured() as queries: + with patch('zerver.lib.cache.cache_set') as cache_mock: + result = self._get_home_page() + self.assertEqual(result.status_code, 200) + self.assert_length(cache_mock.call_args_list, 17) + self.assert_length(queries, 60) + @slow("Creates and subscribes 10 users in a loop. Should use bulk queries.") def test_num_queries_with_streams(self) -> None: main_user = self.example_user('hamlet')