diff options
Diffstat (limited to 'test_utils/managers/conftest.py')
| -rw-r--r-- | test_utils/managers/conftest.py | 578 |
1 files changed, 40 insertions, 538 deletions
diff --git a/test_utils/managers/conftest.py b/test_utils/managers/conftest.py index c8a6e2f..d2e5d20 100644 --- a/test_utils/managers/conftest.py +++ b/test_utils/managers/conftest.py @@ -1,9 +1,33 @@ -from typing import TYPE_CHECKING, Callable +from __future__ import annotations + +from typing import Callable import pytest -from generalresearch.managers.base import Permission +from generalresearch.managers.gr.business import ( + BusinessAddressManager, + BusinessBankAccountManager, + BusinessManager, +) +from generalresearch.managers.gr.team import ( + MembershipManager, + TeamManager, +) +from generalresearch.managers.spectrum.survey import SpectrumSurveyManager +from generalresearch.managers.thl.buyer import BuyerManager +from generalresearch.managers.thl.ipinfo import ( + GeoIpInfoManager, + IPGeonameManager, + IPInformationManager, +) +from generalresearch.managers.thl.profiling.uqa import UQAManager +from generalresearch.managers.thl.userhealth import ( + AuditLogManager, + IPRecordManager, + UserIpHistoryManager, +) from generalresearch.models import Source +from generalresearch.models.thl.user import User from generalresearch.pg_helper import PostgresConfig from generalresearch.redis_helper import RedisConfig from generalresearch.sql_helper import SqlHelper @@ -11,437 +35,11 @@ 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, - ) - from generalresearch.grliq.managers.forensic_events import ( - GrlIqEventManager, - ) - from generalresearch.grliq.managers.forensic_results import ( - GrlIqCategoryResultsReader, - ) - from generalresearch.managers.gr.authentication import ( - GRTokenManager, - GRUserManager, - ) - from generalresearch.managers.gr.business import ( - BusinessAddressManager, - BusinessBankAccountManager, - BusinessManager, - ) - from generalresearch.managers.gr.team import ( - MembershipManager, - TeamManager, - ) - from generalresearch.managers.thl.buyer import BuyerManager - from generalresearch.managers.thl.category import CategoryManager - from generalresearch.managers.thl.contest_manager import ContestManager - from generalresearch.managers.thl.ipinfo import ( - GeoIpInfoManager, - IPGeonameManager, - IPInformationManager, - ) - from generalresearch.managers.thl.ledger_manager.ledger import ( - LedgerAccountManager, - LedgerManager, - LedgerTransactionManager, - ) - from generalresearch.managers.thl.ledger_manager.thl_ledger import ( - ThlLedgerManager, - ) - from generalresearch.managers.thl.maxmind import MaxmindManager - from generalresearch.managers.thl.maxmind.basic import ( - MaxmindBasicManager, - ) - from generalresearch.managers.thl.payout import ( - BrokerageProductPayoutEventManager, - BusinessPayoutEventManager, - PayoutEventManager, - UserPayoutEventManager, - ) - from generalresearch.managers.thl.product import ProductManager - from generalresearch.managers.thl.session import SessionManager - from generalresearch.managers.thl.task_adjustment import ( - TaskAdjustmentManager, - ) - from generalresearch.managers.thl.user_manager.user_manager import ( - UserManager, - ) - from generalresearch.managers.thl.user_manager.user_metadata_manager import ( - UserMetadataManager, - ) - from generalresearch.managers.thl.userhealth import ( - AuditLogManager, - IPRecordManager, - UserIpHistoryManager, - ) - from generalresearch.managers.thl.wall import ( - WallCacheManager, - WallManager, - ) - from generalresearch.models.thl.user import User - - # === THL === @pytest.fixture(scope="session") -def ltxm( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "LedgerTransactionManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.ledger_manager.ledger import ( - LedgerTransactionManager, - ) - - return LedgerTransactionManager( - pg_config=thl_web_rw, - permissions=[Permission.CREATE, Permission.READ], - testing=True, - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def lam( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "LedgerAccountManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.ledger_manager.ledger import ( - LedgerAccountManager, - ) - - return LedgerAccountManager( - pg_config=thl_web_rw, - permissions=[Permission.CREATE, Permission.READ], - testing=True, - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def lm(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig) -> "LedgerManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.ledger_manager.ledger import ( - LedgerManager, - ) - - return LedgerManager( - pg_config=thl_web_rw, - permissions=[ - Permission.CREATE, - Permission.READ, - Permission.UPDATE, - Permission.DELETE, - ], - testing=True, - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def thl_lm( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "ThlLedgerManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.ledger_manager.thl_ledger import ( - ThlLedgerManager, - ) - - return ThlLedgerManager( - pg_config=thl_web_rw, - permissions=[ - Permission.CREATE, - Permission.READ, - Permission.UPDATE, - Permission.DELETE, - ], - testing=True, - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def payout_event_manager( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "PayoutEventManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.payout import PayoutEventManager - - return PayoutEventManager( - pg_config=thl_web_rw, - permissions=[Permission.CREATE, Permission.READ], - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def user_payout_event_manager( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "UserPayoutEventManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.payout import UserPayoutEventManager - - return UserPayoutEventManager( - pg_config=thl_web_rw, - permissions=[Permission.CREATE, Permission.READ], - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def brokerage_product_payout_event_manager( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "BrokerageProductPayoutEventManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.payout import ( - BrokerageProductPayoutEventManager, - ) - - return BrokerageProductPayoutEventManager( - pg_config=thl_web_rw, - permissions=[Permission.CREATE, Permission.READ], - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def business_payout_event_manager( - thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "BusinessPayoutEventManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.payout import ( - BusinessPayoutEventManager, - ) - - return BusinessPayoutEventManager( - pg_config=thl_web_rw, - permissions=[Permission.CREATE, Permission.READ], - redis_config=thl_redis_config, - ) - - -@pytest.fixture(scope="session") -def product_manager(thl_web_rw: PostgresConfig) -> "ProductManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.product import ProductManager - - return ProductManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def user_manager( - settings: "GRLBaseSettings", thl_web_rw: PostgresConfig, thl_web_rr: PostgresConfig -) -> "UserManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert thl_web_rr.dsn - assert thl_web_rr.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rr.dsn.path - - from generalresearch.managers.thl.user_manager.user_manager import ( - UserManager, - ) - - return UserManager( - pg_config=thl_web_rw, - pg_config_rr=thl_web_rr, - redis=settings.redis, - ) - - -@pytest.fixture(scope="session") -def user_metadata_manager(thl_web_rw: PostgresConfig) -> "UserMetadataManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.user_manager.user_metadata_manager import ( - UserMetadataManager, - ) - - return UserMetadataManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def session_manager(thl_web_rw: PostgresConfig) -> "SessionManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.session import SessionManager - - return SessionManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def wall_manager(thl_web_rw: PostgresConfig) -> "WallManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.wall import WallManager - - return WallManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -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 - - return WallCacheManager(pg_config=thl_web_rw, redis_config=thl_redis_config) - - -@pytest.fixture(scope="session") -def task_adjustment_manager(thl_web_rw: PostgresConfig) -> "TaskAdjustmentManager": - # assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.task_adjustment import ( - TaskAdjustmentManager, - ) - - return TaskAdjustmentManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def contest_manager(thl_web_rw: PostgresConfig) -> "ContestManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.contest_manager import ContestManager - - return ContestManager( - pg_config=thl_web_rw, - permissions=[ - Permission.CREATE, - Permission.READ, - Permission.UPDATE, - Permission.DELETE, - ], - ) - - -@pytest.fixture(scope="session") -def category_manager(thl_web_rw: PostgresConfig) -> "CategoryManager": - assert thl_web_rw.dsn - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.category import CategoryManager - - return CategoryManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def buyer_manager(thl_web_rw: PostgresConfig) -> "BuyerManager": - # assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.buyer import BuyerManager - - return BuyerManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def survey_manager(thl_web_rw: PostgresConfig): - # assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.survey import SurveyManager - - return SurveyManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def surveystat_manager(thl_web_rw: PostgresConfig): - # assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.survey import SurveyStatManager - - return SurveyStatManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def surveypenalty_manager(thl_redis_config: RedisConfig): - from generalresearch.managers.thl.survey_penalty import SurveyPenaltyManager - - return SurveyPenaltyManager(redis_config=thl_redis_config) - - -@pytest.fixture(scope="session") -def upk_schema_manager(thl_web_rw: PostgresConfig): - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.profiling.schema import ( - UpkSchemaManager, - ) - - return UpkSchemaManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def user_upk_manager(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig): - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.profiling.user_upk import ( - UserUpkManager, - ) - - return UserUpkManager(pg_config=thl_web_rw, redis_config=thl_redis_config) - - -@pytest.fixture(scope="session") -def question_manager(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig): - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.profiling.question import ( - QuestionManager, - ) - - return QuestionManager(pg_config=thl_web_rw) - - -@pytest.fixture(scope="session") -def uqa_manager(thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig): - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - from generalresearch.managers.thl.profiling.uqa import UQAManager - - return UQAManager(redis_config=thl_redis_config, pg_config=thl_web_rw) - - -@pytest.fixture(scope="function") -def uqa_manager_clear_cache(uqa_manager, user: "User"): - # On successive py-test/jenkins runs, the cache may contain - # the previous run's info (keyed under the same user_id) - uqa_manager.clear_cache(user) - yield - uqa_manager.clear_cache(user) - - -@pytest.fixture(scope="session") -def audit_log_manager(thl_web_rw: PostgresConfig) -> "AuditLogManager": +def audit_log_manager(thl_web_rw: PostgresConfig) -> AuditLogManager: assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -451,7 +49,7 @@ def audit_log_manager(thl_web_rw: PostgresConfig) -> "AuditLogManager": @pytest.fixture(scope="session") -def ip_geoname_manager(thl_web_rw: PostgresConfig) -> "IPGeonameManager": +def ip_geoname_manager(thl_web_rw: PostgresConfig) -> IPGeonameManager: assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -461,7 +59,7 @@ def ip_geoname_manager(thl_web_rw: PostgresConfig) -> "IPGeonameManager": @pytest.fixture(scope="session") -def ip_information_manager(thl_web_rw: PostgresConfig) -> "IPInformationManager": +def ip_information_manager(thl_web_rw: PostgresConfig) -> IPInformationManager: assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -473,7 +71,7 @@ def ip_information_manager(thl_web_rw: PostgresConfig) -> "IPInformationManager" @pytest.fixture(scope="session") def ip_record_manager( thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "IPRecordManager": +) -> IPRecordManager: assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -485,7 +83,7 @@ def ip_record_manager( @pytest.fixture(scope="session") def user_iphistory_manager( thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "UserIpHistoryManager": +) -> UserIpHistoryManager: assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -508,7 +106,7 @@ def user_iphistory_manager_clear_cache(user_iphistory_manager, user): @pytest.fixture(scope="session") def geoipinfo_manager( thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig -) -> "GeoIpInfoManager": +) -> GeoIpInfoManager: assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -518,38 +116,6 @@ def geoipinfo_manager( @pytest.fixture(scope="session") -def maxmind_basic_manager(settings: "GRLBaseSettings") -> "MaxmindBasicManager": - from generalresearch.managers.thl.maxmind.basic import ( - MaxmindBasicManager, - ) - - return MaxmindBasicManager( - data_dir="/tmp/", - maxmind_account_id=settings.maxmind_account_id, - maxmind_license_key=settings.maxmind_license_key, - ) - - -@pytest.fixture(scope="session") -def maxmind_manager( - settings: "GRLBaseSettings", - thl_web_rw: PostgresConfig, - thl_redis_config: RedisConfig, -) -> "MaxmindManager": - assert thl_web_rw.dsn.path - assert "/unittest-" in thl_web_rw.dsn.path - - from generalresearch.managers.thl.maxmind import MaxmindManager - - return MaxmindManager( - pg_config=thl_web_rw, - redis_config=thl_redis_config, - maxmind_account_id=settings.maxmind_account_id, - maxmind_license_key=settings.maxmind_license_key, - ) - - -@pytest.fixture(scope="session") def cashout_method_manager(thl_web_rw: PostgresConfig): assert thl_web_rw.dsn.path assert "/unittest-" in thl_web_rw.dsn.path @@ -592,7 +158,6 @@ def uqa_db_index(thl_web_rw: PostgresConfig): # except pymysql.OperationalError as e: # if "Duplicate key name 'idx_user_id'" not in str(e): # raise - return None @pytest.fixture(scope="session") @@ -606,9 +171,7 @@ def delete_cashoutmethod_db(thl_web_rw: PostgresConfig) -> Callable[..., None]: @pytest.fixture(scope="session") -def setup_cashoutmethod_db( - settings: "GRLBaseSettings", cashout_method_manager, delete_cashoutmethod_db -): +def setup_cashoutmethod_db(cashout_method_manager, delete_cashoutmethod_db): delete_cashoutmethod_db() for x in EXAMPLE_TANGO_CASHOUT_METHODS: cashout_method_manager.create(x) @@ -621,14 +184,12 @@ def setup_cashoutmethod_db( # cashout_method_manager.create(AMT_BONUS_CASHOUT_METHOD) raise NotImplementedError("Need to implement setup_cashoutmethod_db") - return None - # === THL: Marketplaces === @pytest.fixture(scope="session") -def spectrum_manager(spectrum_rw: SqlHelper) -> "SpectrumSurveyManager": +def spectrum_manager(spectrum_rw: SqlHelper) -> SpectrumSurveyManager: from generalresearch.managers.spectrum.survey import ( SpectrumSurveyManager, ) @@ -640,7 +201,7 @@ def spectrum_manager(spectrum_rw: SqlHelper) -> "SpectrumSurveyManager": @pytest.fixture(scope="session") def business_manager( gr_db: PostgresConfig, gr_redis_config: RedisConfig -) -> "BusinessManager": +) -> BusinessManager: from generalresearch.redis_helper import RedisConfig assert gr_db.dsn.path @@ -656,7 +217,7 @@ def business_manager( @pytest.fixture(scope="session") -def business_address_manager(gr_db: PostgresConfig) -> "BusinessAddressManager": +def business_address_manager(gr_db: PostgresConfig) -> BusinessAddressManager: assert gr_db.dsn.path assert "/unittest-" in gr_db.dsn.path @@ -668,7 +229,7 @@ def business_address_manager(gr_db: PostgresConfig) -> "BusinessAddressManager": @pytest.fixture(scope="session") def business_bank_account_manager( gr_db: PostgresConfig, -) -> "BusinessBankAccountManager": +) -> BusinessBankAccountManager: assert gr_db.dsn.path assert "/unittest-" in gr_db.dsn.path @@ -680,7 +241,7 @@ def business_bank_account_manager( @pytest.fixture(scope="session") -def team_manager(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> "TeamManager": +def team_manager(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> TeamManager: assert gr_db.dsn.path assert "/unittest-" in gr_db.dsn.path @@ -690,27 +251,7 @@ def team_manager(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> "TeamMa @pytest.fixture(scope="session") -def gr_um(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> "GRUserManager": - assert gr_db.dsn.path - assert "/unittest-" in gr_db.dsn.path - - from generalresearch.managers.gr.authentication import GRUserManager - - return GRUserManager(pg_config=gr_db, redis_config=gr_redis_config) - - -@pytest.fixture(scope="session") -def gr_tm(gr_db: PostgresConfig) -> "GRTokenManager": - assert gr_db.dsn.path - assert "/unittest-" in gr_db.dsn.path - - from generalresearch.managers.gr.authentication import GRTokenManager - - return GRTokenManager(pg_config=gr_db) - - -@pytest.fixture(scope="session") -def membership_manager(gr_db: PostgresConfig) -> "MembershipManager": +def membership_manager(gr_db: PostgresConfig) -> MembershipManager: assert gr_db.dsn.path assert "/unittest-" in gr_db.dsn.path @@ -719,47 +260,8 @@ def membership_manager(gr_db: PostgresConfig) -> "MembershipManager": return MembershipManager(pg_config=gr_db) -# === GRL IQ === - - -@pytest.fixture(scope="session") -def grliq_dm(grliq_db: PostgresConfig) -> "GrlIqDataManager": - assert grliq_db.dsn.path - assert "/unittest-" in grliq_db.dsn.path - - from generalresearch.grliq.managers.forensic_data import ( - GrlIqDataManager, - ) - - return GrlIqDataManager(postgres_config=grliq_db) - - -@pytest.fixture(scope="session") -def grliq_em(grliq_db: PostgresConfig) -> "GrlIqEventManager": - assert grliq_db.dsn.path - assert "/unittest-" in grliq_db.dsn.path - - from generalresearch.grliq.managers.forensic_events import ( - GrlIqEventManager, - ) - - return GrlIqEventManager(postgres_config=grliq_db) - - -@pytest.fixture(scope="session") -def grliq_crr(grliq_db: PostgresConfig) -> "GrlIqCategoryResultsReader": - assert grliq_db.dsn.path - assert "/unittest-" in grliq_db.dsn.path - - from generalresearch.grliq.managers.forensic_results import ( - GrlIqCategoryResultsReader, - ) - - return GrlIqCategoryResultsReader(postgres_config=grliq_db) - - @pytest.fixture(scope="session") -def delete_buyers_surveys(thl_web_rw: PostgresConfig, buyer_manager: "BuyerManager"): +def delete_buyers_surveys(thl_web_rw: PostgresConfig, buyer_manager: BuyerManager): # assert "/unittest-" in thl_web_rw.dsn.path thl_web_rw.execute_write( """ |
