refactor: move process_random_number_job import to module level in tests
This commit is contained in:
parent
89fbdb37bd
commit
6f3e729b25
1 changed files with 2 additions and 16 deletions
|
|
@ -6,6 +6,8 @@ from unittest.mock import AsyncMock, MagicMock
|
|||
|
||||
import pytest
|
||||
|
||||
from worker import process_random_number_job
|
||||
|
||||
|
||||
def create_mock_pool(mock_conn: AsyncMock) -> MagicMock:
|
||||
"""Create a mock asyncpg pool with proper async context manager behavior."""
|
||||
|
|
@ -25,8 +27,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_generates_random_number_in_range(self):
|
||||
"""Verify random number is in range [0, 100]."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
# Create mock job
|
||||
job = MagicMock()
|
||||
job.id = 123
|
||||
|
|
@ -52,8 +52,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_stores_correct_user_id(self):
|
||||
"""Verify the correct user_id is stored in the outcome."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
user_id = 42
|
||||
|
||||
job = MagicMock()
|
||||
|
|
@ -75,8 +73,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_stores_job_id(self):
|
||||
"""Verify the job_id is stored in the outcome."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
job_id = 456
|
||||
|
||||
job = MagicMock()
|
||||
|
|
@ -98,8 +94,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_stores_status_completed(self):
|
||||
"""Verify the status is set to 'completed'."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
job = MagicMock()
|
||||
job.id = 123
|
||||
job.payload = json.dumps({"user_id": 1}).encode()
|
||||
|
|
@ -119,8 +113,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_records_duration_ms(self):
|
||||
"""Verify duration_ms is recorded (should be >= 0)."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
job = MagicMock()
|
||||
job.id = 123
|
||||
job.payload = json.dumps({"user_id": 1}).encode()
|
||||
|
|
@ -141,8 +133,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_missing_user_id_does_not_insert(self):
|
||||
"""Verify no insert happens if user_id is missing from payload."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
job = MagicMock()
|
||||
job.id = 123
|
||||
job.payload = json.dumps({}).encode() # Missing user_id
|
||||
|
|
@ -158,8 +148,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_empty_payload_does_not_insert(self):
|
||||
"""Verify no insert happens with empty payload."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
job = MagicMock()
|
||||
job.id = 123
|
||||
job.payload = None
|
||||
|
|
@ -175,8 +163,6 @@ class TestRandomNumberJobHandler:
|
|||
@pytest.mark.asyncio
|
||||
async def test_malformed_json_payload_does_not_insert(self):
|
||||
"""Verify no insert happens with malformed JSON payload."""
|
||||
from worker import process_random_number_job
|
||||
|
||||
job = MagicMock()
|
||||
job.id = 123
|
||||
job.payload = b"not valid json {"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue