aboutsummaryrefslogtreecommitdiff
path: root/tests/http/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/http/conftest.py')
-rw-r--r--tests/http/conftest.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/http/conftest.py b/tests/http/conftest.py
index 200bf1c..4f11fde 100644
--- a/tests/http/conftest.py
+++ b/tests/http/conftest.py
@@ -1,10 +1,19 @@
import httpx
+import redis
import pytest
import requests_mock
from asgi_lifespan import LifespanManager
from httpx import AsyncClient, ASGITransport
+from typing import Dict, Any
from jb.main import app
+import json
+
+from httpx import AsyncClient
+import secrets
+
+from jb.config import JB_EVENTS_STREAM, settings
+from tests import generate_amt_id
@pytest.fixture(scope="session")
@@ -48,3 +57,43 @@ def httpxclient_ip(httpxclient):
def mock_requests():
with requests_mock.Mocker() as m:
yield m
+
+
+def generate_hex_id(length: int = 40) -> str:
+ # length is number of hex chars, so we need length//2 bytes
+ return secrets.token_hex(length // 2)
+
+
+@pytest.fixture
+def mturk_event_body_record(
+ hit_record: Hit, assignment_stub_record: AssignmentStub
+) -> Dict[str, Any]:
+ return {
+ "Type": "Notification",
+ "Message": json.dumps(
+ {
+ "Events": [
+ {
+ "EventType": "AssignmentSubmitted",
+ "EventTimestamp": "2025-10-16T18:45:51.000000Z",
+ "HITId": hit_record.amt_hit_id,
+ "AssignmentId": assignment_stub_record.amt_assignment_id,
+ "HITTypeId": hit_record.amt_hit_type_id,
+ }
+ ],
+ "EventDocId": generate_hex_id(),
+ "SourceAccount": settings.aws_owner_id,
+ "CustomerId": generate_amt_id(length=14),
+ "EventDocVersion": "2006-05-05",
+ }
+ ),
+ }
+
+
+@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
+ yield
+ redis.xtrim(JB_EVENTS_STREAM, maxlen=0)
+ assert redis.xlen(JB_EVENTS_STREAM) == 0