Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
This reverts commit b0c085e.
  • Loading branch information
孙永强 committed Nov 4, 2024
1 parent d973cc4 commit e46bf3e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
7 changes: 1 addition & 6 deletions seahub/api2/endpoints/admin/group_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion seahub/api2/endpoints/draft_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
5 changes: 2 additions & 3 deletions seahub/api2/endpoints/file_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion seahub/api2/endpoints/file_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions seahub/api2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/api/endpoints/test_user_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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

0 comments on commit e46bf3e

Please sign in to comment.