Skip to content

Commit ae35bf1

Browse files
committed
TestProposedChangePipelineConflict setup uses a repository with a different name
1 parent 462b65d commit ae35bf1

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

backend/tests/helpers/file_repo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
class FileRepo:
1616
name: str
1717
sources_directory: Path
18+
19+
# Some tests make a prior copy of fixtures/repos/car-dealership folder in a temp folder,
20+
# in which case we need to use that temp folder instead of fixture dir. This could probably be removed
21+
# when https://github.com/opsmill/infrahub/issues/4296 is fixed.
22+
local_repo_base_path: Path = get_fixtures_dir() / "repos"
23+
1824
_repo: Optional[Repo] = None
1925
_initial_branch: Optional[str] = None
2026
_branches: list[str] = field(default_factory=list)
@@ -48,7 +54,7 @@ def _apply_pull_requests(self, repo_base: Path) -> None:
4854
self.repo.git.commit("-m", pull_request)
4955

5056
def __post_init__(self) -> None:
51-
repo_base = Path(get_fixtures_dir(), "repos", self.name)
57+
repo_base = Path(self.local_repo_base_path, self.name)
5258
initial_directory = self._initial_directory(repo_base=repo_base)
5359
shutil.copytree(repo_base / initial_directory, self.sources_directory / self.name)
5460
self._repo = Repo.init(self.sources_directory / self.name, initial_branch=self._initial_branch)

backend/tests/integration/proposed_change/test_proposed_change_conflict.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
import shutil
4+
import tempfile
5+
from pathlib import Path
36
from typing import TYPE_CHECKING
47

58
import pytest
@@ -10,21 +13,37 @@
1013
from infrahub.core.manager import NodeManager
1114
from infrahub.core.node import Node
1215
from infrahub.services.adapters.cache.redis import RedisCache
16+
from infrahub.utils import get_fixtures_dir
1317
from tests.constants import TestKind
1418
from tests.helpers.file_repo import FileRepo
1519
from tests.helpers.schema import CAR_SCHEMA, load_schema
1620
from tests.helpers.test_app import TestInfrahubApp
1721

1822
if TYPE_CHECKING:
19-
from pathlib import Path
20-
2123
from infrahub_sdk import InfrahubClient
2224

2325
from infrahub.database import InfrahubDatabase
2426
from tests.adapters.message_bus import BusSimulator
2527

2628

2729
class TestProposedChangePipelineConflict(TestInfrahubApp):
30+
@pytest.fixture(scope="class")
31+
def car_dealership_copy(self):
32+
"""
33+
Copies car-dealership local repository to a temporary folder, with a new name.
34+
This is needed for this test as using car-dealership folder leads to issues most probably
35+
related to https://github.com/opsmill/infrahub/issues/4296 as some other tests use this same repository.
36+
"""
37+
38+
source_folder = Path(get_fixtures_dir(), "repos", "car-dealership")
39+
new_folder_name = "car-dealership-copy"
40+
41+
with tempfile.TemporaryDirectory() as temp_dir:
42+
temp_path = Path(temp_dir)
43+
destination_folder = temp_path / new_folder_name
44+
shutil.copytree(source_folder, destination_folder)
45+
yield temp_path, new_folder_name
46+
2847
@pytest.fixture(scope="class")
2948
async def initial_dataset(
3049
self,
@@ -33,6 +52,7 @@ async def initial_dataset(
3352
git_repos_source_dir_module_scope: Path,
3453
client: InfrahubClient,
3554
bus_simulator: BusSimulator,
55+
car_dealership_copy: tuple[Path, str],
3656
) -> str:
3757
await load_schema(db, schema=CAR_SCHEMA)
3858
john = await Node.init(schema=TestKind.PERSON, db=db)
@@ -57,10 +77,11 @@ async def initial_dataset(
5777
await jesko.save(db=db)
5878

5979
bus_simulator.service.cache = RedisCache()
60-
FileRepo(name="car-dealership", sources_directory=git_repos_source_dir_module_scope)
80+
repo_path, repo_name = car_dealership_copy
81+
FileRepo(name=repo_name, local_repo_base_path=repo_path, sources_directory=git_repos_source_dir_module_scope)
6182
client_repository = await client.create(
6283
kind=InfrahubKind.REPOSITORY,
63-
data={"name": "car-dealership", "location": f"{git_repos_source_dir_module_scope}/car-dealership"},
84+
data={"name": "dealership-car", "location": f"{git_repos_source_dir_module_scope}/{repo_name}"},
6485
)
6586
await client_repository.save()
6687
return client_repository.id

0 commit comments

Comments
 (0)