Phase 2: Job enqueueing from counter
- Add backend/jobs.py with enqueue_random_number_job function - Modify counter increment endpoint to enqueue job after incrementing - Add mock_enqueue_job fixture to conftest.py for all tests - Add test_increment_enqueues_job_with_user_id to verify correct user_id - Job is enqueued synchronously; failure causes request to fail
This commit is contained in:
parent
10c0316603
commit
6ca0ae88dd
4 changed files with 98 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
# Set required env vars before importing app
|
||||
os.environ.setdefault("SECRET_KEY", "test-secret-key-for-testing-only")
|
||||
|
|
@ -238,3 +239,16 @@ async def user_no_roles(client_factory):
|
|||
"cookies": dict(response.cookies),
|
||||
"response": response,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_enqueue_job():
|
||||
"""Mock job enqueueing for all tests.
|
||||
|
||||
pgqueuer requires PostgreSQL-specific features that aren't available
|
||||
in the test database setup. We mock the enqueue function to avoid
|
||||
connection issues while still testing the counter logic.
|
||||
"""
|
||||
mock = AsyncMock(return_value=1) # Return a fake job ID
|
||||
with patch("routes.counter.enqueue_random_number_job", mock):
|
||||
yield mock
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue