aboutsummaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorMax Nanis2026-09-01 16:58:01 -0700
committerMax Nanis2026-09-01 16:58:01 -0700
commit4e9e08718884b1c4394d16055ba3f30c790ef8d0 (patch)
treea8c0c40ac5ac92d90c7cdfdda31c34ddf1e62d79 /test_utils
parentfdfd6dbd2b71b0cf11741915620dca181fdc7bb0 (diff)
downloadgeneralresearch-4e9e08718884b1c4394d16055ba3f30c790ef8d0.tar.gz
generalresearch-4e9e08718884b1c4394d16055ba3f30c790ef8d0.zip
Latest state for Django Migrations / Discussion
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/conftest.py51
-rw-r--r--test_utils/managers/gr/conftest.py2
-rw-r--r--test_utils/managers/thl/conftest.py34
-rw-r--r--test_utils/models/gr/conftest.py55
4 files changed, 88 insertions, 54 deletions
diff --git a/test_utils/conftest.py b/test_utils/conftest.py
index daf6b43..44e36a6 100644
--- a/test_utils/conftest.py
+++ b/test_utils/conftest.py
@@ -225,8 +225,10 @@ def django_db_factory(
_ran = {}
import django
+ from django.apps import apps
from django.conf import settings as django_settings
from django.core.management import call_command
+ from django.utils.functional import empty
def _inner(
django_project: str = "generalresearch.thl_django",
@@ -242,34 +244,43 @@ def django_db_factory(
# We need model files that are NOT in this repo.
gr_path = gr_repo()
sys.path.insert(0, str(gr_path))
+ print("DJANGO_PROJECT_PATH", str(gr_path), sys.path)
# 1. Bootstrapping Django settings
- if not django_settings.configured:
- django_settings.configure(
- DATABASES={
- "default": {
- "ENGINE": "django.db.backends.postgresql",
- "NAME": postgres_instance_dict["name"],
- "USER": postgres_instance_dict["username"],
- "PASSWORD": postgres_instance_dict["password"],
- "HOST": postgres_instance_dict["host"],
- "PORT": postgres_instance_dict["port"],
- }
- },
- INSTALLED_APPS=[
- "django.contrib.postgres",
- "django.contrib.contenttypes",
- django_project,
- ],
- )
+ # if not django_settings.configured:
+ # 1. Reset the lazy wrapper back to an empty state
+ # if not django_settings.configured:
+
+ django_settings._wrapped = empty
+
+ django_settings.configure(
+ DATABASES={
+ "default": {
+ "ENGINE": "django.db.backends.postgresql",
+ "NAME": postgres_instance_dict["name"],
+ "USER": postgres_instance_dict["username"],
+ "PASSWORD": postgres_instance_dict["password"],
+ "HOST": postgres_instance_dict["host"],
+ "PORT": postgres_instance_dict["port"],
+ }
+ },
+ INSTALLED_APPS=[
+ "django.contrib.postgres",
+ "django.contrib.contenttypes",
+ django_project,
+ ],
+ )
django.setup()
- # for model in apps.get_models():
- # print(f"Discovered model: {model._meta.label}")
+ for model in apps.get_models():
+ print(f"Discovered model: {model._meta.label}")
# 2. Run migrations directly during fixture activation
+ print("DJANGO_PROJECT", django_project)
if "gr" in django_project:
call_command("makemigrations", "common", interactive=False)
+ else:
+ call_command("makemigrations", interactive=False)
call_command("migrate")
diff --git a/test_utils/managers/gr/conftest.py b/test_utils/managers/gr/conftest.py
index a7fa9e9..b5db2a5 100644
--- a/test_utils/managers/gr/conftest.py
+++ b/test_utils/managers/gr/conftest.py
@@ -24,6 +24,8 @@ if TYPE_CHECKING:
# === Msc ===
+
+
@pytest.fixture(scope="session")
def gr_redis_config_db() -> str:
return str(randint(99, 1_023))
diff --git a/test_utils/managers/thl/conftest.py b/test_utils/managers/thl/conftest.py
index 391b74c..6e19bef 100644
--- a/test_utils/managers/thl/conftest.py
+++ b/test_utils/managers/thl/conftest.py
@@ -45,20 +45,7 @@ if TYPE_CHECKING:
WallManager,
)
-
-@pytest.fixture(scope="session")
-def thl_web_rr(django_db_factory: Callable[..., PostgresDsn]) -> PostgresConfig:
-
- return PostgresConfig(
- dsn=django_db_factory("generalresearch.thl_django"),
- connect_timeout=1,
- statement_timeout=5,
- )
-
-
-@pytest.fixture(scope="session")
-def thl_web_rw(thl_web_rr: PostgresConfig) -> PostgresConfig:
- return thl_web_rr
+# === Msc ===
@pytest.fixture(scope="session")
@@ -98,6 +85,25 @@ def thl_redis_config(
@pytest.fixture(scope="session")
+def thl_web_rr(django_db_factory: Callable[..., PostgresDsn]) -> PostgresConfig:
+ _dsn = django_db_factory("generalresearch.thl_django")
+
+ return PostgresConfig(
+ dsn=_dsn,
+ connect_timeout=1,
+ statement_timeout=5,
+ )
+
+
+@pytest.fixture(scope="session")
+def thl_web_rw(thl_web_rr: PostgresConfig) -> PostgresConfig:
+ return thl_web_rr
+
+
+# === Managers ===
+
+
+@pytest.fixture(scope="session")
def payout_event_manager(
thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
) -> PayoutEventManager:
diff --git a/test_utils/models/gr/conftest.py b/test_utils/models/gr/conftest.py
index b87f3bb..a73dd70 100644
--- a/test_utils/models/gr/conftest.py
+++ b/test_utils/models/gr/conftest.py
@@ -66,36 +66,59 @@ def gr_user_cache(
return gr_user
+# --- Business Bank Account ---
+
+
@pytest.fixture
def gr_business_bank_account_factory(
- gr_bbam: BusinessBankAccountManager,
+ gr_business_bank_account_manager: BusinessBankAccountManager,
) -> Callable[..., BusinessBankAccount]:
def _inner(
business_id: PositiveInt,
+ save: bool = True,
uuid: UUIDStr | None = None,
transfer_method: TransferMethod | None = None,
account_number: str | None = None,
routing_number: str | None = None,
iban: str | None = None,
swift: str | None = None,
- ):
- from generalresearch.models.gr.business import TransferMethod
+ **kwargs,
+ ) -> BusinessBankAccount:
- return gr_bbam.create(
- business_id=business_id,
- uuid=uuid or uuid4().hex,
- transfer_method=transfer_method or TransferMethod.ACH,
- account_number=account_number or uuid4().hex[:6],
- routing_number=routing_number or uuid4().hex[:6],
- iban=iban or uuid4().hex[:6],
- swift=swift or uuid4().hex[:6],
- )
+ if save:
+ return gr_business_bank_account_manager.create(
+ business_id=business_id,
+ uuid=uuid or uuid4().hex,
+ transfer_method=transfer_method or TransferMethod.ACH,
+ account_number=account_number or uuid4().hex[:6],
+ routing_number=routing_number or uuid4().hex[:6],
+ iban=iban or uuid4().hex[:6],
+ swift=swift or uuid4().hex[:6],
+ **kwargs,
+ )
+ else:
+ raise ValueError("BusinessBankAccount Business not supported yet")
return _inner
@pytest.fixture
+def gr_business_bank_account(gr_business_factory: Callable[..., Business]) -> Business:
+ return gr_business_factory(save=True)
+
+
+@pytest.fixture
+def unsaved_gr_business_bank_account(
+ gr_business_factory: Callable[..., Business],
+) -> Business:
+ return gr_business_factory(save=False)
+
+
+# -----------------
+
+
+@pytest.fixture
def gr_business_address_factory(
gr_bam: BusinessAddressManager,
) -> Callable[..., BusinessAddress]:
@@ -204,14 +227,6 @@ def business_address(
return business_address_manager.create_dummy(business_id=gr_business.id)
-@pytest.fixture
-def business_bank_account(
- gr_business: Business,
- business_bank_account_manager: BusinessBankAccountManager,
-) -> BusinessBankAccount:
- return business_bank_account_manager.create_dummy(business_id=gr_business.id)
-
-
@pytest.fixture()
def gr_user_token_header(gr_user_token: GRToken) -> dict[str, str]:
return gr_user_token.auth_header