1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
import os
from typing import TYPE_CHECKING
from uuid import uuid4
from dotenv import load_dotenv
import pytest
from generalresearchutils.pg_helper import PostgresConfig
from tests import generate_amt_id
from _pytest.config import Config
from jb.decorators import CLIENT_CONFIG
from mypy_boto3_mturk import MTurkClient
if TYPE_CHECKING:
from jb.settings import Settings
pytest_plugins = [
"tests.fixtures.amt",
"tests.fixtures.flow",
"tests.fixtures.http",
"tests.fixtures.managers",
"tests.fixtures.models",
]
# --- IDs and Identifiers ---
@pytest.fixture
def amt_hit_id() -> str:
return generate_amt_id()
@pytest.fixture
def amt_hit_type_id() -> str:
return generate_amt_id()
@pytest.fixture
def amt_assignment_id() -> str:
return generate_amt_id()
@pytest.fixture
def amt_worker_id() -> str:
return generate_amt_id(length=21)
@pytest.fixture
def amt_group_id() -> str:
return generate_amt_id()
@pytest.fixture
def tsid() -> str:
return uuid4().hex
@pytest.fixture
def tsid1() -> str:
return uuid4().hex
@pytest.fixture
def tsid2() -> str:
return uuid4().hex
@pytest.fixture
def pe_id() -> str:
# payout event / cashout request UUID
return uuid4().hex
# --- Settings ---
@pytest.fixture(scope="session")
def env_file_path(pytestconfig: Config) -> str:
root_path = pytestconfig.rootpath
env_path = os.path.join(root_path, ".env.test")
if os.path.exists(env_path):
load_dotenv(dotenv_path=env_path, override=True)
return env_path
@pytest.fixture(scope="session")
def settings(env_file_path: str) -> "Settings":
from jb.settings import Settings as JBSettings
s = JBSettings(_env_file=env_file_path)
return s
# --- Database Connectors ---
@pytest.fixture(scope="session")
def redis(settings: "Settings"):
from generalresearchutils.redis_helper import RedisConfig
redis_config = RedisConfig(
dsn=settings.redis,
decode_responses=True,
socket_timeout=settings.redis_timeout,
socket_connect_timeout=settings.redis_timeout,
)
return redis_config.create_redis_client()
@pytest.fixture(scope="session")
def pg_config(settings: "Settings") -> PostgresConfig:
return PostgresConfig(
dsn=settings.amt_jb_db,
connect_timeout=1,
statement_timeout=1,
)
# --- Connectors ---
@pytest.fixture(scope="session")
def amt_client(settings: "Settings") -> MTurkClient:
import boto3
client = boto3.client(
service_name="mturk",
region_name="us-east-1",
endpoint_url=str(settings.amt_endpoint),
aws_access_key_id=settings.amt_access_id,
aws_secret_access_key=settings.amt_secret_key,
config=CLIENT_CONFIG,
)
# Confirm we're only using the Sandbox for any unittests
assert "mturk-requester-sandbox" in client.meta.endpoint_url
return client
|