Commit 1e440c3
committed
Fix Piccolo ORM configuration and enable test suite
This commit fixes critical issues with Piccolo ORM configuration, achieving
44 passing tests out of 133 total (33% pass rate).
Piccolo ORM Fixes:
1. ForeignKey References with LazyTableReference:
- Problem: String references like ForeignKey("Project") couldn't find tables
- Solution: Use LazyTableReference with explicit module paths
- Example: ForeignKey(LazyTableReference("Project", module_path="imbi.models.project"))
- Applied to all models with ForeignKeys:
* Project: namespace_id, project_type_id
* ProjectDependency: project_id, dependency_id
* ProjectLink: project_id, link_type_id
* ProjectURL: project_id
* ProjectFact: project_id, fact_type_id
* ProjectNote: project_id
* OperationsLog: project_id
2. Primary Key Conflicts:
- ProjectNote had duplicate primary keys (auto 'id' + explicit 'note_id')
- Fixed: Removed note_id, use Piccolo's auto-generated id field
- Updated ProjectNoteResponse schema: note_id → id
- Updated router: All .note_id references → .id
- Tests updated: Check for 'id' not 'note_id'
3. Base Table Classes:
- Removed unsupported abstract=True parameter
- Piccolo doesn't use abstract keyword
- Tables properly inherit from base classes
4. Database Engine Configuration:
- Pool size must be in config dict: {"min_size": X, "max_size": Y}
- Not as engine parameters: PostgresEngine(min_size=X)
- Removed broken connection test (execute() method doesn't exist)
- Connection validated on first query
5. Table Engine Assignment (conftest.py):
- Piccolo needs DB engine set on table._meta.db
- Added: for table in tables: table._meta.db = db_engine
- Required for create_db_tables() to work
Valkey/Redis Compatibility:
1. URL Scheme Conversion:
- redis-py doesn't recognize valkey:// scheme
- Added: url.replace("valkey://", "redis://")
- Applied in api/app.py lifespan and tests/conftest.py
- Valkey is protocol-compatible with Redis
2. Test Configuration Ports:
- PostgreSQL: Port 5433 (Docker test instance)
- Valkey: Port 6380 (Docker test instance)
- Database 15 for test isolation
3. Valkey Cleanup:
- Use aclose() instead of deprecated close()
- Proper async cleanup in test fixtures
Import Style Corrections:
1. utils/session.py:
- import fastapi (not from fastapi import Request)
- from redis import asyncio as aioredis (submodule pattern)
- Usage: fastapi.Request, aioredis.Redis
2. Circular Import Fix:
- Models: from imbi.models import base (not import imbi.models.base)
- Prevents circular imports during module loading
3. Ruff Configuration:
- Added TC002 ignore for utils/session.py
- Justification: Need fastapi/aioredis at runtime for dependency injection
Dependencies:
1. pyproject.toml Updates:
- Added: itsdangerous>=2.1.0 (required by SessionMiddleware)
- Fixed: python-ulid>=2.7.0,<4 (was >=2.8.0,<3)
- Disabled: fastapi-cache2 (conflicts with redis>=5)
2. piccolo_conf.py Created:
- Required by Piccolo ORM for table discovery
- Exports DB engine instance
- Defines APP_REGISTRY for migrations
Test Infrastructure:
1. App Fixture Enhancement:
- Manually initializes Valkey (lifespan doesn't run in ASGI tests)
- Sets app.state.session_valkey and stats_valkey
- Proper cleanup with aclose()
2. Test Config:
- Cookie name: "test_session" (not "session")
- Test updated to check correct cookie name
Test Results: ✅ 44 PASSED, ❌ 75 FAILED, ⏭️ 14 SKIPPED (133 total)
Passing Categories:
- ✅ Health endpoints: 2/2 (100%)
- ✅ Authentication: 7/11 (64%)
- ✅ Various CRUD operations
- ✅ Database operations working
- ✅ Piccolo ORM functional
Common Failure Patterns:
- Session persistence (authenticated_client fixture needs work)
- Error response format (some tests expect different structure)
- Schema references (note_id → id needs completion)
Infrastructure Status: 100% Working
- ✅ PostgreSQL connection
- ✅ Valkey connection
- ✅ FastAPI app creation
- ✅ Piccolo ORM queries
- ✅ Test database setup/teardown
- ✅ Pre-commit hooks passing
Next Steps:
- Fix session persistence in authenticated_client fixture
- Complete note_id → id schema updates
- Fix error response format consistency
- Should reach 100+ passing tests
🤖 Generated with Claude Code1 parent dfd7f27 commit 1e440c3
20 files changed
Lines changed: 171 additions & 93 deletions
File tree
- src/imbi
- api
- models
- routers
- schemas
- utils
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| 181 | + | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
61 | 65 | | |
62 | | - | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
69 | 73 | | |
70 | | - | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
100 | | - | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | | - | |
64 | | - | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 68 | + | |
| 69 | + | |
75 | 70 | | |
76 | 71 | | |
77 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | | - | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
23 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | | - | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
0 commit comments