[games] Revamp user game upload backend functionality with comprehensive tests#1537
Open
[games] Revamp user game upload backend functionality with comprehensive tests#1537
Conversation
Previous implimentation of user game upload hardcoded various variables and did not account for new additions such as embedded games. Revamped that functionality, and added a command file to test this.
This was
linked to
issues
May 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enhances the existing UploadFileView to provide a robust user game upload system that supports both embedded games and Twine file uploads with proper validation, improved UX, and comprehensive test coverage. The current system had hardcoded values, no form validation, and limited functionality - this update transforms it into a comprehensive upload solution with full test coverage. What is added in this PR specifically is:
Enhanced UploadFileView with GET method to display upload forms and dual POST handling for embedded/Twine games
Added proper form validation for required fields, file extensions, and input types with clear error messaging
Added user attribution system that automatically adds uploaders to game users and tracks ownership
Added a management command test_user_uploads to create sample Twine games for testing functionality
Added new URL route /games/upload/ for dedicated upload access while maintaining backward compatibility
Added comprehensive test suite covering authentication, validation, success scenarios, and error handling
Added edge case testing for file uploads, numeric validation, and proper cleanup of test artifacts
To easily test this PR:
First, run the command python manage.py test_user_uploads. This will create test Twine games and a test user account. Then, visit /games/upload/ while logged in to test the upload form, or visit the direct game URLs provided by the command output to see the uploaded Twine games in action. To run the automated tests, use python manage.py test chigame.games.tests.test_user_uploads -v 2 to see detailed test results.
The files changed in this PR are mainly views.py for the enhanced upload logic, urls.py for the new route, the new management command test_user_uploads.py for generating test data, and the comprehensive test suite test_user_uploads.py that ensures reliability across all upload scenarios.