import pytest from django.utils import timezone from accounts.models import User from contest.models import Contest, Question, RatingHistory, RealtimeMatch @pytest.mark.django_db def test_profile_返回实时比赛历史及_rating_变化(client): user = User.objects.create_user( username="profile_player", password="StrongPass_2026", nickname="档案玩家", rating=1016, ) opponent = User.objects.create_user( username="profile_opponent", password="StrongPass_2026", nickname="对局对手", rating=984, ) contest = Contest.objects.create( slug="profile-realtime", title="档案实时赛", kind=Contest.Kind.REALTIME, track=Question.Track.STANDARD, status=Contest.Status.PUBLISHED, ) match = RealtimeMatch.objects.create( contest=contest, player_one=user, player_two=opponent, player_one_rating=1000, player_two_rating=1000, winner=user, status=RealtimeMatch.Status.COMPLETED, completed_at=timezone.now(), ) RatingHistory.objects.create( user=user, match=match, rating_before=1000, rating_after=1016, delta=16, ) client.force_login(user) response = client.get("/api/v1/progression/me/") assert response.status_code == 200 history = response.json()["recent_matches"] assert len(history) == 1 assert history[0]["match_id"] == str(match.id) assert history[0]["contest"] == "档案实时赛" assert history[0]["opponent"] == "对局对手" assert history[0]["result"] == "win" assert history[0]["rating_delta"] == 16 assert history[0]["rating_after"] == 1016 assert history[0]["completed_at"]