Files
mtgonline/backend/BACKEND_TESTING_SUMMARY.md
T
akadmin 915242b330 feat: MTG database integration with Redis caching
- 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.
2026-07-18 18:41:05 +00:00

116 lines
3.3 KiB
Markdown

# 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_admin`
- `test_list_users_non_admin`
- `test_create_ban`
- `test_list_bans`
- `test_unban_user`
- **Authentication Tests**: 7/7 passing
- `test_login_success`
- `test_login_invalid_password`
- `test_login_nonexistent_user`
- `test_register_success`
- `test_register_duplicate_username`
- `test_get_current_user`
- `test_refresh_token`
- **Deck Management Tests**: 8/8 passing
- `test_create_deck`
- `test_list_decks`
- `test_get_deck`
- `test_update_deck`
- `test_delete_deck`
- `test_create_folder`
- `test_list_folders`
- `test_delete_folder`
## Key Changes Made
### 1. JWT Token Updates (`app/core/security.py`)
- Added `privlevel` field to JWT access tokens
- Updated `get_current_user()` to extract `privlevel` from token
- Updated `create_access_token()` to accept `privlevel` parameter
### 2. Test Fixtures (`tests/conftest.py`)
- Fixed `client` fixture to share database session with test fixtures
- Used `hash_password()` for proper bcrypt password hashing
- Updated fixture scope from `session` to `function` for isolation
- Properly cleaned up dependency overrides
### 3. Router Fixes (`app/routers/decks.py`)
- Reordered routes to prevent `/folders` from matching `/{deck_id}`
- Routes now checked in correct order: specific routes first, then parameterized
### 4. Database Model Updates (`app/models/models.py`)
- Made `folder_id` in `DecklistFile` nullable (optional at creation)
### 5. Schema Updates (`app/schemas/schemas.py`)
- Removed relationship fields from `FolderResponse` to 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
1. ✅ Backend test suite complete
2. ⏳ Frontend development (Next.js)
3. ⏳ API integration testing
4. ⏳ Deployment setup
## Files Modified
- `app/core/security.py`
- `app/models/models.py`
- `app/routers/auth.py`
- `app/routers/decks.py`
- `app/schemas/schemas.py`
- `tests/conftest.py`
- `tests/test_admin.py`
- `tests/test_auth.py`
- `tests/test_decks.py`
## Commands
```bash
# 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
```