aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Nanis2026-08-21 11:19:36 -0700
committerMax Nanis2026-08-21 11:19:36 -0700
commitc4a44873540ca4c0a3ab19b9beef4cfc6e0252a7 (patch)
treedd35c70a920fee9c480896e0f64b1ba0d6487e3f
parent05102628a7dc85a5a19a32415a7ec41ea7a91812 (diff)
downloadgeneralresearch-c4a44873540ca4c0a3ab19b9beef4cfc6e0252a7.tar.gz
generalresearch-c4a44873540ca4c0a3ab19b9beef4cfc6e0252a7.zip
last files for Greg to merge
-rw-r--r--test_utils/conftest.py14
-rw-r--r--tests/models/gr/test_base.py39
2 files changed, 42 insertions, 11 deletions
diff --git a/test_utils/conftest.py b/test_utils/conftest.py
index cd7f282..378b9cc 100644
--- a/test_utils/conftest.py
+++ b/test_utils/conftest.py
@@ -4,6 +4,7 @@ import os
import shutil
import stat
import subprocess
+import sys
import tempfile
from datetime import datetime, timedelta, timezone
from os.path import join as pjoin
@@ -174,7 +175,7 @@ def git_key_path(
@pytest.fixture(scope="session")
-def gr_models(git_key_path: Path) -> Callable[..., Path]:
+def gr_repo(git_key_path: Path) -> Callable[..., Path]:
repo_url = "ssh://code.g-r-l.com/general-research/gr-carer.git"
repo_path = Path("/tmp/gr-carer")
@@ -202,7 +203,9 @@ def gr_models(git_key_path: Path) -> Callable[..., Path]:
@pytest.fixture(scope="session")
def django_db_factory(
- postgres_instance: PostgresDsn, postgres_instance_dict: PostgresDict
+ postgres_instance: PostgresDsn,
+ postgres_instance_dict: PostgresDict,
+ gr_repo: Callable[..., Path],
) -> Callable[..., PostgresDsn]:
import django
@@ -211,6 +214,13 @@ def django_db_factory(
def _inner(django_project: str = "generalresearch.thl_django"):
+ if "gr" in django_project:
+ # We need model files that are NOT in this repo.
+ gr_path = gr_repo()
+ sys.path.insert(0, str(gr_path))
+
+ print(sys.path)
+
# 1. Bootstrapping Django settings
if not django_settings.configured:
django_settings.configure(
diff --git a/tests/models/gr/test_base.py b/tests/models/gr/test_base.py
index 323d7b6..a9f01a8 100644
--- a/tests/models/gr/test_base.py
+++ b/tests/models/gr/test_base.py
@@ -1,5 +1,8 @@
+import subprocess
+from pathlib import Path
from typing import Callable
+import pytest
from pydantic import PostgresDsn
from generalresearch.pg_helper import PostgresConfig
@@ -7,19 +10,37 @@ from generalresearch.pg_helper import PostgresConfig
class TestGRPostgresDjangoCreation:
+ def test_git(self, git_key_path: Path, 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],
):
- dsn = django_db_factory("gr_carer")
+ dsn = django_db_factory("gr")
assert isinstance(dsn, PostgresDsn)
- def test_django_tables(self, thl_web_rw: PostgresConfig):
- res = thl_web_rw.execute_sql_query(query="""
- SELECT COUNT(*)
- FROM information_schema.tables
- WHERE table_schema = 'public';
- """)
- assert len(res) == 1
- assert res[0]["count"] == 56
+ # def test_django_tables(self, thl_web_rw: PostgresConfig):
+ # res = thl_web_rw.execute_sql_query(query="""
+ # SELECT COUNT(*)
+ # FROM information_schema.tables
+ # WHERE table_schema = 'public';
+ # """)
+ # assert len(res) == 1
+ # assert res[0]["count"] == 56