aboutsummaryrefslogtreecommitdiff
path: root/test_utils/managers/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils/managers/conftest.py')
-rw-r--r--test_utils/managers/conftest.py269
1 files changed, 125 insertions, 144 deletions
diff --git a/test_utils/managers/conftest.py b/test_utils/managers/conftest.py
index d2e5d20..391e6bf 100644
--- a/test_utils/managers/conftest.py
+++ b/test_utils/managers/conftest.py
@@ -1,39 +1,42 @@
from __future__ import annotations
-from typing import Callable
+import random
+from collections.abc import Callable
+from datetime import datetime
+from typing import TYPE_CHECKING
+from uuid import uuid4
import pytest
-from generalresearch.managers.gr.business import (
- BusinessAddressManager,
- BusinessBankAccountManager,
- BusinessManager,
+from generalresearch.managers.thl.cashout_method import (
+ CashoutMethodManager,
)
-from generalresearch.managers.gr.team import (
- MembershipManager,
- TeamManager,
+from generalresearch.managers.thl.user_streak import (
+ UserStreakManager,
)
-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
-from test_utils.managers.cashout_methods import (
- EXAMPLE_TANGO_CASHOUT_METHODS,
+from generalresearch.models.definitions import Source
+from generalresearch.models.thl.wallet.cashout_method import (
+ CashoutMethod,
+ TangoCashoutMethodData,
)
+from generalresearch.models.thl.wallet.definitions import Currency, PayoutType
+
+if TYPE_CHECKING:
+ from generalresearch.managers.spectrum.survey import SpectrumSurveyManager
+ from generalresearch.managers.thl.buyer import BuyerManager
+ from generalresearch.managers.thl.ipinfo import (
+ GeoIpInfoManager,
+ IPGeonameManager,
+ )
+ from generalresearch.managers.thl.userhealth import (
+ AuditLogManager,
+ IPRecordManager,
+ UserIpHistoryManager,
+ )
+ 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
# === THL ===
@@ -59,16 +62,6 @@ def ip_geoname_manager(thl_web_rw: PostgresConfig) -> IPGeonameManager:
@pytest.fixture(scope="session")
-def ip_information_manager(thl_web_rw: PostgresConfig) -> IPInformationManager:
- assert thl_web_rw.dsn.path
- assert "/unittest-" in thl_web_rw.dsn.path
-
- from generalresearch.managers.thl.ipinfo import IPInformationManager
-
- return IPInformationManager(pg_config=thl_web_rw)
-
-
-@pytest.fixture(scope="session")
def ip_record_manager(
thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
) -> IPRecordManager:
@@ -95,7 +88,7 @@ def user_iphistory_manager(
@pytest.fixture(scope="function")
-def user_iphistory_manager_clear_cache(user_iphistory_manager, user):
+def user_iphistory_manager_clear_cache(user_iphistory_manager, user: User):
# On successive py-test/jenkins runs, the cache may contain
# the previous run's info (keyed under the same user_id)
user_iphistory_manager.delete_user_ip_history_cache(user_id=user.user_id)
@@ -116,12 +109,9 @@ def geoipinfo_manager(
@pytest.fixture(scope="session")
-def cashout_method_manager(thl_web_rw: PostgresConfig):
+def cashout_method_manager(thl_web_rw: PostgresConfig) -> CashoutMethodManager:
assert thl_web_rw.dsn.path
assert "/unittest-" in thl_web_rw.dsn.path
- from generalresearch.managers.thl.cashout_method import (
- CashoutMethodManager,
- )
return CashoutMethodManager(pg_config=thl_web_rw)
@@ -134,12 +124,9 @@ def event_manager(thl_redis_config: RedisConfig):
@pytest.fixture(scope="session")
-def user_streak_manager(thl_web_rw: PostgresConfig):
+def user_streak_manager(thl_web_rw: PostgresConfig) -> UserStreakManager:
assert thl_web_rw.dsn.path
assert "/unittest-" in thl_web_rw.dsn.path
- from generalresearch.managers.thl.user_streak import (
- UserStreakManager,
- )
return UserStreakManager(pg_config=thl_web_rw)
@@ -171,123 +158,117 @@ def delete_cashoutmethod_db(thl_web_rw: PostgresConfig) -> Callable[..., None]:
@pytest.fixture(scope="session")
-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)
-
- # 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")
-
-
-# === THL: Marketplaces ===
+def setup_cashoutmethod_db(
+ cashout_method_manager: CashoutMethodManager,
+ delete_cashoutmethod_db: Callable[..., None],
+ example_tango_cashout_methods: list[CashoutMethod],
+) -> Callable[..., None]:
+ def _inner():
+ delete_cashoutmethod_db()
-@pytest.fixture(scope="session")
-def spectrum_manager(spectrum_rw: SqlHelper) -> SpectrumSurveyManager:
- from generalresearch.managers.spectrum.survey import (
- SpectrumSurveyManager,
- )
+ for x in example_tango_cashout_methods:
+ cashout_method_manager.create(x)
- return SpectrumSurveyManager(sql_helper=spectrum_rw)
+ return _inner
-# === GR ===
@pytest.fixture(scope="session")
-def business_manager(
- gr_db: PostgresConfig, gr_redis_config: RedisConfig
-) -> BusinessManager:
- from generalresearch.redis_helper import RedisConfig
+def random_ext_id_factory(base: str = "U02") -> Callable[..., str]:
- assert gr_db.dsn.path
- assert "/unittest-" in gr_db.dsn.path
- assert isinstance(gr_redis_config, RedisConfig)
+ def _inner() -> str:
+ suffix = random.randint(0, 99999)
+ return f"{base}{suffix:05d}"
- from generalresearch.managers.gr.business import BusinessManager
-
- return BusinessManager(
- pg_config=gr_db,
- redis_config=gr_redis_config,
- )
+ return _inner
@pytest.fixture(scope="session")
-def business_address_manager(gr_db: PostgresConfig) -> BusinessAddressManager:
- assert gr_db.dsn.path
- assert "/unittest-" in gr_db.dsn.path
+def example_tango_cashout_methods(
+ random_ext_id_factory: Callable[..., str],
+) -> list[CashoutMethod]:
+ return [
+ CashoutMethod(
+ id=uuid4().hex,
+ last_updated=datetime.fromisoformat("2021-06-23T20:45:38.239182Z"),
+ is_live=True,
+ type=PayoutType.TANGO,
+ ext_id='U025035',
+ name="Safeway eGift Card $25",
+ data=TangoCashoutMethodData(
+ value_type="fixed", countries=["US"], utid='U025035'
+ ),
+ user=None,
+ image_url="https://d30s7yzk2az89n.cloudfront.net/images/brands/b694446-1200w-326ppi.png",
+ original_currency=Currency.USD,
+ min_value=2500,
+ max_value=2500,
+ ),
+ CashoutMethod(
+ id=uuid4().hex,
+ last_updated=datetime.fromisoformat("2021-06-23T20:45:38.239182Z"),
+ is_live=True,
+ type=PayoutType.TANGO,
+ ext_id='U006961',
+ name="Amazon.it Gift Certificate",
+ data=TangoCashoutMethodData(
+ value_type="variable", countries=["IT"], utid="U006961"
+ ),
+ user=None,
+ image_url="https://d30s7yzk2az89n.cloudfront.net/images/brands/b405753-1200w-326ppi.png",
+ original_currency=Currency.EUR,
+ min_value=1,
+ max_value=10000,
+ ),
+ ]
- from generalresearch.managers.gr.business import BusinessAddressManager
- return BusinessAddressManager(pg_config=gr_db)
+# === THL: Marketplaces ===
@pytest.fixture(scope="session")
-def business_bank_account_manager(
- gr_db: PostgresConfig,
-) -> BusinessBankAccountManager:
- assert gr_db.dsn.path
- assert "/unittest-" in gr_db.dsn.path
-
- from generalresearch.managers.gr.business import (
- BusinessBankAccountManager,
+def spectrum_survey_manager(spectrum_rw: SqlHelper) -> SpectrumSurveyManager:
+ from generalresearch.managers.spectrum.survey import (
+ SpectrumSurveyManager,
)
- return BusinessBankAccountManager(pg_config=gr_db)
-
-
-@pytest.fixture(scope="session")
-def team_manager(gr_db: PostgresConfig, gr_redis_config: RedisConfig) -> TeamManager:
- assert gr_db.dsn.path
- assert "/unittest-" in gr_db.dsn.path
-
- from generalresearch.managers.gr.team import TeamManager
-
- return TeamManager(pg_config=gr_db, redis_config=gr_redis_config)
+ return SpectrumSurveyManager(sql_helper=spectrum_rw)
@pytest.fixture(scope="session")
-def membership_manager(gr_db: PostgresConfig) -> MembershipManager:
- assert gr_db.dsn.path
- assert "/unittest-" in gr_db.dsn.path
-
- from generalresearch.managers.gr.team import MembershipManager
-
- return MembershipManager(pg_config=gr_db)
+def delete_buyers_surveys(
+ thl_web_rw: PostgresConfig, buyer_manager: BuyerManager
+) -> Callable[..., None]:
+ def _inner():
+ # assert "/unittest-" in thl_web_rw.dsn.path
+ thl_web_rw.execute_write(
+ """
+ DELETE FROM marketplace_surveystat
+ WHERE survey_id IN (
+ SELECT id
+ FROM marketplace_survey
+ WHERE source = %(source)s
+ );""",
+ params={"source": Source.TESTING.value},
+ )
+ thl_web_rw.execute_write(
+ """
+ DELETE FROM marketplace_survey
+ WHERE buyer_id IN (
+ SELECT id
+ FROM marketplace_buyer
+ WHERE source = %(source)s
+ );""",
+ params={"source": Source.TESTING.value},
+ )
+ thl_web_rw.execute_write(
+ """
+ DELETE from marketplace_buyer
+ WHERE source=%(source)s;
+ """,
+ params={"source": Source.TESTING.value},
+ )
+ buyer_manager.populate_caches()
-@pytest.fixture(scope="session")
-def delete_buyers_surveys(thl_web_rw: PostgresConfig, buyer_manager: BuyerManager):
- # assert "/unittest-" in thl_web_rw.dsn.path
- thl_web_rw.execute_write(
- """
- DELETE FROM marketplace_surveystat
- WHERE survey_id IN (
- SELECT id
- FROM marketplace_survey
- WHERE source = %(source)s
- );""",
- params={"source": Source.TESTING.value},
- )
- thl_web_rw.execute_write(
- """
- DELETE FROM marketplace_survey
- WHERE buyer_id IN (
- SELECT id
- FROM marketplace_buyer
- WHERE source = %(source)s
- );""",
- params={"source": Source.TESTING.value},
- )
- thl_web_rw.execute_write(
- """
- DELETE from marketplace_buyer
- WHERE source=%(source)s;
- """,
- params={"source": Source.TESTING.value},
- )
- buyer_manager.populate_caches()
+ return _inner