aboutsummaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorMax Nanis2026-03-08 21:57:53 -0400
committerMax Nanis2026-03-08 21:57:53 -0400
commitce291a165fab6b6dc9f053c7b75a699d0fdf389f (patch)
tree7a7b393f432684e13ffe92c40015fb6afc07ceac /test_utils
parentb2e56ec3ebc5eb91eb10cc37cc9e02102f441660 (diff)
downloadgeneralresearch-ce291a165fab6b6dc9f053c7b75a699d0fdf389f.tar.gz
generalresearch-ce291a165fab6b6dc9f053c7b75a699d0fdf389f.zip
Simple typing changes, Ruff import formatter. p2
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/conftest.py9
-rw-r--r--test_utils/managers/conftest.py145
-rw-r--r--test_utils/managers/upk/conftest.py32
-rw-r--r--test_utils/models/conftest.py110
-rw-r--r--test_utils/spectrum/conftest.py8
5 files changed, 183 insertions, 121 deletions
diff --git a/test_utils/conftest.py b/test_utils/conftest.py
index e074301..54fb682 100644
--- a/test_utils/conftest.py
+++ b/test_utils/conftest.py
@@ -247,13 +247,16 @@ def utc_30days_ago() -> "datetime":
@pytest.fixture(scope="function")
-def delete_df_collection(thl_web_rw, create_main_accounts) -> Callable:
+def delete_df_collection(
+ thl_web_rw: PostgresConfig, create_main_accounts: Callable[..., None]
+) -> Callable[..., None]:
+
from generalresearch.incite.collections import (
DFCollection,
DFCollectionType,
)
- def _teardown_events(coll: "DFCollection"):
+ def _inner(coll: "DFCollection"):
match coll.data_type:
case DFCollectionType.LEDGER:
for table in [
@@ -290,7 +293,7 @@ def delete_df_collection(thl_web_rw, create_main_accounts) -> Callable:
query=f"DELETE FROM {coll.data_type.value};",
)
- return _teardown_events
+ return _inner
# === GR Related ===
diff --git a/test_utils/managers/conftest.py b/test_utils/managers/conftest.py
index f1f774e..94dabae 100644
--- a/test_utils/managers/conftest.py
+++ b/test_utils/managers/conftest.py
@@ -1,15 +1,18 @@
from typing import TYPE_CHECKING, Callable
-import pymysql
import pytest
from generalresearch.managers.base import Permission
from generalresearch.models import Source
+from generalresearch.pg_helper import PostgresConfig
+from generalresearch.redis_helper import RedisConfig
+from generalresearch.sql_helper import SqlHelper
from test_utils.managers.cashout_methods import (
EXAMPLE_TANGO_CASHOUT_METHODS,
)
if TYPE_CHECKING:
+ from generalresearch.config import GRLBaseSettings
from generalresearch.grliq.managers.forensic_data import (
GrlIqDataManager,
)
@@ -32,6 +35,7 @@ if TYPE_CHECKING:
MembershipManager,
TeamManager,
)
+ from generalresearch.managers.thl.category import CategoryManager
from generalresearch.managers.thl.contest_manager import ContestManager
from generalresearch.managers.thl.ipinfo import (
GeoIpInfoManager,
@@ -84,7 +88,9 @@ if TYPE_CHECKING:
@pytest.fixture(scope="session")
-def ltxm(thl_web_rw, thl_redis_config) -> "LedgerTransactionManager":
+def ltxm(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "LedgerTransactionManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ledger_manager.ledger import (
@@ -100,7 +106,9 @@ def ltxm(thl_web_rw, thl_redis_config) -> "LedgerTransactionManager":
@pytest.fixture(scope="session")
-def lam(thl_web_rw, thl_redis_config) -> "LedgerAccountManager":
+def lam(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "LedgerAccountManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ledger_manager.ledger import (
@@ -116,7 +124,7 @@ def lam(thl_web_rw, thl_redis_config) -> "LedgerAccountManager":
@pytest.fixture(scope="session")
-def lm(thl_web_rw, thl_redis_config) -> "LedgerManager":
+def lm(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig) -> "LedgerManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ledger_manager.ledger import (
@@ -137,7 +145,9 @@ def lm(thl_web_rw, thl_redis_config) -> "LedgerManager":
@pytest.fixture(scope="session")
-def thl_lm(thl_web_rw, thl_redis_config) -> "ThlLedgerManager":
+def thl_lm(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "ThlLedgerManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ledger_manager.thl_ledger import (
@@ -158,7 +168,9 @@ def thl_lm(thl_web_rw, thl_redis_config) -> "ThlLedgerManager":
@pytest.fixture(scope="session")
-def payout_event_manager(thl_web_rw, thl_redis_config) -> "PayoutEventManager":
+def payout_event_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "PayoutEventManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.payout import PayoutEventManager
@@ -171,7 +183,9 @@ def payout_event_manager(thl_web_rw, thl_redis_config) -> "PayoutEventManager":
@pytest.fixture(scope="session")
-def user_payout_event_manager(thl_web_rw, thl_redis_config) -> "UserPayoutEventManager":
+def user_payout_event_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "UserPayoutEventManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.payout import UserPayoutEventManager
@@ -185,7 +199,7 @@ def user_payout_event_manager(thl_web_rw, thl_redis_config) -> "UserPayoutEventM
@pytest.fixture(scope="session")
def brokerage_product_payout_event_manager(
- thl_web_rw, thl_redis_config
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
) -> "BrokerageProductPayoutEventManager":
assert "/unittest-" in thl_web_rw.dsn.path
@@ -202,7 +216,7 @@ def brokerage_product_payout_event_manager(
@pytest.fixture(scope="session")
def business_payout_event_manager(
- thl_web_rw, thl_redis_config
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
) -> "BusinessPayoutEventManager":
assert "/unittest-" in thl_web_rw.dsn.path
@@ -218,7 +232,7 @@ def business_payout_event_manager(
@pytest.fixture(scope="session")
-def product_manager(thl_web_rw) -> "ProductManager":
+def product_manager(thl_web_rw: PostgresConfig) -> "ProductManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.product import ProductManager
@@ -227,7 +241,9 @@ def product_manager(thl_web_rw) -> "ProductManager":
@pytest.fixture(scope="session")
-def user_manager(settings, thl_web_rw, thl_web_rr) -> "UserManager":
+def user_manager(
+ settings: "GRLBaseSettings", thl_web_rw: PostgresConfig, thl_web_rr: PostgresConfig
+) -> "UserManager":
assert "/unittest-" in thl_web_rw.dsn.path
assert "/unittest-" in thl_web_rr.dsn.path
@@ -243,7 +259,7 @@ def user_manager(settings, thl_web_rw, thl_web_rr) -> "UserManager":
@pytest.fixture(scope="session")
-def user_metadata_manager(thl_web_rw) -> "UserMetadataManager":
+def user_metadata_manager(thl_web_rw: PostgresConfig) -> "UserMetadataManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.user_manager.user_metadata_manager import (
@@ -254,7 +270,7 @@ def user_metadata_manager(thl_web_rw) -> "UserMetadataManager":
@pytest.fixture(scope="session")
-def session_manager(thl_web_rw) -> "SessionManager":
+def session_manager(thl_web_rw: PostgresConfig) -> "SessionManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.session import SessionManager
@@ -263,7 +279,7 @@ def session_manager(thl_web_rw) -> "SessionManager":
@pytest.fixture(scope="session")
-def wall_manager(thl_web_rw) -> "WallManager":
+def wall_manager(thl_web_rw: PostgresConfig) -> "WallManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.wall import WallManager
@@ -272,7 +288,9 @@ def wall_manager(thl_web_rw) -> "WallManager":
@pytest.fixture(scope="session")
-def wall_cache_manager(thl_web_rw, thl_redis_config) -> "WallCacheManager":
+def wall_cache_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "WallCacheManager":
# assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.wall import WallCacheManager
@@ -281,7 +299,7 @@ def wall_cache_manager(thl_web_rw, thl_redis_config) -> "WallCacheManager":
@pytest.fixture(scope="session")
-def task_adjustment_manager(thl_web_rw) -> "TaskAdjustmentManager":
+def task_adjustment_manager(thl_web_rw: PostgresConfig) -> "TaskAdjustmentManager":
# assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.task_adjustment import (
@@ -292,7 +310,7 @@ def task_adjustment_manager(thl_web_rw) -> "TaskAdjustmentManager":
@pytest.fixture(scope="session")
-def contest_manager(thl_web_rw) -> "ContestManager":
+def contest_manager(thl_web_rw: PostgresConfig) -> "ContestManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.contest_manager import ContestManager
@@ -309,7 +327,7 @@ def contest_manager(thl_web_rw) -> "ContestManager":
@pytest.fixture(scope="session")
-def category_manager(thl_web_rw):
+def category_manager(thl_web_rw: PostgresConfig) -> "CategoryManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.category import CategoryManager
@@ -317,7 +335,7 @@ def category_manager(thl_web_rw):
@pytest.fixture(scope="session")
-def buyer_manager(thl_web_rw):
+def buyer_manager(thl_web_rw: PostgresConfig):
# assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.buyer import BuyerManager
@@ -325,7 +343,7 @@ def buyer_manager(thl_web_rw):
@pytest.fixture(scope="session")
-def survey_manager(thl_web_rw):
+def survey_manager(thl_web_rw: PostgresConfig):
# assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.survey import SurveyManager
@@ -333,7 +351,7 @@ def survey_manager(thl_web_rw):
@pytest.fixture(scope="session")
-def surveystat_manager(thl_web_rw):
+def surveystat_manager(thl_web_rw: PostgresConfig):
# assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.survey import SurveyStatManager
@@ -348,7 +366,7 @@ def surveypenalty_manager(thl_redis_config):
@pytest.fixture(scope="session")
-def upk_schema_manager(thl_web_rw):
+def upk_schema_manager(thl_web_rw: PostgresConfig):
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.profiling.schema import (
UpkSchemaManager,
@@ -358,7 +376,7 @@ def upk_schema_manager(thl_web_rw):
@pytest.fixture(scope="session")
-def user_upk_manager(thl_web_rw, thl_redis_config):
+def user_upk_manager(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig):
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.profiling.user_upk import (
UserUpkManager,
@@ -368,7 +386,7 @@ def user_upk_manager(thl_web_rw, thl_redis_config):
@pytest.fixture(scope="session")
-def question_manager(thl_web_rw, thl_redis_config):
+def question_manager(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig):
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.profiling.question import (
QuestionManager,
@@ -378,7 +396,7 @@ def question_manager(thl_web_rw, thl_redis_config):
@pytest.fixture(scope="session")
-def uqa_manager(thl_web_rw, thl_redis_config):
+def uqa_manager(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig):
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.profiling.uqa import UQAManager
@@ -395,7 +413,7 @@ def uqa_manager_clear_cache(uqa_manager, user):
@pytest.fixture(scope="session")
-def audit_log_manager(thl_web_rw) -> "AuditLogManager":
+def audit_log_manager(thl_web_rw: PostgresConfig) -> "AuditLogManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.userhealth import AuditLogManager
@@ -404,7 +422,7 @@ def audit_log_manager(thl_web_rw) -> "AuditLogManager":
@pytest.fixture(scope="session")
-def ip_geoname_manager(thl_web_rw) -> "IPGeonameManager":
+def ip_geoname_manager(thl_web_rw: PostgresConfig) -> "IPGeonameManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ipinfo import IPGeonameManager
@@ -413,7 +431,7 @@ def ip_geoname_manager(thl_web_rw) -> "IPGeonameManager":
@pytest.fixture(scope="session")
-def ip_information_manager(thl_web_rw) -> "IPInformationManager":
+def ip_information_manager(thl_web_rw: PostgresConfig) -> "IPInformationManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ipinfo import IPInformationManager
@@ -422,7 +440,9 @@ def ip_information_manager(thl_web_rw) -> "IPInformationManager":
@pytest.fixture(scope="session")
-def ip_record_manager(thl_web_rw, thl_redis_config) -> "IPRecordManager":
+def ip_record_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "IPRecordManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.userhealth import IPRecordManager
@@ -431,7 +451,9 @@ def ip_record_manager(thl_web_rw, thl_redis_config) -> "IPRecordManager":
@pytest.fixture(scope="session")
-def user_iphistory_manager(thl_web_rw, thl_redis_config) -> "UserIpHistoryManager":
+def user_iphistory_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "UserIpHistoryManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.userhealth import (
@@ -451,7 +473,9 @@ def user_iphistory_manager_clear_cache(user_iphistory_manager, user):
@pytest.fixture(scope="session")
-def geoipinfo_manager(thl_web_rw, thl_redis_config) -> "GeoIpInfoManager":
+def geoipinfo_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "GeoIpInfoManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.ipinfo import GeoIpInfoManager
@@ -469,7 +493,9 @@ def maxmind_basic_manager() -> "MaxmindBasicManager":
@pytest.fixture(scope="session")
-def maxmind_manager(thl_web_rw, thl_redis_config) -> "MaxmindManager":
+def maxmind_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> "MaxmindManager":
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.maxmind import MaxmindManager
@@ -478,7 +504,7 @@ def maxmind_manager(thl_web_rw, thl_redis_config) -> "MaxmindManager":
@pytest.fixture(scope="session")
-def cashout_method_manager(thl_web_rw):
+def cashout_method_manager(thl_web_rw: PostgresConfig):
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.cashout_method import (
CashoutMethodManager,
@@ -488,14 +514,14 @@ def cashout_method_manager(thl_web_rw):
@pytest.fixture(scope="session")
-def event_manager(thl_redis_config):
+def event_manager(thl_redis_config: RedisConfig):
from generalresearch.managers.events import EventManager
return EventManager(redis_config=thl_redis_config)
@pytest.fixture(scope="session")
-def user_streak_manager(thl_web_rw):
+def user_streak_manager(thl_web_rw: PostgresConfig):
assert "/unittest-" in thl_web_rw.dsn.path
from generalresearch.managers.thl.user_streak import (
UserStreakManager,
@@ -505,7 +531,7 @@ def user_streak_manager(thl_web_rw):
@pytest.fixture(scope="session")
-def uqa_db_index(thl_web_rw):
+def uqa_db_index(thl_web_rw: PostgresConfig):
# There were some custom indices created not through django.
# Make sure the index used in the index hint exists
assert "/unittest-" in thl_web_rw.dsn.path
@@ -521,7 +547,7 @@ def uqa_db_index(thl_web_rw):
@pytest.fixture(scope="session")
-def delete_cashoutmethod_db(thl_web_rw) -> Callable:
+def delete_cashoutmethod_db(thl_web_rw: PostgresConfig) -> Callable[..., None]:
def _delete_cashoutmethod_db():
thl_web_rw.execute_write(
query="DELETE FROM accounting_cashoutmethod;",
@@ -531,14 +557,21 @@ def delete_cashoutmethod_db(thl_web_rw) -> Callable:
@pytest.fixture(scope="session")
-def setup_cashoutmethod_db(settings, cashout_method_manager, delete_cashoutmethod_db):
- settings.amt_
-
+def setup_cashoutmethod_db(
+ settings: "GRLBaseSettings", cashout_method_manager, delete_cashoutmethod_db
+):
delete_cashoutmethod_db()
for x in EXAMPLE_TANGO_CASHOUT_METHODS:
cashout_method_manager.create(x)
- cashout_method_manager.create(AMT_ASSIGNMENT_CASHOUT_METHOD)
- cashout_method_manager.create(AMT_BONUS_CASHOUT_METHOD)
+
+ # TODO: convert these ids into instances to use.
+ # settings.amt_bonus_cashout_method_id
+ # settings.amt_assignment_cashout_method_id
+
+ # cashout_method_manager.create(AMT_ASSIGNMENT_CASHOUT_METHOD)
+ # cashout_method_manager.create(AMT_BONUS_CASHOUT_METHOD)
+ raise NotImplementedError("Need to implement setup_cashoutmethod_db")
+
return None
@@ -546,7 +579,7 @@ def setup_cashoutmethod_db(settings, cashout_method_manager, delete_cashoutmetho
@pytest.fixture(scope="session")
-def spectrum_manager(spectrum_rw):
+def spectrum_manager(spectrum_rw: SqlHelper) -> "SpectrumSurveyManager":
from generalresearch.managers.spectrum.survey import (
SpectrumSurveyManager,
)
@@ -556,7 +589,9 @@ def spectrum_manager(spectrum_rw):
# === GR ===
@pytest.fixture(scope="session")
-def business_manager(gr_db, gr_redis_config) -> "BusinessManager":
+def business_manager(
+ gr_db: PostgresConfig, gr_redis_config: RedisConfig
+) -> "BusinessManager":
from generalresearch.redis_helper import RedisConfig
assert "/unittest-" in gr_db.dsn.path
@@ -571,7 +606,7 @@ def business_manager(gr_db, gr_redis_config) -> "BusinessManager":
@pytest.fixture(scope="session")
-def business_address_manager(gr_db) -> "BusinessAddressManager":
+def business_address_manager(gr_db: PostgresConfig) -> "BusinessAddressManager":
assert "/unittest-" in gr_db.dsn.path
from generalresearch.managers.gr.business import BusinessAddressManager
@@ -580,7 +615,9 @@ def business_address_manager(gr_db) -> "BusinessAddressManager":
@pytest.fixture(scope="session")
-def business_bank_account_manager(gr_db) -> "BusinessBankAccountManager":
+def business_bank_account_manager(
+ gr_db: PostgresConfig,
+) -> "BusinessBankAccountManager":
assert "/unittest-" in gr_db.dsn.path
from generalresearch.managers.gr.business import (
@@ -591,7 +628,7 @@ def business_bank_account_manager(gr_db) -> "BusinessBankAccountManager":
@pytest.fixture(scope="session")
-def team_manager(gr_db, gr_redis_config) -> "TeamManager":
+def team_manager(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> "TeamManager":
assert "/unittest-" in gr_db.dsn.path
from generalresearch.managers.gr.team import TeamManager
@@ -600,7 +637,7 @@ def team_manager(gr_db, gr_redis_config) -> "TeamManager":
@pytest.fixture(scope="session")
-def gr_um(gr_db, gr_redis_config) -> "GRUserManager":
+def gr_um(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> "GRUserManager":
assert "/unittest-" in gr_db.dsn.path
from generalresearch.managers.gr.authentication import GRUserManager
@@ -609,7 +646,7 @@ def gr_um(gr_db, gr_redis_config) -> "GRUserManager":
@pytest.fixture(scope="session")
-def gr_tm(gr_db) -> "GRTokenManager":
+def gr_tm(gr_db: PostgresConfig) -> "GRTokenManager":
assert "/unittest-" in gr_db.dsn.path
from generalresearch.managers.gr.authentication import GRTokenManager
@@ -618,7 +655,7 @@ def gr_tm(gr_db) -> "GRTokenManager":
@pytest.fixture(scope="session")
-def membership_manager(gr_db) -> "MembershipManager":
+def membership_manager(gr_db: PostgresConfig) -> "MembershipManager":
assert "/unittest-" in gr_db.dsn.path
from generalresearch.managers.gr.team import MembershipManager
@@ -630,7 +667,7 @@ def membership_manager(gr_db) -> "MembershipManager":
@pytest.fixture(scope="session")
-def grliq_dm(grliq_db) -> "GrlIqDataManager":
+def grliq_dm(grliq_db: PostgresConfig) -> "GrlIqDataManager":
assert "/unittest-" in grliq_db.dsn.path
from generalresearch.grliq.managers.forensic_data import (
@@ -641,7 +678,7 @@ def grliq_dm(grliq_db) -> "GrlIqDataManager":
@pytest.fixture(scope="session")
-def grliq_em(grliq_db) -> "GrlIqEventManager":
+def grliq_em(grliq_db: PostgresConfig) -> "GrlIqEventManager":
assert "/unittest-" in grliq_db.dsn.path
from generalresearch.grliq.managers.forensic_events import (
@@ -652,7 +689,7 @@ def grliq_em(grliq_db) -> "GrlIqEventManager":
@pytest.fixture(scope="session")
-def grliq_crr(grliq_db) -> "GrlIqCategoryResultsReader":
+def grliq_crr(grliq_db: PostgresConfig) -> "GrlIqCategoryResultsReader":
assert "/unittest-" in grliq_db.dsn.path
from generalresearch.grliq.managers.forensic_results import (
@@ -663,7 +700,7 @@ def grliq_crr(grliq_db) -> "GrlIqCategoryResultsReader":
@pytest.fixture(scope="session")
-def delete_buyers_surveys(thl_web_rw, buyer_manager):
+def delete_buyers_surveys(thl_web_rw: PostgresConfig, buyer_manager):
# assert "/unittest-" in thl_web_rw.dsn.path
thl_web_rw.execute_write(
"""
diff --git a/test_utils/managers/upk/conftest.py b/test_utils/managers/upk/conftest.py
index 61be924..e28d085 100644
--- a/test_utils/managers/upk/conftest.py
+++ b/test_utils/managers/upk/conftest.py
@@ -1,6 +1,6 @@
import os
import time
-from typing import Optional
+from typing import TYPE_CHECKING, Optional
from uuid import UUID
import pandas as pd
@@ -8,6 +8,9 @@ import pytest
from generalresearch.pg_helper import PostgresConfig
+if TYPE_CHECKING:
+ from generalresearch.managers.thl.category import CategoryManager
+
def insert_data_from_csv(
thl_web_rw: PostgresConfig,
@@ -39,7 +42,9 @@ def insert_data_from_csv(
@pytest.fixture(scope="session")
-def category_data(thl_web_rw, category_manager) -> None:
+def category_data(
+ thl_web_rw: PostgresConfig, category_manager: "CategoryManager"
+) -> None:
fp = os.path.join(os.path.dirname(__file__), "marketplace_category.csv.gz")
insert_data_from_csv(
thl_web_rw,
@@ -66,20 +71,23 @@ def category_data(thl_web_rw, category_manager) -> None:
@pytest.fixture(scope="session")
-def property_data(thl_web_rw) -> None:
+def property_data(thl_web_rw: PostgresConfig) -> None:
fp = os.path.join(os.path.dirname(__file__), "marketplace_property.csv.gz")
insert_data_from_csv(thl_web_rw, fp=fp, table_name="marketplace_property")
@pytest.fixture(scope="session")
-def item_data(thl_web_rw) -> None:
+def item_data(thl_web_rw: PostgresConfig) -> None:
fp = os.path.join(os.path.dirname(__file__), "marketplace_item.csv.gz")
insert_data_from_csv(thl_web_rw, fp=fp, table_name="marketplace_item")
@pytest.fixture(scope="session")
def propertycategoryassociation_data(
- thl_web_rw, category_data, property_data, category_manager
+ thl_web_rw: PostgresConfig,
+ category_data,
+ property_data,
+ category_manager: "CategoryManager",
) -> None:
table_name = "marketplace_propertycategoryassociation"
fp = os.path.join(os.path.dirname(__file__), f"{table_name}.csv.gz")
@@ -93,27 +101,31 @@ def propertycategoryassociation_data(
@pytest.fixture(scope="session")
-def propertycountry_data(thl_web_rw, property_data) -> None:
+def propertycountry_data(thl_web_rw: PostgresConfig, property_data) -> None:
fp = os.path.join(os.path.dirname(__file__), "marketplace_propertycountry.csv.gz")
insert_data_from_csv(thl_web_rw, fp=fp, table_name="marketplace_propertycountry")
@pytest.fixture(scope="session")
-def propertymarketplaceassociation_data(thl_web_rw, property_data) -> None:
+def propertymarketplaceassociation_data(
+ thl_web_rw: PostgresConfig, property_data
+) -> None:
table_name = "marketplace_propertymarketplaceassociation"
fp = os.path.join(os.path.dirname(__file__), f"{table_name}.csv.gz")
insert_data_from_csv(thl_web_rw, fp=fp, table_name=table_name)
@pytest.fixture(scope="session")
-def propertyitemrange_data(thl_web_rw, property_data, item_data) -> None:
+def propertyitemrange_data(
+ thl_web_rw: PostgresConfig, property_data, item_data
+) -> None:
table_name = "marketplace_propertyitemrange"
fp = os.path.join(os.path.dirname(__file__), f"{table_name}.csv.gz")
insert_data_from_csv(thl_web_rw, fp=fp, table_name=table_name)
@pytest.fixture(scope="session")
-def question_data(thl_web_rw) -> None:
+def question_data(thl_web_rw: PostgresConfig) -> None:
table_name = "marketplace_question"
fp = os.path.join(os.path.dirname(__file__), f"{table_name}.csv.gz")
insert_data_from_csv(
@@ -122,7 +134,7 @@ def question_data(thl_web_rw) -> None:
@pytest.fixture(scope="session")
-def clear_upk_tables(thl_web_rw):
+def clear_upk_tables(thl_web_rw: PostgresConfig):
tables = [
"marketplace_propertyitemrange",
"marketplace_propertymarketplaceassociation",
diff --git a/test_utils/models/conftest.py b/test_utils/models/conftest.py
index dcc3b66..81dc11e 100644
--- a/test_utils/models/conftest.py
+++ b/test_utils/models/conftest.py
@@ -5,7 +5,6 @@ from random import randint
from typing import TYPE_CHECKING, Callable, Dict, List, Optional
from uuid import uuid4
-import pytest
from pydantic import AwareDatetime, PositiveInt
from generalresearch.models import Source
@@ -14,6 +13,7 @@ from generalresearch.models.thl.definitions import (
Status,
)
from generalresearch.models.thl.survey.model import Buyer, Survey
+from generalresearch.pg_helper import PostgresConfig
from test_utils.managers.conftest import (
business_address_manager,
business_manager,
@@ -28,6 +28,7 @@ from test_utils.managers.conftest import (
if TYPE_CHECKING:
from generalresearch.currency import USDCent
+ from generalresearch.managers.thl.session import SessionManager
from generalresearch.models.gr.authentication import GRToken, GRUser
from generalresearch.models.gr.business import (
Business,
@@ -53,7 +54,7 @@ if TYPE_CHECKING:
@pytest.fixture(scope="function")
-def user(request, product_manager, user_manager, thl_web_rr) -> "User":
+def user(request, product_manager, user_manager, thl_web_rr: PostgresConfig) -> "User":
product = getattr(request, "product", None)
if product is None:
@@ -74,25 +75,29 @@ def user_with_wallet(
@pytest.fixture
-def user_with_wallet_amt(request, user_factory, product_amt_true: "Product") -> "User":
+def user_with_wallet_amt(
+ request, user_factory: Callable[..., "User"], product_amt_true: "Product"
+) -> "User":
# A user on a product with user wallet enabled, on AMT, but they have no money
return user_factory(product=product_amt_true)
@pytest.fixture(scope="function")
-def user_factory(user_manager, thl_web_rr) -> Callable:
- def _create_user(product: "Product", created: Optional[datetime] = None):
+def user_factory(user_manager, thl_web_rr: PostgresConfig) -> Callable[..., "User"]:
+
+ def _inner(product: "Product", created: Optional[datetime] = None):
u = user_manager.create_dummy(product=product, created=created)
u.prefetch_product(pg_config=thl_web_rr)
return u
- return _create_user
+ return _inner
@pytest.fixture(scope="function")
-def wall_factory(wall_manager) -> Callable:
- def _create_wall(
+def wall_factory(wall_manager) -> Callable[..., "Wall"]:
+
+ def _inner(
session: "Session", wall_status: "Status", req_cpi: Optional[Decimal] = None
):
@@ -126,10 +131,10 @@ def wall_factory(wall_manager) -> Callable:
return wall
- return _create_wall
+ return _inner
-@pytest.fixture(scope="function")
+@pytest.fixture
def wall(session, user, wall_manager) -> Optional["Wall"]:
from generalresearch.models.thl.task_status import StatusCode1
@@ -143,9 +148,12 @@ def wall(session, user, wall_manager) -> Optional["Wall"]:
return wall
-@pytest.fixture(scope="function")
+@pytest.fixture
def session_factory(
- wall_factory, session_manager, wall_manager, utc_hour_ago
+ wall_factory,
+ session_manager: "SessionManager",
+ wall_manager,
+ utc_hour_ago: datetime,
) -> Callable[..., "Session"]:
from generalresearch.models.thl.session import Source
@@ -208,11 +216,13 @@ def session_factory(
@pytest.fixture(scope="function")
def finished_session_factory(
- session_factory, session_manager, utc_hour_ago
-) -> Callable:
+ session_factory: Callable[..., "Session"],
+ session_manager: "SessionManager",
+ utc_hour_ago: datetime,
+) -> Callable[..., "Session"]:
from generalresearch.models.thl.session import Source
- def _create_finished_session(
+ def _inner(
user: "User",
# Wall details
wall_count: int = 5,
@@ -246,11 +256,11 @@ def finished_session_factory(
)
return s
- return _create_finished_session
+ return _inner
@pytest.fixture(scope="function")
-def session(user, session_manager, wall_manager) -> "Session":
+def session(user, session_manager: "SessionManager", wall_manager) -> "Session":
from generalresearch.models.thl.session import Session, Wall
session: Session = session_manager.create_dummy(user=user, country_iso="us")
@@ -294,7 +304,7 @@ def product_factory(product_manager) -> Callable:
return _create_product
-@pytest.fixture(scope="function")
+@pytest.fixture
def payout_config(request) -> "PayoutConfig":
from generalresearch.models.thl.product import (
PayoutConfig,
@@ -315,7 +325,7 @@ def payout_config(request) -> "PayoutConfig":
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def product_user_wallet_yes(payout_config, product_manager) -> "Product":
from generalresearch.managers.thl.product import ProductManager
from generalresearch.models.thl.product import UserWalletConfig
@@ -326,7 +336,7 @@ def product_user_wallet_yes(payout_config, product_manager) -> "Product":
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def product_user_wallet_no(product_manager) -> "Product":
from generalresearch.managers.thl.product import ProductManager
from generalresearch.models.thl.product import UserWalletConfig
@@ -337,7 +347,7 @@ def product_user_wallet_no(product_manager) -> "Product":
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def product_amt_true(product_manager, payout_config) -> "Product":
from generalresearch.models.thl.product import UserWalletConfig
@@ -347,7 +357,7 @@ def product_amt_true(product_manager, payout_config) -> "Product":
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def bp_payout_factory(
thl_lm, product_manager, business_payout_event_manager
) -> Callable:
@@ -380,7 +390,7 @@ def bp_payout_factory(
# === GR ===
-@pytest.fixture(scope="function")
+@pytest.fixture
def business(request, business_manager) -> "Business":
from generalresearch.managers.gr.business import BusinessManager
@@ -388,7 +398,7 @@ def business(request, business_manager) -> "Business":
return business_manager.create_dummy()
-@pytest.fixture(scope="function")
+@pytest.fixture
def business_address(request, business, business_address_manager) -> "BusinessAddress":
from generalresearch.managers.gr.business import BusinessAddressManager
@@ -396,7 +406,7 @@ def business_address(request, business, business_address_manager) -> "BusinessAd
return business_address_manager.create_dummy(business_id=business.id)
-@pytest.fixture(scope="function")
+@pytest.fixture
def business_bank_account(
request, business, business_bank_account_manager
) -> "BusinessBankAccount":
@@ -406,7 +416,7 @@ def business_bank_account(
return business_bank_account_manager.create_dummy(business_id=business.id)
-@pytest.fixture(scope="function")
+@pytest.fixture
def team(request, team_manager) -> "Team":
from generalresearch.managers.gr.team import TeamManager
@@ -414,7 +424,7 @@ def team(request, team_manager) -> "Team":
return team_manager.create_dummy()
-@pytest.fixture(scope="function")
+@pytest.fixture
def gr_user(gr_um) -> "GRUser":
from generalresearch.managers.gr.authentication import GRUserManager
@@ -422,7 +432,7 @@ def gr_user(gr_um) -> "GRUser":
return gr_um.create_dummy()
-@pytest.fixture(scope="function")
+@pytest.fixture
def gr_user_cache(gr_user, gr_db, thl_web_rr, gr_redis_config):
gr_user.set_cache(
pg_config=gr_db, thl_web_rr=thl_web_rr, redis_config=gr_redis_config
@@ -430,12 +440,12 @@ def gr_user_cache(gr_user, gr_db, thl_web_rr, gr_redis_config):
return gr_user
-@pytest.fixture(scope="function")
-def gr_user_factory(gr_um) -> Callable:
- def _create_gr_user():
+@pytest.fixture
+def gr_user_factory(gr_um) -> Callable[..., "GRUser"]:
+ def _inner():
return gr_um.create_dummy()
- return _create_gr_user
+ return _inner
@pytest.fixture()
@@ -447,7 +457,7 @@ def gr_user_token(gr_user, gr_tm, gr_db) -> "GRToken":
@pytest.fixture()
-def gr_user_token_header(gr_user_token) -> Dict:
+def gr_user_token_header(gr_user_token: "GRToken") -> Dict[str, str]:
return gr_user_token.auth_header
@@ -461,41 +471,41 @@ def membership(request, team, gr_user, team_manager) -> "Membership":
@pytest.fixture(scope="function")
def membership_factory(
team: "Team", gr_user: "GRUser", membership_manager, team_manager, gr_um
-) -> Callable:
+) -> Callable[..., "Membership"]:
from generalresearch.managers.gr.team import MembershipManager
membership_manager: MembershipManager
- def _create_membership(**kwargs):
+ def _inner(**kwargs) -> "Membership":
_team = kwargs.get("team", team_manager.create_dummy())
_gr_user = kwargs.get("gr_user", gr_um.create_dummy())
return membership_manager.create(team=_team, gr_user=_gr_user)
- return _create_membership
+ return _inner
-@pytest.fixture(scope="function")
-def audit_log(audit_log_manager, user) -> "AuditLog":
+@pytest.fixture
+def audit_log(audit_log_manager, user: "User") -> "AuditLog":
from generalresearch.managers.thl.userhealth import AuditLogManager
audit_log_manager: AuditLogManager
return audit_log_manager.create_dummy(user_id=user.user_id)
-@pytest.fixture(scope="function")
-def audit_log_factory(audit_log_manager) -> Callable:
+@pytest.fixture
+def audit_log_factory(audit_log_manager) -> Callable[..., "AuditLog"]:
from generalresearch.managers.thl.userhealth import AuditLogManager
audit_log_manager: AuditLogManager
- def _create_audit_log(
+ def _inner(
user_id: PositiveInt,
level: Optional["AuditLogLevel"] = None,
event_type: Optional[str] = None,
event_msg: Optional[str] = None,
event_value: Optional[float] = None,
- ):
+ ) -> "AuditLog":
return audit_log_manager.create_dummy(
user_id=user_id,
level=level,
@@ -504,10 +514,10 @@ def audit_log_factory(audit_log_manager) -> Callable:
event_value=event_value,
)
- return _create_audit_log
+ return _inner
-@pytest.fixture(scope="function")
+@pytest.fixture
def ip_geoname(ip_geoname_manager) -> "IPGeoname":
from generalresearch.managers.thl.ipinfo import IPGeonameManager
@@ -515,7 +525,7 @@ def ip_geoname(ip_geoname_manager) -> "IPGeoname":
return ip_geoname_manager.create_dummy()
-@pytest.fixture(scope="function")
+@pytest.fixture
def ip_information(ip_information_manager, ip_geoname) -> "IPInformation":
from generalresearch.managers.thl.ipinfo import IPInformationManager
@@ -525,7 +535,7 @@ def ip_information(ip_information_manager, ip_geoname) -> "IPInformation":
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def ip_information_factory(ip_information_manager) -> Callable:
from generalresearch.managers.thl.ipinfo import IPInformationManager
@@ -542,8 +552,8 @@ def ip_information_factory(ip_information_manager) -> Callable:
return _create_ip_info
-@pytest.fixture(scope="function")
-def ip_record(ip_record_manager, ip_geoname, user) -> "IPRecord":
+@pytest.fixture
+def ip_record(ip_record_manager, ip_geoname, user: "User") -> "IPRecord":
from generalresearch.managers.thl.userhealth import IPRecordManager
ip_record_manager: IPRecordManager
@@ -551,8 +561,8 @@ def ip_record(ip_record_manager, ip_geoname, user) -> "IPRecord":
return ip_record_manager.create_dummy(user_id=user.user_id)
-@pytest.fixture(scope="function")
-def ip_record_factory(ip_record_manager, user) -> Callable:
+@pytest.fixture
+def ip_record_factory(ip_record_manager, user: "User") -> Callable:
from generalresearch.managers.thl.userhealth import IPRecordManager
ip_record_manager: IPRecordManager
diff --git a/test_utils/spectrum/conftest.py b/test_utils/spectrum/conftest.py
index d737730..0afc3f5 100644
--- a/test_utils/spectrum/conftest.py
+++ b/test_utils/spectrum/conftest.py
@@ -34,21 +34,21 @@ def spectrum_rw(settings: "GRLBaseSettings") -> SqlHelper:
@pytest.fixture(scope="session")
-def spectrum_criteria_manager(spectrum_rw) -> SpectrumCriteriaManager:
+def spectrum_criteria_manager(spectrum_rw: SqlHelper) -> SpectrumCriteriaManager:
assert "/unittest-" in spectrum_rw.dsn.path
return SpectrumCriteriaManager(spectrum_rw)
@pytest.fixture(scope="session")
-def spectrum_survey_manager(spectrum_rw) -> SpectrumSurveyManager:
+def spectrum_survey_manager(spectrum_rw: SqlHelper) -> SpectrumSurveyManager:
assert "/unittest-" in spectrum_rw.dsn.path
return SpectrumSurveyManager(spectrum_rw)
@pytest.fixture(scope="session")
def setup_spectrum_surveys(
- spectrum_rw, spectrum_survey_manager, spectrum_criteria_manager
-):
+ spectrum_rw: SqlHelper, spectrum_survey_manager, spectrum_criteria_manager
+) -> None:
now = datetime.now(timezone.utc)
# make sure these example surveys exist in db
surveys = [SpectrumSurvey.model_validate_json(x) for x in SURVEYS_JSON]