Conversation
|
Hi Carrie, thank you for your message. I am looking into the issue that you brought up, and will look into it now. Thanks! |
…ines in my views.py file. this resolves issue #1283
…me into testing_analytics_page
carriesunluo05
left a comment
There was a problem hiding this comment.
Hey Umer, was able to run the tests and also saw a tournament that ended that had the information about a match:

However, there are a few small points that needs to be changed before I approve:
- in models.py, remove ====== in line 910 (with this i wont be able to run migrations)
- This could be a problem from my side but if you have a migration file called 0003_alter_livechat..., remove it. If you don't have this problem, ignore this
- in tests.py, remove ====== in line 356
- in tournament_detail, add an {% endif %} before the last line such that it looks smth like this:
{% endif %}
{% endif %}
{% endblock content %}
for the buttons to work. you might have forgotten to close an if block somewhere above.
carriesunluo05
left a comment
There was a problem hiding this comment.
LGTM! Just checked that you fixed the few problems I caught and it seems to work.
| # If the user is authenticated but not staff, show only tournaments they are part of | ||
| if self.request.user.is_authenticated: | ||
| return Tournament.objects.prefetch_related("matches").filter(players=self.request.user) | ||
|
|
There was a problem hiding this comment.
@umerp why is the above code added twice? Is this a merge error?
|
|
||
|
|
||
| # =============== Word Game Views =============== | ||
|
|
There was a problem hiding this comment.
why did you deleted and added back MatchStatsView?
|
|
||
| # =============== Word Game Views =============== | ||
|
|
||
|
|
There was a problem hiding this comment.
In fact,can you explain why do we change the views.py file? I think all the changes here are not coupled with the tests
|
@umerp we are also seeing a lot of merge related duplicated code addition. Please resolve them as they will likely affect the result of CI as well |
Please merge 1082 first then 1275 then this one.
Summary
Create a comprehensive test file to verify backend match timing behavior and the tournament analytics view. These tests ensure accurate tracking of match start/end times and correct rendering of statistics on the frontend.
Tests that were written.
Unit tests for match timing behavior (MatchTimingTests):
• test_match_timing_on_status_change:
Ensures start_time, end_time, and duration are set correctly as the lobby status transitions from Viewable to Finished.
• test_match_timing_via_api:
Confirms that calling the update_match_status API endpoint updates timing fields appropriately.
• test_match_timing_in_game_flow:
Simulates actual player moves during a match and ensures timing is updated correctly through the game flow.
• test_fastest_match:
Validates that the system correctly identifies the match with the shortest duration.
• test_slowest_match:
Validates that the system correctly identifies the match with the longest duration.
Tests for analytics view (MatchStatsViewTests):
• test_fastest_match:
Ensures the fastest match is shown correctly on the analytics page.
• test_slowest_match:
Ensures the slowest match is shown correctly on the analytics page.
• test_match_stats_view:
Verifies correct context is passed to the template, including tournament data, fastest/slowest matches, and the list of matches.
• test_match_stats_view_ongoing_tournament:
Confirms the user is redirected if the tournament is ongoing and analytics should not be available yet.
• test_match_stats_view_no_matches:
Ensures that the view renders without error when no matches are present and that it correctly shows None for fastest/slowest matches.
⸻
How should this be manually tested?
1. Create a new tournament and play a match. Navigate to a tournament that has ended.
2. Visit the /tournament//stats/ route.
3. Confirm that:
• Fastest and slowest matches are displayed correctly
• Match durations and timestamps are accurate
• The page handles edge cases (e.g., no matches) gracefully
4. Create a tournament that is still ongoing and visit its stats page — you should be redirected
Running the test file:
1. Run the test.py file and make sure that everything passes. You should see and OK if everything has passed.
This resolves #1283