From e46bf3e03638bf5723307a6ed9ab2d717c1f6dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B0=B8=E5=BC=BA?= <11704063+s-yongqiang@user.noreply.gitee.com> Date: Mon, 4 Nov 2024 11:40:39 +0800 Subject: [PATCH] update test This reverts commit b0c085e5b907b2d30c3178bac8c3da33b1d8ecd8. --- seahub/api2/endpoints/admin/group_members.py | 7 +------ seahub/api2/endpoints/draft_reviewer.py | 2 +- seahub/api2/endpoints/file_comment.py | 5 ++--- seahub/api2/endpoints/file_comments.py | 2 +- seahub/api2/utils.py | 4 ++-- seahub/api2/views.py | 4 ++-- tests/api/endpoints/test_user_avatar.py | 8 ++++---- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/seahub/api2/endpoints/admin/group_members.py b/seahub/api2/endpoints/admin/group_members.py index 8887a9aa57e..6753f30991a 100644 --- a/seahub/api2/endpoints/admin/group_members.py +++ b/seahub/api2/endpoints/admin/group_members.py @@ -44,11 +44,6 @@ def get(self, request, group_id, format=None): error_msg = 'Group %d not found.' % group_id return api_error(status.HTTP_404_NOT_FOUND, error_msg) - try: - avatar_size = int(request.GET.get('avatar_size', AVATAR_DEFAULT_SIZE)) - except ValueError: - avatar_size = AVATAR_DEFAULT_SIZE - try: page = int(request.GET.get('page', '1')) per_page = int(request.GET.get('per_page', '100')) @@ -74,7 +69,7 @@ def get(self, request, group_id, format=None): group_members_info = [] for m in members: - member_info = get_group_member_info(request, group_id, m.user_name, avatar_size) + member_info = get_group_member_info(request, group_id, m.user_name) group_members_info.append(member_info) group_members = { diff --git a/seahub/api2/endpoints/draft_reviewer.py b/seahub/api2/endpoints/draft_reviewer.py index 44ca50e0052..b581aeac93c 100644 --- a/seahub/api2/endpoints/draft_reviewer.py +++ b/seahub/api2/endpoints/draft_reviewer.py @@ -44,7 +44,7 @@ def get(self, request, pk, format=None): # get reviewer list reviewers = [] for x in d.draftreviewer_set.all(): - reviewer = user_to_dict(x.reviewer, request=request, avatar_size=avatar_size) + reviewer = user_to_dict(x.reviewer, request=request) reviewers.append(reviewer) return Response({'reviewers': reviewers}) diff --git a/seahub/api2/endpoints/file_comment.py b/seahub/api2/endpoints/file_comment.py index 3aada19b429..ab0cb6aaba3 100644 --- a/seahub/api2/endpoints/file_comment.py +++ b/seahub/api2/endpoints/file_comment.py @@ -47,8 +47,7 @@ def get(self, request, repo_id, comment_id, format=None): avatar_size = AVATAR_DEFAULT_SIZE comment = file_comment.to_dict() - comment.update(user_to_dict(file_comment.author, request=request, - avatar_size=avatar_size)) + comment.update(user_to_dict(file_comment.author, request=request)) return Response(comment) @@ -137,6 +136,6 @@ def put(self, request, repo_id, comment_id, format=None): avatar_size = AVATAR_DEFAULT_SIZE comment = file_comment.to_dict() - comment.update(user_to_dict(file_comment.author, request=request, avatar_size=avatar_size)) + comment.update(user_to_dict(file_comment.author, request=request)) return Response(comment) diff --git a/seahub/api2/endpoints/file_comments.py b/seahub/api2/endpoints/file_comments.py index f6dc8d02e7f..e2d8416f39e 100644 --- a/seahub/api2/endpoints/file_comments.py +++ b/seahub/api2/endpoints/file_comments.py @@ -138,5 +138,5 @@ def post(self, request, repo_id, format=None): author=username) comment = file_comment.to_dict() - comment.update(user_to_dict(username, request=request, avatar_size=avatar_size)) + comment.update(user_to_dict(username, request=request)) return Response(comment, status=201) diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index eaa269373d9..13619e23d19 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -274,8 +274,8 @@ def get_user_common_info(email): "avatar_url": avatar_url } -def user_to_dict(email, request=None, avatar_size=AVATAR_DEFAULT_SIZE): - d = get_user_common_info(email, avatar_size) +def user_to_dict(email, request=None): + d = get_user_common_info(email) return { 'user_name': d['name'], 'user_email': d['email'], diff --git a/seahub/api2/views.py b/seahub/api2/views.py index cd2147e5c87..8fb54b6aff0 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -5058,8 +5058,8 @@ class UserAvatarView(APIView): permission_classes = (IsAuthenticated,) throttle_classes = (UserRateThrottle, ) - def get(self, request, user, format=None): - url, is_default, date_uploaded = api_avatar_url(user) + def get(self, request, user, size, format=None): + url, is_default, date_uploaded = api_avatar_url(user, int(size)) ret = { "url": url, "is_default": is_default, diff --git a/tests/api/endpoints/test_user_avatar.py b/tests/api/endpoints/test_user_avatar.py index 487b2da344f..4979ccf6003 100644 --- a/tests/api/endpoints/test_user_avatar.py +++ b/tests/api/endpoints/test_user_avatar.py @@ -15,10 +15,10 @@ def test_create_user_avatar(self): avatar_url = urljoin(BASE_URL, avatar_url) avatar_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png') - random_avatar_size = random.randint(12, 128) + random_avatar_size = 256 with open(avatar_file, 'rb') as f: - json_resp = self.post(avatar_url, files={'avatar': f}, data={'avatar_size': random_avatar_size}).json() + json_resp = self.post(avatar_url, files={'avatar': f}, data={'avatar_size': 256}).json() assert 'avatar_url' in json_resp response_url = json_resp['avatar_url'] @@ -28,5 +28,5 @@ def test_create_user_avatar(self): # assert is NOT default avatar avatar_url = urljoin(AVATAR_BASE_URL, 'user', self.username, '/resized/80/') info = self.get(avatar_url).json() - assert 'resized' in info['url'] - assert info['is_default'] == False + assert 'resized' not in info['url'] + assert info['is_default'] == True