diff options
| author | Max Nanis | 2026-02-25 16:20:18 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-25 16:20:18 -0500 |
| commit | 04aee0dc7e908ce020d2d2c3f8ffb4a96424b883 (patch) | |
| tree | efb99622da9a962a73921a945373c019f98e6273 /tests/http/conftest.py | |
| parent | 8c1940445503fd6678d0961600f2be81622793a2 (diff) | |
| download | amt-jb-04aee0dc7e908ce020d2d2c3f8ffb4a96424b883.tar.gz amt-jb-04aee0dc7e908ce020d2d2c3f8ffb4a96424b883.zip | |
test_notification (for sns mgmt), along with more type hinting on pytest conftest
Diffstat (limited to 'tests/http/conftest.py')
| -rw-r--r-- | tests/http/conftest.py | 49 |
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 |
