Skip to content

Conversation

@umerp
Copy link
Contributor

@umerp umerp commented May 21, 2025

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

@umerp
Copy link
Contributor Author

umerp commented May 23, 2025

Hi Carrie, thank you for your message. I am looking into the issue that you brought up, and will look into it now. Thanks!

Copy link
Contributor

@carriesunluo05 carriesunluo05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Umer, was able to run the tests and also saw a tournament that ended that had the information about a match:
Screenshot 2025-05-23 at 1 55 18 PM
However, there are a few small points that needs to be changed before I approve:

  1. in models.py, remove ====== in line 910 (with this i wont be able to run migrations)
  2. 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
  3. in tests.py, remove ====== in line 356
  4. 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 carriesunluo05 self-requested a review May 23, 2025 19:06
Copy link
Contributor

@carriesunluo05 carriesunluo05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just checked that you fixed the few problems I caught and it seems to work.

Copy link
Contributor

@MuyanXie MuyanXie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments below

# 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@umerp why is the above code added twice? Is this a merge error?



# =============== Word Game Views ===============

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you deleted and added back MatchStatsView?


# =============== Word Game Views ===============


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@MuyanXie
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request x/tournaments

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Tournament] Testing file for new analytics page

5 participants