-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor tests to use helper fixtures, eliminating 195 lines of boilerplate #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Add tests for user_handler functions (password verification, user retrieval, deletion, team membership) - Add tests for team_handler functions (team retrieval by ID/name, deletion) - Add tests for table_handler functions (table creation/deletion, cell operations, permissions) Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Remove duplicate pytest marker - Fix UUID conversion logic to use UUID() constructor instead of uuid4() Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Fix error message pattern to include 'in schema' - Fix delete_table to use actual project_id instead of random UUID Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Ensure all tests use consistent marker order: data_db first, asyncio second - Matches existing test pattern in test_projects.py Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
|
@copilot You may also create new test markers or new testfiles. Make it a priority that tests are easy to understand and if failed the reason is easy to find. You may also edit my tests if there is a need for that. |
- Add helper fixtures to conftest.py for common test setup - Add descriptive assertion messages to all tests for easier debugging - Split large test_table_handler.py into focused files: * test_table_operations.py for table/cell operations * test_table_permissions.py for permission management - Add new pytest markers (table_operations, table_permissions) - Add comprehensive tests/README.md documenting test organization Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
I've improved the test organization and clarity in commit d785bee: Test Organization:
Improved Clarity:
Easier Failure Diagnosis:
You can now run focused test groups: |
| async def test_valid_password_with_username(user_db_transaction): | ||
| """Test password validation with username.""" | ||
| # Create a test user | ||
| user_id = await create_user( |
| async def test_valid_password_with_email(user_db_transaction): | ||
| """Test password validation with email.""" | ||
| # Create a test user | ||
| user_id = await create_user( |
|
@copilot Are the tests still in a way the db is reset after? |
Yes, the database is still reset after each test. All tests use the This includes:
Each test runs in complete isolation with a clean database state. |
|
@copilot I see you are using much "str(project_id)". It seems i didn't change all the functions to use UUIDs as parameters. Please take care of this. |
- Update table_handler.py functions to accept UUID directly instead of string * create_table now takes project_id: UUID * set_cell_value now takes project_id: UUID * get_cell_value now takes project_id: UUID - Remove str(project_id) calls from all test files - Add comprehensive web route tests (test_web_routes.py) * Index/homepage tests * Login/logout functionality * Dashboard access control * Error page tests (403, 404, 500) * Static file serving * Middleware and headers - Add @pytest.mark.web marker for web tests - Update tests/README.md with web test documentation Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
Fixed in commit d3deb5f: UUID Handling:
Web Tests:
Total test count increased from 36 to 51 tests. |
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
- Update test_table_operations.py to use test_project and test_table fixtures - Reduces code duplication by ~20 lines per test - Makes tests more concise and focused on what they're testing - Update test_table_permissions.py to use test_user and test_project fixtures - Still creates second user manually since tests need two distinct users - Eliminates repetitive project creation code Benefits: - Tests are now ~50% shorter and easier to read - Reduced boilerplate setup code - Better maintainability - fixture changes propagate automatically - Consistent test data across tests using fixtures Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Add section on when to use fixtures vs manual creation - Include example showing fixture usage - Document the helper fixtures with their dependencies - Provide clear guidance for test writers This completes the refactoring to use helper fixtures consistently. Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
Tests in
test_table_operations.pyandtest_table_permissions.pywere duplicating user/project/table creation logic instead of using thetest_user,test_project, andtest_tablefixtures fromconftest.py.Changes
test_projectandtest_tablefixtures (280→161 lines, -42%)test_userandtest_projectfixtures (263→187 lines, -29%)Example
Before:
After:
Not Changed
test_user_handler.pyandtest_team_handler.pycontinue manual creation - they validate creation functions and require specific user properties per test.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.