test performance: Pass in users to api_* helpers.

This reduces query counts in some cases, since
we no longer need to look up the user again. In
particular, it reduces some noise when we
count queries for O(N)-related tests.

The query count is usually reduced by 2 per
API call.  We no longer need to look up Realm
and UserProfile.  In most cases we are saving
these lookups for the whole tests, since we
usually already have the `user` objects for
other reasons.  In a few places we are simply
moving where that query happens within the
test.

In some places I shorten names like `test_user`
or `user_profile` to just be `user`.
This commit is contained in:
Steve Howell
2020-03-10 10:48:26 +00:00
committed by Tim Abbott
parent 626ad0078d
commit c235333041
25 changed files with 401 additions and 406 deletions

View File

@@ -1179,7 +1179,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
# Make sure the bot cannot create their own default stream.
url = "/api/v1/bots/{}".format(bot_user.id)
result = self.api_patch(bot_user.email, url, bot_info)
result = self.api_patch(bot_user, url, bot_info)
self.assert_json_error_contains(result, 'endpoint does not accept')
def test_patch_bot_events_register_stream_allowed(self) -> None: