chore(test): 为/api/v2/beatmaps/{beatmap_id}/scores/users/{user_id}端点添加测试
This commit is contained in:
31
test_api.py
31
test_api.py
@@ -124,6 +124,24 @@ def get_beatmap_scores(access_token: str, beatmap_id: int):
|
||||
return None
|
||||
|
||||
|
||||
def get_user_beatmap_score(access_token: str, beatmap_id: int, user_id: int):
|
||||
"""获取玩家成绩"""
|
||||
url = f"{API_URL}/api/v2/beatmaps/{beatmap_id}/scores/users/{user_id}"
|
||||
headers = {"Authorization": f"Bearer {access_token}"}
|
||||
try:
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
print(f"✅ 成功获取谱面 {beatmap_id} 中用户 {user_id} 的成绩数据")
|
||||
return response.json()
|
||||
else:
|
||||
print(f"❌ 获取谱面成绩失败: {response.status_code}")
|
||||
print(f"响应内容: {response.text}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"❌ 获取谱面成绩请求失败: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
"""主测试函数"""
|
||||
print("=== osu! API 模拟服务器测试 ===\n")
|
||||
@@ -180,8 +198,17 @@ def main():
|
||||
else:
|
||||
print("用户在该谱面没有成绩记录")
|
||||
|
||||
# 6. 测试令牌刷新
|
||||
print("\n6. 测试令牌刷新...")
|
||||
# 6. 测试谱面指定用户成绩
|
||||
user_score = get_user_beatmap_score(token_data["access_token"], 1, 1)
|
||||
if user_score:
|
||||
print(f"用户成绩ID:{user_score['score']['id']}")
|
||||
print(f"此成绩acc:{user_score['score']['accuracy']}")
|
||||
print(f"总分:{user_score['score']['classic_total_score']}")
|
||||
else:
|
||||
print("该用户在此谱面没有记录")
|
||||
|
||||
# 7. 测试令牌刷新
|
||||
print("\n7. 测试令牌刷新...")
|
||||
new_token_data = refresh_token(token_data["refresh_token"])
|
||||
if new_token_data:
|
||||
print(f"新访问令牌: {new_token_data['access_token']}")
|
||||
|
||||
Reference in New Issue
Block a user