- Added MTG card ORM models (mtg_cards, mtg_sets tables) - Created card_database service with search, get_by_name, get_by_set - Added Redis client with caching layer (3600s TTL default) - Created card router with caching on all endpoints: - Search cards (5min cache) - Get card by name (10min cache) - Get cards by set (15min cache) - Get card types/rarities (30min cache) - Get sets (1hr cache) - Get statistics (1hr cache) - Updated settings.py: - Added JWT_SECRET_KEY field - Added DB_CONFIG and REDIS_CONFIG dictionaries - Updated security.py to use JWT_SECRET_KEY with fallback - Updated auth.py to use timezone-aware datetimes - Updated refresh_mtg.py to use settings instead of os.environ - Updated mtg_monitor.py to use settings for connections - Added services package with __init__.py All 20 tests passing.
3.3 KiB
3.3 KiB
Backend Testing Summary
Overview
Successfully fixed and completed the backend test suite for the mtgonline project. All 20 tests are now passing.
Test Results
======================= 20 passed, 57 warnings in 5.20s ========================
Test Breakdown
-
Admin Tests: 5/5 passing
test_list_users_admintest_list_users_non_admintest_create_bantest_list_banstest_unban_user
-
Authentication Tests: 7/7 passing
test_login_successtest_login_invalid_passwordtest_login_nonexistent_usertest_register_successtest_register_duplicate_usernametest_get_current_usertest_refresh_token
-
Deck Management Tests: 8/8 passing
test_create_decktest_list_deckstest_get_decktest_update_decktest_delete_decktest_create_foldertest_list_folderstest_delete_folder
Key Changes Made
1. JWT Token Updates (app/core/security.py)
- Added
privlevelfield to JWT access tokens - Updated
get_current_user()to extractprivlevelfrom token - Updated
create_access_token()to acceptprivlevelparameter
2. Test Fixtures (tests/conftest.py)
- Fixed
clientfixture to share database session with test fixtures - Used
hash_password()for proper bcrypt password hashing - Updated fixture scope from
sessiontofunctionfor isolation - Properly cleaned up dependency overrides
3. Router Fixes (app/routers/decks.py)
- Reordered routes to prevent
/foldersfrom matching/{deck_id} - Routes now checked in correct order: specific routes first, then parameterized
4. Database Model Updates (app/models/models.py)
- Made
folder_idinDecklistFilenullable (optional at creation)
5. Schema Updates (app/schemas/schemas.py)
- Removed relationship fields from
FolderResponseto avoid async context issues - Simplified schema to only include direct fields
Architecture Notes
Authentication Flow
Login → JWT Token (includes privlevel) → Authorization checks
Test Database Setup
- Uses in-memory SQLite (
sqlite+aiosqlite:///:memory:) - Each test function gets isolated database state
- Shared session via dependency override
Security Features Tested
- Password hashing with bcrypt
- JWT token validation
- Admin privilege checks (privlevel-based authorization)
- Duplicate username/email prevention
- Token refresh mechanism
Repository Information
- Repository:
https://git.optimex.systems/admin/mtgonline.git - Branch:
main - Latest Commit:
167a352 - Status: Backend test suite complete and ready for frontend development
Next Steps
- ✅ Backend test suite complete
- ⏳ Frontend development (Next.js)
- ⏳ API integration testing
- ⏳ Deployment setup
Files Modified
app/core/security.pyapp/models/models.pyapp/routers/auth.pyapp/routers/decks.pyapp/schemas/schemas.pytests/conftest.pytests/test_admin.pytests/test_auth.pytests/test_decks.py
Commands
# Run all tests
cd /home/wall-o/projects/mtgonline/backend
/home/wall-o/workspace/venv/bin/python -m pytest tests/ -v
# Run specific test file
/home/wall-o/workspace/venv/bin/python -m pytest tests/test_auth.py -v
# Run with verbose output
/home/wall-o/workspace/venv/bin/python -m pytest tests/ -v --tb=short