From 6df4d8a8d66c7e8071ef25c783a89b34a5671701 Mon Sep 17 00:00:00 2001 From: stuppie Date: Tue, 13 Oct 2026 14:50:37 -0700 Subject: pytest fixtures django_db_factory using gr in this project --- test_utils/conftest.py | 76 +++----------------------------------- test_utils/managers/gr/conftest.py | 2 +- tests/models/gr/test_base.py | 33 +---------------- 3 files changed, 9 insertions(+), 102 deletions(-) diff --git a/test_utils/conftest.py b/test_utils/conftest.py index cd3fd45..450c90e 100644 --- a/test_utils/conftest.py +++ b/test_utils/conftest.py @@ -2,7 +2,6 @@ from __future__ import annotations import os import shutil -import stat import subprocess import sys from collections.abc import Callable, Generator @@ -155,66 +154,6 @@ def postgres_instance_host( yield value -@pytest.fixture(scope="session") -def git_key_path( - tmp_path_factory: TempPathFactory, - settings: GRLBaseSettings, -) -> Generator[Path]: - # We are using the tmp_path_factory because unlike the tmp_path (which - # is function scoped), this is session scoped. - - assert settings.git_creds, "Must define key to download alternative models" - fn = tmp_path_factory.mktemp("keys") / "git_creds" - key_content = settings.git_creds.replace("\\n", "\n") - fn.write_text(key_content, encoding="utf-8") - os.chmod(fn, stat.S_IRUSR | stat.S_IWUSR) - - yield Path(fn) - - os.unlink(fn) - - -@pytest.fixture(scope="session") -def gr_repo( - git_key_path: Path, - tmp_path_factory: TempPathFactory, -) -> Callable[..., Path | None]: - repo_url = "ssh://code.g-r-l.com:6611/general-research/gr-carer.git" - - _ran = {} - - fn = tmp_path_factory.mktemp("repos") - repo_path = fn / "gr-carer" - - def _inner() -> Path: - - if _ran.get(repo_url, False): - print(f"Already ran django_db_factory.{repo_url}") - return repo_path - - _ran[repo_url] = True - - ssh_cmd = ( - f'ssh -i "{git_key_path}" ' - "-o IdentitiesOnly=yes " - "-o StrictHostKeyChecking=no " - ) - env = {**os.environ, "GIT_SSH_COMMAND": ssh_cmd} - - if repo_path.exists(): - subprocess.run(["git", "-C", str(repo_path), "pull"], check=True, env=env) - else: - subprocess.run( - ["git", "clone", "--depth", "1", repo_url, str(repo_path)], - check=True, - env=env, - ) - - return repo_path - - return _inner - - @pytest.fixture(scope="session") def django_settings_file( postgres_instance_dict: PostgresDict, @@ -259,17 +198,14 @@ USE_TZ = True @pytest.fixture(scope="session") def django_db_factory( postgres_instance: PostgresDsn, - gr_repo: Callable[..., Path], django_settings_file: Callable[..., tuple[str, Path]], - postgres_instance_dict: PostgresDict, - tmp_path_factory: TempPathFactory, -) -> Callable[..., PostgresDsn | None]: +) -> Callable[..., PostgresDsn]: _ran = {} def _inner( django_project: str = "generalresearch.thl_django", - ) -> PostgresDsn | None: + ) -> PostgresDsn: if _ran.get(django_project, False): print(f"Already ran django_db_factory:{django_project}") @@ -285,11 +221,11 @@ def django_db_factory( ], ) - elif django_project == "gr.common": - _cwd = gr_repo() - _manage_path = "gr.app.manage" + elif django_project == "generalresearch.gr_django": + _cwd = None + _manage_path = "generalresearch.gr_django.app.manage" _settings_module, _settings_dir = django_settings_file( - extra_installed_apps=["gr.common"] + extra_installed_apps=["generalresearch.gr_django"] ) else: diff --git a/test_utils/managers/gr/conftest.py b/test_utils/managers/gr/conftest.py index 09e08f5..9a0654a 100644 --- a/test_utils/managers/gr/conftest.py +++ b/test_utils/managers/gr/conftest.py @@ -67,7 +67,7 @@ def gr_redis_config( @pytest.fixture(scope="session") def gr_db(django_db_factory: Callable[..., PostgresDsn]) -> PostgresConfig: - _dsn = django_db_factory("gr.common") + _dsn = django_db_factory("generalresearch.gr_django") return PostgresConfig( dsn=_dsn, diff --git a/tests/models/gr/test_base.py b/tests/models/gr/test_base.py index 5ab5dff..d312501 100644 --- a/tests/models/gr/test_base.py +++ b/tests/models/gr/test_base.py @@ -1,41 +1,12 @@ -from __future__ import annotations - -import subprocess from collections.abc import Callable -from pathlib import Path -from typing import TYPE_CHECKING -import pytest from pydantic import PostgresDsn -if TYPE_CHECKING: - from generalresearch.pg_helper import PostgresConfig - class TestGRPostgresDjangoCreation: - - def test_git(self, gr_repo: Callable[..., Path]): - repo_path = gr_repo() - - try: - # Run the git command inside the target directory - result = subprocess.run( - ["git", "rev-parse", "--is-inside-work-tree"], - cwd=repo_path, - capture_output=True, - text=True, - check=True, - ) - # Check if the output string is exactly "true" - assert result.stdout.strip() == "true" - - except (subprocess.CalledProcessError, FileNotFoundError) as e: - pytest.fail(f"Directory is not a Git repo or Git is not installed: {e}") - def test_django_creation( self, - django_db_factory: Callable[..., None], + django_db_factory: Callable[..., PostgresDsn], ): - - dsn = django_db_factory("gr.common") + dsn = django_db_factory("generalresearch.gr_django") assert isinstance(dsn, PostgresDsn) -- cgit v1.2.3 From 32e306c94adc134d4c32d7f67573e7b66985806a Mon Sep 17 00:00:00 2001 From: stuppie Date: Tue, 13 Oct 2026 14:55:33 -0700 Subject: BusinessCreate.model_rebuild() and fix imports --- generalresearch/models/gr/__init__.py | 6 ++++-- generalresearch/models/gr/business.py | 19 +++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/generalresearch/models/gr/__init__.py b/generalresearch/models/gr/__init__.py index 7e1516b..132f72b 100644 --- a/generalresearch/models/gr/__init__.py +++ b/generalresearch/models/gr/__init__.py @@ -1,13 +1,15 @@ from generalresearch.models.gr.authentication import GRToken, GRUser -from generalresearch.models.gr.business import Business +from generalresearch.models.gr.business import Business, BusinessCreate from generalresearch.models.gr.team import Team from generalresearch.models.thl.finance import BusinessBalances from generalresearch.models.thl.payout import BrokerageProductPayoutEvent from generalresearch.models.thl.product import Product -_ = Business, Product, BrokerageProductPayoutEvent, BusinessBalances +# To prevent type checkers from removing these imports from this file +_ = Product, BrokerageProductPayoutEvent, BusinessBalances GRUser.model_rebuild() GRToken.model_rebuild() +BusinessCreate.model_rebuild() Business.model_rebuild() Team.model_rebuild() diff --git a/generalresearch/models/gr/business.py b/generalresearch/models/gr/business.py index 5ab819f..efda584 100644 --- a/generalresearch/models/gr/business.py +++ b/generalresearch/models/gr/business.py @@ -19,12 +19,10 @@ from pydantic import ( Field, PositiveInt, ValidationError, - computed_field, ) from pydantic.json_schema import SkipJsonSchema from pydantic_extra_types.phone_numbers import PhoneNumber -from generalresearch.currency import USDCent from generalresearch.decorators import LOG from generalresearch.incite.schemas.mergers.pop_ledger import ( numerical_col_names, @@ -42,16 +40,7 @@ from generalresearch.models.thl.finance import ( BusinessUserWalletBalances, POPFinancial, ) -from generalresearch.models.thl.ledger import LedgerAccount, OrderBy -from generalresearch.models.thl.payout import BusinessPayoutEvent - -if TYPE_CHECKING: - from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge - from generalresearch.pg_helper import PostgresConfig - from generalresearch.redis_helper import RedisConfig - -logging.basicConfig() -logger = logging.getLogger(__name__) +from generalresearch.models.thl.ledger import LedgerAccount if TYPE_CHECKING: from generalresearch.incite.base import GRLDatasets @@ -61,6 +50,7 @@ if TYPE_CHECKING: from generalresearch.incite.mergers.foundations.enriched_wall import ( EnrichedWallMerge, ) + from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge from generalresearch.managers.gr.business import ( BusinessBankAccountManager, ) @@ -75,6 +65,11 @@ if TYPE_CHECKING: ) from generalresearch.managers.thl.product import ProductManager from generalresearch.models.thl.product import Product + from generalresearch.pg_helper import PostgresConfig + from generalresearch.redis_helper import RedisConfig + +logging.basicConfig() +logger = logging.getLogger(__name__) class BusinessBankAccount(BaseModel): -- cgit v1.2.3 From e5ba13edd8afa10330ad8e6e67fa1c023263345c Mon Sep 17 00:00:00 2001 From: stuppie Date: Tue, 13 Oct 2026 15:35:00 -0700 Subject: bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2bca0ef..c9fc83c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "generalresearch" -version = "3.8.0" +version = "3.8.1" description = "Python Utilities for General Research" readme = "README.md" requires-python = ">=3.14" -- cgit v1.2.3