Improve coverage

This commit is contained in:
2026-02-20 06:02:57 +00:00
committed by Anibal Angulo
parent 94226ba913
commit 6edbca98bd
28 changed files with 2719 additions and 387 deletions

View File

@@ -8,7 +8,8 @@ This directory contains the test suite for the capa-de-integracion application.
- **pytest-asyncio** - Async test support
- **pytest-cov** - Coverage reporting
- **pytest-env** - Environment variable configuration (cleaner than manual setup)
- **pytest-recording** - HTTP recording (configured but not used for gRPC Firestore)
- **pytest-recording** - HTTP recording (configured but not used for gRPC Firestore or Redis)
- **fakeredis** - In-memory Redis mock for testing without a container
- **inline-snapshot** - Snapshot testing support
## Running Tests
@@ -27,6 +28,18 @@ uv run pytest --cov=capa_de_integracion
uv run pytest -v
```
## Redis Service Tests
The Redis service tests use **fakeredis**, an in-memory implementation of Redis that doesn't require a running Redis container.
**Benefits:**
- ✅ No external dependencies - tests run anywhere
- ✅ Fast execution - all operations are in-memory
- ✅ Automatic cleanup - each test gets a fresh Redis instance
- ✅ Full Redis protocol support - tests verify real behavior
The `redis_service` and `clean_redis` fixtures automatically use fakeredis, so tests work identically to production code but without needing a container.
## Firestore Service Tests
The Firestore service tests require the Firestore emulator to be running.
@@ -59,19 +72,21 @@ The Firestore service tests require the Firestore emulator to be running.
#### Why No pytest-recording Cassettes?
While pytest-recording is configured in the project, **cassettes are not generated** for Firestore tests. This is because:
While pytest-recording is configured in the project, **cassettes are not generated** for Firestore or Redis tests. This is because:
- **Firestore uses gRPC protocol**, not HTTP
- **Redis uses RESP (Redis Serialization Protocol)**, not HTTP
- **pytest-recording/vcrpy only supports HTTP** requests
- The Firestore Python client communicates via gRPC, which cannot be recorded by vcrpy
**Solution**: Tests run directly against the Firestore emulator. This provides:
- ✅ Real integration testing with actual Firestore behavior
- ✅ No mocking - tests verify actual data operations
- ✅ Fast execution (emulator is local)
- ❌ Requires emulator to be running
**Solutions:**
- **Redis**: Uses **fakeredis** - an in-memory Redis implementation that provides full Redis functionality without requiring a container or cassettes
- **Firestore**: Tests run directly against the Firestore emulator, providing:
- ✅ Real integration testing with actual Firestore behavior
- ✅ No mocking - tests verify actual data operations
- ✅ Fast execution (emulator is local)
- ❌ Requires emulator to be running
If you need offline/recorded tests, consider:
If you need offline/recorded Firestore tests, consider:
1. Using the emulator's export/import feature for test data
2. Implementing a mock FirestoreService for unit tests
3. Using snapshot testing with inline-snapshot for assertions
@@ -97,13 +112,15 @@ env =
GCP_LOCATION=us-central1
GCP_FIRESTORE_DATABASE_ID=(default)
RAG_ENDPOINT_URL=http://localhost:8000/rag
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_HOST=localhost # Not used - tests use fakeredis
REDIS_PORT=6379 # Not used - tests use fakeredis
DLP_TEMPLATE_COMPLETE_FLOW=projects/test/dlpJobTriggers/test
```
These are automatically loaded before any test runs, ensuring consistent test environment setup.
**Note:** Redis tests use **fakeredis** instead of connecting to the configured REDIS_HOST/REDIS_PORT, so no Redis container is needed.
## Fixtures
### `emulator_settings`