aboutsummaryrefslogtreecommitdiff
path: root/tests/models/gr/test_base.py
blob: 5ab5dffeba16670d4c0469f6d71a128717791078 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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],
    ):

        dsn = django_db_factory("gr.common")
        assert isinstance(dsn, PostgresDsn)