fix: run activity import enforcement tests without pytest-asyncio
CI container only installs pytest; use asyncio.run() for async route handlers. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ae7d0ac1d9
commit
72d101415f
|
|
@ -1,5 +1,6 @@
|
||||||
"""Feature-Enforcement für Legacy Activity CSV-Import (#37)."""
|
"""Feature-Enforcement für Legacy Activity CSV-Import (#37)."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -8,8 +9,7 @@ from fastapi import HTTPException
|
||||||
from routers.activity import import_activity_csv
|
from routers.activity import import_activity_csv
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
def test_import_activity_csv_blocks_when_limit_reached():
|
||||||
async def test_import_activity_csv_blocks_when_limit_reached():
|
|
||||||
upload = AsyncMock()
|
upload = AsyncMock()
|
||||||
upload.read = AsyncMock(return_value=b"Workout Type,Start\n")
|
upload.read = AsyncMock(return_value=b"Workout Type,Start\n")
|
||||||
|
|
||||||
|
|
@ -23,16 +23,17 @@ async def test_import_activity_csv_blocks_when_limit_reached():
|
||||||
},
|
},
|
||||||
), patch("routers.activity.log_feature_usage"):
|
), patch("routers.activity.log_feature_usage"):
|
||||||
with pytest.raises(HTTPException) as exc:
|
with pytest.raises(HTTPException) as exc:
|
||||||
await import_activity_csv(
|
asyncio.run(
|
||||||
file=upload,
|
import_activity_csv(
|
||||||
x_profile_id=None,
|
file=upload,
|
||||||
session={"profile_id": "profile-1"},
|
x_profile_id=None,
|
||||||
|
session={"profile_id": "profile-1"},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
assert exc.value.status_code == 403
|
assert exc.value.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
def test_import_activity_csv_increments_usage_per_insert(monkeypatch):
|
||||||
async def test_import_activity_csv_increments_usage_per_insert(monkeypatch):
|
|
||||||
upload = AsyncMock()
|
upload = AsyncMock()
|
||||||
upload.read = AsyncMock(
|
upload.read = AsyncMock(
|
||||||
return_value=(
|
return_value=(
|
||||||
|
|
@ -97,10 +98,12 @@ async def test_import_activity_csv_increments_usage_per_insert(monkeypatch):
|
||||||
lambda _pid, feature: increments.append(feature),
|
lambda _pid, feature: increments.append(feature),
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await import_activity_csv(
|
result = asyncio.run(
|
||||||
file=upload,
|
import_activity_csv(
|
||||||
x_profile_id=None,
|
file=upload,
|
||||||
session={"profile_id": "profile-1"},
|
x_profile_id=None,
|
||||||
|
session={"profile_id": "profile-1"},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["inserted"] == 1
|
assert result["inserted"] == 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user