test_auth_backends: Verify the avatar contents.

Consuming response.streaming_content fixes this warning from
TestLDAP.test_login_success_when_user_does_not_exist_with_valid_subdomain:
“ResourceWarning: unclosed file <_io.FileIO
name='/srv/zulip/var/…/3cc4b5a15b6f4f06b3f9a6ecb179b08702329716.png'
mode='rb' closefd=True>”.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-01-20 21:06:30 -08:00 committed by Tim Abbott
parent ba7ea7cc80
commit db24eca832
1 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import base64
import copy import copy
import datetime import datetime
import json import json
import os
import re import re
import secrets import secrets
import time import time
@ -70,7 +71,7 @@ from zerver.lib.test_helpers import (
use_s3_backend, use_s3_backend,
) )
from zerver.lib.types import Validator from zerver.lib.types import Validator
from zerver.lib.upload import MEDIUM_AVATAR_SIZE, resize_avatar from zerver.lib.upload import DEFAULT_AVATAR_SIZE, MEDIUM_AVATAR_SIZE, resize_avatar
from zerver.lib.users import get_all_api_keys from zerver.lib.users import get_all_api_keys
from zerver.lib.validator import ( from zerver.lib.validator import (
check_bool, check_bool,
@ -5950,8 +5951,11 @@ class TestLDAP(ZulipLDAPTestCase):
self.assertEqual(user_profile.avatar_source, UserProfile.AVATAR_FROM_USER) self.assertEqual(user_profile.avatar_source, UserProfile.AVATAR_FROM_USER)
url = avatar_url(user_profile) url = avatar_url(user_profile)
assert url is not None assert url is not None
result = self.client_get(url) response = self.client_get(url)
self.assertEqual(result.status_code, 200) self.assertEqual(response.status_code, 200)
with open(os.path.join(settings.DEPLOY_ROOT, "static/images/team/tim.png"), "rb") as f:
tim = f.read()
self.assert_streaming_content(response, resize_avatar(tim, DEFAULT_AVATAR_SIZE))
@override_settings(AUTHENTICATION_BACKENDS=("zproject.backends.ZulipLDAPAuthBackend",)) @override_settings(AUTHENTICATION_BACKENDS=("zproject.backends.ZulipLDAPAuthBackend",))
def test_login_success_when_user_does_not_exist_with_split_full_name_mapping(self) -> None: def test_login_success_when_user_does_not_exist_with_split_full_name_mapping(self) -> None: