Skip to content

Commit c293cbb

Browse files
author
Arendelle
committed
add more tests of webutils.py
1 parent cb39369 commit c293cbb

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

physicsLab/web/webutils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,19 @@ class AvatarsIter(_async_tool.AsyncTool):
357357
''' 获取头像的迭代器 '''
358358
def __init__(
359359
self,
360-
search_id: str,
360+
user_id: str,
361361
category: str,
362362
user: Optional[api.User] = None,
363363
size_category: str = "full",
364364
max_retry: Optional[int] = 0,
365365
) -> None:
366-
''' @param search_id: 用户id
366+
''' @param user_id: 用户id
367367
@param category: 只能为 "Experiment" 或 "Discussion" 或 "User"
368368
@param size_category: 只能为 "small.round" 或 "thumbnail" 或 "full"
369369
@param user: 查询者, None为匿名用户
370370
@param max_retry: 最大重试次数(大于等于0), 为None时不限制重试次数
371371
'''
372-
if not isinstance(search_id, str) or \
372+
if not isinstance(user_id, str) or \
373373
not isinstance(category, str) or \
374374
not isinstance(size_category, str) or \
375375
not isinstance(user, (api.User, type(None))) or \
@@ -383,18 +383,18 @@ def __init__(
383383
user = api.User()
384384

385385
if category == "User":
386-
self.max_img_counter = user.get_user(search_id)["Data"]["User"]["Avatar"]
386+
self.max_img_counter = user.get_user(user_id)["Data"]["User"]["Avatar"]
387387
category = "users"
388388
elif category == "Experiment":
389-
self.max_img_counter = user.get_summary(search_id, Category.Experiment)["Data"]["Image"]
389+
self.max_img_counter = user.get_summary(user_id, Category.Experiment)["Data"]["Image"]
390390
category = "experiments"
391391
elif category == "Discussion":
392-
self.max_img_counter = user.get_summary(search_id, Category.Discussion)["Data"]["Image"]
392+
self.max_img_counter = user.get_summary(user_id, Category.Discussion)["Data"]["Image"]
393393
category = "experiments"
394394
else:
395395
assert False
396396

397-
self.search_id = search_id
397+
self.search_id = user_id
398398
self.category = category
399399
self.size_category = size_category
400400
self.user = user

test_pl/test_pl_web.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import inspect
3-
import asyncio
4-
import time
52
from datetime import datetime
63
from .base import *
74

@@ -74,3 +71,24 @@ async def test_banned_msg_iter(self):
7471
):
7572
counter += 1
7673
self.assertEqual(counter, 1)
74+
75+
async def test_comments_iter(self):
76+
for _ in web.CommentsIter(user=user, id="677d5c6c826568de4e9896c5", category="Discussion"):
77+
pass
78+
79+
# temp user can't get comments on user's profile
80+
# async def test_warned_msg_iter(self):
81+
# counter = 0
82+
# for _ in web.WarnedMsgIter(user=user, user_id="63e76ce5fd0015cb932e8b05", start_time=1731155184, end_time=1731155185):
83+
# counter += 1
84+
# self.assertEqual(counter, 1)
85+
86+
async def test_relations_iter(self):
87+
for _ in web.RelationsIter(user=user, user_id="62d3fd092f3a2a60cc8ccc9e", display_type="Following", max_retry=4):
88+
pass
89+
90+
async def test_avatars_iter(self):
91+
for _ in web.AvatarsIter(
92+
user_id="5ce629e157035932b52f9315", category="User", user=user, size_category="small.round", max_retry=4
93+
):
94+
pass

0 commit comments

Comments
 (0)