aboutsummaryrefslogtreecommitdiff
path: root/tests/fixtures/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fixtures/http.py')
-rw-r--r--tests/fixtures/http.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/tests/fixtures/http.py b/tests/fixtures/http.py
index 5f50580..e38c853 100644
--- a/tests/fixtures/http.py
+++ b/tests/fixtures/http.py
@@ -1,20 +1,20 @@
+import json
+import secrets
+from collections.abc import AsyncGenerator
+from typing import Any
+
import httpx
-import redis
import pytest
import requests_mock
from asgi_lifespan import LifespanManager
-from httpx import AsyncClient, ASGITransport
-from typing import Dict, Any, AsyncGenerator
+from generalresearch.redis_helper import RedisConfig
+from httpx import ASGITransport, AsyncClient
+from jb.config import JB_EVENTS_STREAM, settings
+from jb.decorators import get_redis_config
from jb.main import app
-import json
-
-from httpx import AsyncClient
-import secrets
-
-from jb.models.hit import Hit
from jb.models.assignment import AssignmentStub
-from jb.config import JB_EVENTS_STREAM, settings
+from jb.models.hit import Hit
from tests import generate_amt_id
@@ -24,7 +24,8 @@ def anyio_backend():
@pytest.fixture(scope="session")
-async def httpxclient() -> AsyncGenerator[AsyncClient, None]:
+async def httpxclient(redis_config: RedisConfig) -> AsyncGenerator[AsyncClient, None]:
+ app.dependency_overrides[get_redis_config] = lambda: redis_config
# limiter.enabled = True
# limiter.reset()
app.testing = True
@@ -38,6 +39,8 @@ async def httpxclient() -> AsyncGenerator[AsyncClient, None]:
yield client
await client.aclose()
+ app.dependency_overrides.clear()
+
@pytest.fixture()
def no_limit():
@@ -69,7 +72,7 @@ def generate_hex_id(length: int = 40) -> str:
@pytest.fixture
def mturk_event_body_record(
hit_record: Hit, assignment_stub_record: AssignmentStub
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
return {
"Type": "Notification",
"Message": json.dumps(
@@ -93,9 +96,11 @@ def mturk_event_body_record(
@pytest.fixture()
-def clean_mturk_events_redis_stream(redis: redis.Redis):
- redis.xtrim(JB_EVENTS_STREAM, maxlen=0)
- assert redis.xlen(JB_EVENTS_STREAM) == 0
+def clean_mturk_events_redis_stream(redis_config: RedisConfig):
+ redis_client = redis_config.create_redis_client()
+
+ redis_client.xtrim(JB_EVENTS_STREAM, maxlen=0)
+ assert redis_client.xlen(JB_EVENTS_STREAM) == 0
yield
- redis.xtrim(JB_EVENTS_STREAM, maxlen=0)
- assert redis.xlen(JB_EVENTS_STREAM) == 0
+ redis_client.xtrim(JB_EVENTS_STREAM, maxlen=0)
+ assert redis_client.xlen(JB_EVENTS_STREAM) == 0