aboutsummaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorMax Nanis2026-09-10 16:59:43 -0700
committerMax Nanis2026-09-10 16:59:43 -0700
commit0ac38066402762dc5fa24f2ffa2170681a6eddb1 (patch)
tree923ea3f9ccd7adaaac89d20074d7ed6af532260e /tests/conftest.py
parentcb098c80351727055ce982b9c2631aab7277b772 (diff)
downloadamt-jb-0ac38066402762dc5fa24f2ffa2170681a6eddb1.tar.gz
amt-jb-0ac38066402762dc5fa24f2ffa2170681a6eddb1.zip
http/managers/models green.
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py42
1 files changed, 35 insertions, 7 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index ca6661a..7a74fa0 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -6,17 +6,22 @@ import sys
from collections.abc import Callable, Generator
from datetime import UTC, datetime
from pathlib import Path
-from typing import TYPE_CHECKING
+from random import randint
+from typing import TYPE_CHECKING, Any
from uuid import uuid4
import pytest
+import redis
+from fastapi.testclient import TestClient
from generalresearch.models.custom_types import InternalHostname, PostgresDict
from generalresearch.pg_helper import PostgresConfig, PostgresDsn
+from generalresearch.redis_helper import RedisConfig
from mypy_boto3_mturk import MTurkClient
from pydantic import TypeAdapter
from pytest import TempPathFactory
-from jb.decorators import CLIENT_CONFIG
+from jb.decorators import CLIENT_CONFIG, get_redis_config
+from jb.main import app
from tests import generate_amt_id
if TYPE_CHECKING:
@@ -322,16 +327,39 @@ def pg_config(django_db_factory: Callable[..., PostgresDsn]) -> PostgresConfig:
@pytest.fixture(scope="session")
-def redis(settings: Settings):
- from generalresearch.redis_helper import RedisConfig
+def redis_config_db() -> str:
+ # need to update 'databases' in /etc/redis/redis.conf
+ # or this won't work and you'll have no indication why ...
+ return str(randint(99, 1_023))
- redis_config = RedisConfig(
- dsn=settings.testing_redis,
+
+@pytest.fixture(scope="session")
+def redis_config(settings: Settings, redis_config_db: str) -> Generator[RedisConfig]:
+ assert "unittest" in str(settings.testing_redis) or "127.0.0.1" in str(
+ settings.testing_redis
+ )
+
+ uri = f"redis://{settings.testing_redis}/{redis_config_db}"
+
+ res = subprocess.run(
+ ["redis-cli", "-u", uri, "SET", "jenkins_lock", "1", "NX", "EX", "3600"],
+ check=True,
+ text=True,
+ capture_output=True,
+ )
+
+ if res.stdout.strip() != "OK":
+ raise ValueError("Redis already locked... aborting.")
+
+ yield RedisConfig(
+ dsn=uri,
decode_responses=True,
socket_timeout=settings.redis_timeout,
socket_connect_timeout=settings.redis_timeout,
)
- return redis_config.create_redis_client()
+
+ r = redis.from_url(uri)
+ r.flushdb()
# --- Connectors ---