diff options
| author | Max Nanis | 2026-09-13 19:03:55 +0000 |
|---|---|---|
| committer | Max Nanis | 2026-09-13 19:03:55 +0000 |
| commit | 8fbe8d439b418796932aaa88297e006c714e4d13 (patch) | |
| tree | 6c800476edc1e771fc570b559d483df8d59d4324 /tests/fixtures/http.py | |
| parent | 12f6fee851b68e86af658dfa17e4a0daed457dd1 (diff) | |
| parent | 2c94f248d2438071a918fa9a30bf114ef9aa29b4 (diff) | |
| download | amt-jb-8fbe8d439b418796932aaa88297e006c714e4d13.tar.gz amt-jb-8fbe8d439b418796932aaa88297e006c714e4d13.zip | |
Merges pull request #3
Off of Amazon!!!
Diffstat (limited to 'tests/fixtures/http.py')
| -rw-r--r-- | tests/fixtures/http.py | 39 |
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 |
