aboutsummaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/grliq/conftest.py174
-rw-r--r--test_utils/managers/conftest.py10
-rw-r--r--test_utils/managers/thl/conftest.py53
-rw-r--r--test_utils/models/conftest.py107
-rw-r--r--test_utils/models/thl/conftest.py308
5 files changed, 409 insertions, 243 deletions
diff --git a/test_utils/grliq/conftest.py b/test_utils/grliq/conftest.py
index bb1a167..f399a99 100644
--- a/test_utils/grliq/conftest.py
+++ b/test_utils/grliq/conftest.py
@@ -27,7 +27,8 @@ if TYPE_CHECKING:
GrlIqEventManager,
)
-# === Miscellaneous ===
+
+# --- Assets ---
@pytest.fixture(scope="function")
@@ -48,18 +49,98 @@ def grliq_db(postgres_instance: PostgresDsn) -> PostgresConfig:
)
-# === Managers ===
+# --- GRLIQ Data ---
@pytest.fixture(scope="session")
-def grliq_dm(grliq_db: PostgresConfig) -> GrlIqDataManager:
+def grliq_data_manager(grliq_db: PostgresConfig) -> GrlIqDataManager:
assert grliq_db.dsn.path
assert "/unittest-" in grliq_db.dsn.path
return GrlIqDataManager(postgres_config=grliq_db)
@pytest.fixture(scope="session")
-def grliq_em(grliq_db: PostgresConfig) -> GrlIqEventManager:
+def grliq_dm(grliq_data_manager: GrlIqDataManager) -> GrlIqDataManager:
+ return grliq_data_manager
+
+
+@pytest.fixture
+def grliq_data_factory(
+ grliq_data_manager: GrlIqDataManager, grliq_data_list: list[dict[str, Any]]
+) -> Callable[..., GrlIqData]:
+
+ def _inner(
+ save: bool = True,
+ is_attempt_allowed: bool = True,
+ product_id: str | None = None,
+ product_user_id: str | None = None,
+ uuid: str | None = None,
+ mid: str | None = None,
+ created_at: datetime | None = None,
+ ) -> GrlIqData:
+ """
+ Creates a dummy record in the db with a GrlIqData (data), GrlIqCheckerResults (result_data),
+ and GrlIqForensicCategoryResult (category_results)
+ :param is_attempt_allowed: Whether the attempt is allowed.
+ :param product_id: product_id of user
+ :param product_user_id: product_user_id of user
+ :param uuid: uuid for the grliq data record
+ :param mid: the thl_session:uuid / mid for the attempt.
+ :return:
+ """
+
+ if save:
+ res: GrlIqData = grliq_data_list[int(is_attempt_allowed)]["data"]
+
+ product_id = product_id or uuid4().hex
+ product_user_id = product_user_id or uuid4().hex
+ uuid = uuid or uuid4().hex
+ mid = mid or uuid4().hex
+ created_at = created_at or datetime.now(tz=UTC)
+
+ res["data"].product_id = product_id
+ res["data"].product_user_id = product_user_id
+ res["data"].uuid = uuid
+ res["data"].mid = mid
+ res["data"].created_at = created_at
+ res["result_data"].uuid = uuid
+ res["category_result"].uuid = uuid
+
+ return grliq_data_manager.create(
+ iq_data=res["data"],
+ result_data=res["result_data"],
+ category_result=res["category_result"],
+ fraud_score=res["category_result"].fraud_score,
+ is_attempt_allowed=res["category_result"].is_attempt_allowed(),
+ )
+ else:
+ raise ValueError("Unsaved GRLIQ Data not supported yet")
+
+ return _inner
+
+
+@pytest.fixture(scope="function")
+def grliq_data(grliq_data_list: list[dict[str, Any]]) -> GrlIqData:
+
+ g: GrlIqData = grliq_data_list[1]["data"]
+
+ g.id = None
+ g.uuid = uuid4().hex
+ g.created_at = datetime.now(tz=UTC)
+ g.timestamp = g.created_at - timedelta(seconds=10)
+ return g
+
+
+@pytest.fixture(scope="function")
+def unsaved_grliq_data(grliq_data_list: list[dict[str, Any]]) -> GrlIqData:
+ raise ValueError("Not supported")
+
+
+# --- GRLIQ Event ---
+
+
+@pytest.fixture(scope="session")
+def grliq_event_manager(grliq_db: PostgresConfig) -> GrlIqEventManager:
assert grliq_db.dsn.path
assert "/unittest-" in grliq_db.dsn.path
@@ -71,16 +152,36 @@ def grliq_em(grliq_db: PostgresConfig) -> GrlIqEventManager:
@pytest.fixture(scope="session")
-def grliq_crr(grliq_db: PostgresConfig) -> GrlIqCategoryResultsReader:
+def grliq_em(grliq_event_manager: GrlIqEventManager) -> GrlIqEventManager:
+ return grliq_event_manager
+
+
+# --- GRLIQ Category Results Reader ---
+
+
+@pytest.fixture(scope="session")
+def grliq_category_results_reader(
+ grliq_db: PostgresConfig,
+) -> GrlIqCategoryResultsReader:
assert grliq_db.dsn.path
assert "/unittest-" in grliq_db.dsn.path
return GrlIqCategoryResultsReader(postgres_config=grliq_db)
+@pytest.fixture(scope="session")
+def grliq_crr(
+ grliq_category_results_reader: GrlIqCategoryResultsReader,
+) -> GrlIqCategoryResultsReader:
+ return grliq_category_results_reader
+
+
# === Models ===
+# === Miscellaneous ===
+
+
@pytest.fixture(scope="session")
def grliq_data_list() -> list[dict[str, Any]]:
return [
@@ -111,66 +212,3 @@ def grliq_data_list() -> list[dict[str, Any]]:
"is_attempt_allowed": True,
},
]
-
-
-@pytest.fixture(scope="function")
-def grliq_data(grliq_data_list: list[dict[str, Any]]) -> GrlIqData:
-
- g: GrlIqData = grliq_data_list[1]["data"]
-
- g.id = None
- g.uuid = uuid4().hex
- g.created_at = datetime.now(tz=UTC)
- g.timestamp = g.created_at - timedelta(seconds=10)
- return g
-
-
-@pytest.fixture
-def grliq_data_factory(
- grliq_dm: GrlIqDataManager, grliq_data_list: list[dict[str, Any]]
-) -> Callable[..., GrlIqData]:
-
- def _inner(
- is_attempt_allowed: bool = True,
- product_id: str | None = None,
- product_user_id: str | None = None,
- uuid: str | None = None,
- mid: str | None = None,
- created_at: datetime | None = None,
- ) -> GrlIqData:
- """
- Creates a dummy record in the db with a GrlIqData (data), GrlIqCheckerResults (result_data),
- and GrlIqForensicCategoryResult (category_results)
- :param is_attempt_allowed: Whether the attempt is allowed.
- :param product_id: product_id of user
- :param product_user_id: product_user_id of user
- :param uuid: uuid for the grliq data record
- :param mid: the thl_session:uuid / mid for the attempt.
- :return:
- """
-
- res: GrlIqData = grliq_data_list[int(is_attempt_allowed)]["data"]
-
- product_id = product_id or uuid4().hex
- product_user_id = product_user_id or uuid4().hex
- uuid = uuid or uuid4().hex
- mid = mid or uuid4().hex
- created_at = created_at or datetime.now(tz=UTC)
-
- res["data"].product_id = product_id
- res["data"].product_user_id = product_user_id
- res["data"].uuid = uuid
- res["data"].mid = mid
- res["data"].created_at = created_at
- res["result_data"].uuid = uuid
- res["category_result"].uuid = uuid
-
- return grliq_dm.create(
- iq_data=res["data"],
- result_data=res["result_data"],
- category_result=res["category_result"],
- fraud_score=res["category_result"].fraud_score,
- is_attempt_allowed=res["category_result"].is_attempt_allowed(),
- )
-
- return _inner
diff --git a/test_utils/managers/conftest.py b/test_utils/managers/conftest.py
index ff088c2..3e7b304 100644
--- a/test_utils/managers/conftest.py
+++ b/test_utils/managers/conftest.py
@@ -56,16 +56,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:
diff --git a/test_utils/managers/thl/conftest.py b/test_utils/managers/thl/conftest.py
index 18a31e2..8ca4383 100644
--- a/test_utils/managers/thl/conftest.py
+++ b/test_utils/managers/thl/conftest.py
@@ -23,6 +23,10 @@ if TYPE_CHECKING:
from generalresearch.config import GRLBaseSettings
from generalresearch.managers.thl.buyer import BuyerManager
from generalresearch.managers.thl.category import CategoryManager
+ from generalresearch.managers.thl.ipinfo import (
+ IPGeonameManager,
+ IPInformationManager,
+ )
from generalresearch.managers.thl.payout import (
BrokerageProductPayoutEventManager,
BusinessPayoutEventManager,
@@ -40,6 +44,10 @@ if TYPE_CHECKING:
from generalresearch.managers.thl.user_manager.user_metadata_manager import (
UserMetadataManager,
)
+ from generalresearch.managers.thl.userhealth import (
+ AuditLogManager,
+ IPRecordManager,
+ )
from generalresearch.managers.thl.wall import (
WallCacheManager,
WallManager,
@@ -153,6 +161,13 @@ def brokerage_product_payout_event_manager(
)
+@pytest.fixture()
+def audit_log_manager(thl_web_rw: PostgresConfig) -> AuditLogManager:
+ from generalresearch.managers.thl.userhealth import AuditLogManager
+
+ return AuditLogManager(pg_config=thl_web_rw)
+
+
@pytest.fixture(scope="session")
def business_payout_event_manager(
thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
@@ -319,3 +334,41 @@ def surveypenalty_manager(thl_redis_config: RedisConfig):
from generalresearch.managers.thl.survey_penalty import SurveyPenaltyManager
return SurveyPenaltyManager(redis_config=thl_redis_config)
+
+
+# --- IP Geolocation ---
+
+
+@pytest.fixture
+def ip_geoname_manager(thl_web_rw: PostgresConfig) -> IPGeonameManager:
+ from generalresearch.managers.thl.ipinfo import IPGeonameManager
+
+ return IPGeonameManager(pg_config=thl_web_rw)
+
+
+# --- IP Information ---
+
+
+@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)
+
+
+# --- IP Record ---
+
+
+@pytest.fixture(scope="session")
+def ip_record_manager(
+ thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
+) -> IPRecordManager:
+ assert thl_web_rw.dsn.path
+ assert "/unittest-" in thl_web_rw.dsn.path
+
+ from generalresearch.managers.thl.userhealth import IPRecordManager
+
+ return IPRecordManager(pg_config=thl_web_rw, redis_config=thl_redis_config)
diff --git a/test_utils/models/conftest.py b/test_utils/models/conftest.py
index d71593f..d5c9a71 100644
--- a/test_utils/models/conftest.py
+++ b/test_utils/models/conftest.py
@@ -10,6 +10,7 @@ from uuid import uuid4
import pytest
from pydantic import AwareDatetime, PositiveInt
+from pytest import FixtureRequest
from pytest import FixtureRequest as Request
from generalresearch.models.definitions import Source
@@ -50,8 +51,6 @@ if TYPE_CHECKING:
)
from generalresearch.models.thl.session import Session, Wall
from generalresearch.models.thl.user import User
- from generalresearch.models.thl.user_iphistory import IPRecord
- from generalresearch.models.thl.userhealth import AuditLog, AuditLogLevel
from generalresearch.pg_helper import PostgresConfig
# === THL ===
@@ -59,15 +58,15 @@ if TYPE_CHECKING:
@pytest.fixture
def user(
- request,
- product_manager: ProductManager,
+ request: FixtureRequest,
user_manager: UserManager,
thl_web_rr: PostgresConfig,
+ product_factory: Callable[..., Product],
) -> User:
product = getattr(request, "product", None)
if product is None:
- product = product_manager.create_dummy()
+ product = product_factory()
u = user_manager.create_dummy(product_id=product.id)
u.prefetch_product(pg_config=thl_web_rr)
@@ -309,31 +308,35 @@ def payout_config(request: Request) -> PayoutConfig:
@pytest.fixture
def product_user_wallet_yes(
- payout_config: PayoutConfig, product_manager: ProductManager
+ product_factory: Callable[..., Product],
+ payout_config: PayoutConfig,
+ product_manager: ProductManager,
) -> Product:
from generalresearch.models.thl.product import UserWalletConfig
- return product_manager.create_dummy(
+ return product_factory(
payout_config=payout_config, user_wallet_config=UserWalletConfig(enabled=True)
)
@pytest.fixture
-def product_user_wallet_no(product_manager: ProductManager) -> Product:
+def product_user_wallet_no(
+ product_factory: Callable[..., Product], product_manager: ProductManager
+) -> Product:
from generalresearch.models.thl.product import UserWalletConfig
- return product_manager.create_dummy(
- user_wallet_config=UserWalletConfig(enabled=False)
- )
+ return product_factory(user_wallet_config=UserWalletConfig(enabled=False))
@pytest.fixture
def product_amt_true(
- product_manager: ProductManager, payout_config: PayoutConfig
+ product_factory: Callable[..., Product],
+ product_manager: ProductManager,
+ payout_config: PayoutConfig,
) -> Product:
from generalresearch.models.thl.product import UserWalletConfig
- return product_manager.create_dummy(
+ return product_factory(
user_wallet_config=UserWalletConfig(amt=True, enabled=True),
payout_config=payout_config,
)
@@ -370,84 +373,6 @@ def bp_payout_factory(
return _inner
-@pytest.fixture
-def audit_log(audit_log_manager: AuditLogManager, user: User) -> AuditLog:
-
- return audit_log_manager.create_dummy(user_id=user.user_id)
-
-
-@pytest.fixture
-def audit_log_factory(
- audit_log_manager: AuditLogManager,
-) -> Callable[..., AuditLog]:
-
- def _inner(
- user_id: PositiveInt,
- level: AuditLogLevel | None = None,
- event_type: str | None = None,
- event_msg: str | None = None,
- event_value: float | None = None,
- ) -> AuditLog:
- return audit_log_manager.create_dummy(
- user_id=user_id,
- level=level,
- event_type=event_type,
- event_msg=event_msg,
- event_value=event_value,
- )
-
- return _inner
-
-
-@pytest.fixture
-def ip_geoname(ip_geoname_manager: IPGeonameManager) -> IPGeoname:
- return ip_geoname_manager.create_dummy()
-
-
-@pytest.fixture
-def ip_information(
- ip_information_manager: IPInformationManager, ip_geoname: IPGeoname
-) -> IPInformation:
- return ip_information_manager.create_dummy(
- geoname_id=ip_geoname.geoname_id, country_iso=ip_geoname.country_iso
- )
-
-
-@pytest.fixture
-def ip_information_factory(
- ip_information_manager: IPInformationManager,
-) -> Callable[..., IPInformation]:
-
- def _inner(ip: str, geoname: IPGeoname, **kwargs) -> IPInformation:
- return ip_information_manager.create_dummy(
- ip=ip,
- geoname_id=geoname.geoname_id,
- country_iso=geoname.country_iso,
- **kwargs,
- )
-
- return _inner
-
-
-@pytest.fixture
-def ip_record(
- ip_record_manager: IPRecordManager, ip_geoname: IPGeoname, user: User
-) -> IPRecord:
-
- return ip_record_manager.create_dummy(user_id=user.user_id)
-
-
-@pytest.fixture
-def ip_record_factory(
- ip_record_manager: IPRecordManager, user: User
-) -> Callable[..., IPRecord]:
-
- def _inner(user_id: PositiveInt, ip: str | None = None) -> IPRecord:
- return ip_record_manager.create_dummy(user_id=user_id, ip=ip)
-
- return _inner
-
-
@pytest.fixture(scope="session")
def buyer(buyer_manager: BuyerManager) -> Buyer:
buyer_code = uuid4().hex
diff --git a/test_utils/models/thl/conftest.py b/test_utils/models/thl/conftest.py
index 5826f0d..14f8f36 100644
--- a/test_utils/models/thl/conftest.py
+++ b/test_utils/models/thl/conftest.py
@@ -62,6 +62,7 @@ if TYPE_CHECKING:
from generalresearch.models.thl.user_iphistory import IPRecord
from generalresearch.models.thl.userhealth import AuditLog
from generalresearch.models.thl.wallet.cashout_method import CashMailOrderData
+ from generalresearch.pg_helper import PostgresConfig
fake = faker.Faker()
@@ -72,30 +73,6 @@ def wall_status() -> Status:
@pytest.fixture
-def user_factory(user_manager: UserManager) -> Callable[..., User]:
-
- def _inner(
- # --- Create dummy "optional" --- #
- product_user_id: str | None = None,
- # --- Optional --- #
- product_id: UUIDStr | None = None,
- product: Product | None = None,
- created: datetime | None = None,
- ) -> User:
-
- product_user_id = product_user_id or uuid4().hex
-
- return user_manager.create_user(
- product_user_id=product_user_id,
- product_id=product_id,
- product=product,
- created=created,
- )
-
- return _inner
-
-
-@pytest.fixture
def wall_factory(
wall_manager: WallManager, session_factory: Session
) -> Callable[..., Wall]:
@@ -155,9 +132,10 @@ def product_factory(product_manager: ProductManager) -> Callable[..., Product]:
def _inner(
save: bool = True,
team: Team | None = None,
+ team_id: UUIDStr | None = None,
business: Business | None = None,
- product_id: UUIDStr | None = None,
business_id: UUIDStr | None = None,
+ product_id: UUIDStr | None = None,
name: str | None = None,
redirect_url: str | None = None,
harmonizer_domain: str | None = None,
@@ -174,8 +152,10 @@ def product_factory(product_manager: ProductManager) -> Callable[..., Product]:
product_id = product_id if product_id else uuid4().hex
- team_id = team.uuid if team else uuid4().hex
- business_id = business.uuid if business else uuid4().hex
+ team_id = (team.uuid if team else None) or team_id or uuid4().hex
+ business_id = (
+ (business.uuid if business else None) or business_id or uuid4().hex
+ )
name = name if name else f"name-{product_id[:12]}"
redirect_url = redirect_url if redirect_url else "https://www.example.com/"
@@ -256,9 +236,12 @@ def session_factory(session_manager: SessionManager):
@pytest.fixture
-def ipgeoname_factory(ipgeoname_manager: IPGeonameManager) -> Callable[..., IPGeoname]:
+def ip_geoname_factory(
+ ip_geoname_manager: IPGeonameManager,
+) -> Callable[..., IPGeoname]:
def _inner(
+ save: bool,
geoname_id: PositiveInt | None = None,
continent_code: str | None = None,
continent_name: str | None = None,
@@ -273,31 +256,47 @@ def ipgeoname_factory(ipgeoname_manager: IPGeonameManager) -> Callable[..., IPGe
time_zone: str | None = None,
is_in_european_union: bool | None = None,
) -> IPGeoname:
-
- return ipgeoname_manager.create(
- geoname_id=geoname_id or randint(1, 999_999_999),
- continent_code=continent_code or "na",
- continent_name=continent_name or "North America",
- country_iso=country_iso or "us",
- country_name=country_name or "United States",
- subdivision_1_iso=subdivision_1_iso or "fl",
- subdivision_1_name=subdivision_1_name or "Florida",
- subdivision_2_iso=subdivision_2_iso,
- subdivision_2_name=subdivision_2_name,
- city_name=city_name,
- metro_code=metro_code,
- time_zone=time_zone,
- is_in_european_union=is_in_european_union,
- )
+ if save:
+ return ip_geoname_manager.create(
+ geoname_id=geoname_id or randint(1, 999_999_999),
+ continent_code=continent_code or "na",
+ continent_name=continent_name or "North America",
+ country_iso=country_iso or "us",
+ country_name=country_name or "United States",
+ subdivision_1_iso=subdivision_1_iso or "fl",
+ subdivision_1_name=subdivision_1_name or "Florida",
+ subdivision_2_iso=subdivision_2_iso,
+ subdivision_2_name=subdivision_2_name,
+ city_name=city_name,
+ metro_code=metro_code,
+ time_zone=time_zone,
+ is_in_european_union=is_in_european_union,
+ )
+ else:
+ raise ValueError("Unsaved IPGeoname not yet supported")
return _inner
-def ipinformation_factory(
+@pytest.fixture()
+def ip_geoname(ip_geoname_factory: Callable[..., IPGeoname]) -> IPGeoname:
+ return ip_geoname_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_ip_geoname(ip_geoname_factory: Callable[..., IPGeoname]) -> IPGeoname:
+ return ip_geoname_factory(save=True)
+
+
+# --- IP Information ---
+
+
+def ip_information_factory(
ipinformation_manager: IPInformationManager,
) -> Callable[..., IPInformation]:
def _inner(
+ save: bool = True,
ip: IPvAnyAddressStr | None = None,
geoname_id: PositiveInt | None = None,
country_iso: str | None = None,
@@ -324,36 +323,184 @@ def ipinformation_factory(
accuracy_radius: int | None = None,
) -> IPInformation:
- return ipinformation_manager.create(
- ip=ip or fake.ipv4_public(),
- geoname_id=geoname_id,
- country_iso=country_iso or fake.country_code(),
- registered_country_iso=registered_country_iso,
- is_anonymous=is_anonymous,
- is_anonymous_vpn=is_anonymous_vpn,
- is_hosting_provider=is_hosting_provider,
- is_public_proxy=is_public_proxy,
- is_tor_exit_node=is_tor_exit_node,
- is_residential_proxy=is_residential_proxy,
- autonomous_system_number=autonomous_system_number,
- autonomous_system_organization=autonomous_system_organization,
- domain=domain,
- isp=isp,
- mobile_country_code=mobile_country_code,
- mobile_network_code=mobile_network_code,
- network=network,
- organization=organization,
- static_ip_score=static_ip_score,
- user_type=user_type,
- postal_code=postal_code,
- latitude=latitude,
- longitude=longitude,
- accuracy_radius=accuracy_radius,
- )
+ if save:
+ return ipinformation_manager.create(
+ ip=ip or fake.ipv4_public(),
+ geoname_id=geoname_id,
+ country_iso=country_iso or fake.country_code(),
+ registered_country_iso=registered_country_iso,
+ is_anonymous=is_anonymous,
+ is_anonymous_vpn=is_anonymous_vpn,
+ is_hosting_provider=is_hosting_provider,
+ is_public_proxy=is_public_proxy,
+ is_tor_exit_node=is_tor_exit_node,
+ is_residential_proxy=is_residential_proxy,
+ autonomous_system_number=autonomous_system_number,
+ autonomous_system_organization=autonomous_system_organization,
+ domain=domain,
+ isp=isp,
+ mobile_country_code=mobile_country_code,
+ mobile_network_code=mobile_network_code,
+ network=network,
+ organization=organization,
+ static_ip_score=static_ip_score,
+ user_type=user_type,
+ postal_code=postal_code,
+ latitude=latitude,
+ longitude=longitude,
+ accuracy_radius=accuracy_radius,
+ )
+ else:
+ raise ValueError("Unsaved IP Information not supported yet")
+
+ return _inner
+
+
+@pytest.fixture
+def ip_information(
+ ip_information_factory: Callable[..., IPInformation],
+) -> IPInformation:
+ return ip_information_factory(save=True)
+
+
+@pytest.fixture
+def unsaved_ip_information(
+ ip_information_factory: Callable[..., IPInformation],
+) -> IPInformation:
+ return ip_information_factory(save=False)
+
+
+# --- IP Record ---
+
+
+@pytest.fixture
+def ip_record_factory(
+ ip_record_manager: IPRecordManager, user: User
+) -> Callable[..., IPRecord]:
+ # return ip_record_manager.create_dummy(user_id=user.user_id)
+
+ # def create_dummy(
+ # self,
+ # user_id: PositiveInt,
+ # ip: IPvAnyAddressStr | None = None,
+ # forwarded_ip1: IPvAnyAddressStr | None = None,
+ # forwarded_ip2: IPvAnyAddressStr | None = None,
+ # forwarded_ip3: IPvAnyAddressStr | None = None,
+ # forwarded_ip4: IPvAnyAddressStr | None = None,
+ # forwarded_ip5: IPvAnyAddressStr | None = None,
+ # forwarded_ip6: IPvAnyAddressStr | None = None,
+ # ) -> IPRecord:
+ # return self.create(
+ # user_id=user_id,
+ # ip=ip or fake.ipv4_public(),
+ # forwarded_ip1=(forwarded_ip1 or fake.ipv4_public()),
+ # forwarded_ip2=(forwarded_ip2 or fake.ipv6() if random() < 0.5 else None),
+ # forwarded_ip3=(
+ # forwarded_ip3 or fake.ipv4_public() if random() < 0.25 else None
+ # ),
+ # forwarded_ip4=forwarded_ip4,
+ # forwarded_ip5=forwarded_ip5,
+ # forwarded_ip6=forwarded_ip6,
+ # )
+
+ def _inner(
+ user_id: PositiveInt, save: bool = True, ip: str | None = None
+ ) -> IPRecord:
+ if save:
+ return ip_record_manager.create_dummy(user_id=user_id, ip=ip)
+ else:
+ raise ValueError("Unsaved IP Record not supported")
return _inner
+@pytest.fixture()
+def ip_record(
+ ip_record_manager: IPRecordManager, ip_geoname: IPGeoname, user: User
+) -> IPRecord:
+ return ip_record_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_ip_record(ip_record_factory: Callable[..., IPRecord]) -> IPRecord:
+ return ip_record_factory(save=False)
+
+
+# --- User ---
+
+
+@pytest.fixture()
+def user_factory(
+ user_manager: UserManager, thl_web_rr: PostgresConfig
+) -> Callable[..., User]:
+
+ def _inner(
+ save: bool = True,
+ # --- Create dummy "optional" --- #
+ product_user_id: str | None = None,
+ # --- Optional --- #
+ product_id: UUIDStr | None = None,
+ product: Product | None = None,
+ created: datetime | None = None,
+ ) -> User:
+ if save:
+ if product is None:
+ product = product_factory()
+
+ product_user_id = product_user_id or uuid4().hex
+
+ u = user_manager.create_user(
+ product_user_id=product_user_id,
+ product_id=product_id,
+ product=product,
+ created=created,
+ )
+
+ u = user_manager.create_dummy(product=product, created=created)
+
+ u.prefetch_product(pg_config=thl_web_rr)
+ return u
+
+ else:
+ raise ValueError("Unsaved User not supported")
+
+ return _inner
+
+
+@pytest.fixture()
+def user(
+ user_factory: Callable[..., User],
+) -> User:
+ return user_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_user(
+ user_factory: Callable[..., User],
+) -> User:
+ return user_factory(save=False)
+
+
+@pytest.fixture
+def user_with_wallet(
+ user_factory: Callable[..., User],
+ product_user_wallet_yes: Product,
+) -> User:
+ # A user on a product with user wallet enabled, but they have no money
+ return user_factory(save=True, product=product_user_wallet_yes)
+
+
+@pytest.fixture
+def user_with_wallet_amt(
+ 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(save=True, product=product_amt_true)
+
+
+# --- User Payout ---
+
+
@pytest.fixture
def user_payout_event_factory(
user_payout_event_manager: UserPayoutEventManager,
@@ -437,11 +584,11 @@ def iprecord_factory(iprecord_manager: IPRecordManager) -> Callable[..., IPRecor
return _inner
-# class AuditLogManager(PostgresManager):
+# --- Audit Log Manager ---
-@pytest.fixture
-def auditlog_factory(audit_log_manager: AuditLogManager):
+@pytest.fixture()
+def audit_log_factory(audit_log_manager: AuditLogManager) -> Callable[..., AuditLog]:
def _inner(
user_id: PositiveInt,
@@ -468,6 +615,19 @@ def auditlog_factory(audit_log_manager: AuditLogManager):
return _inner
+@pytest.fixture()
+def audit_log(auditlog_factory: Callable[..., AuditLog]) -> AuditLog:
+ return auditlog_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_audit_log(auditlog_factory: Callable[..., AuditLog]) -> AuditLog:
+ return auditlog_factory(save=False)
+
+
+# --- ---
+
+
@pytest.fixture(scope="session")
def profiling_info_json() -> str:
return (