-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcontainers packages and move testing to the SDK
- Loading branch information
Showing
17 changed files
with
817 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ sync/dist/ | |
helm/charts/ | ||
helm/Chart.lock | ||
|
||
python_testcontainers/dist/* |
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
backend/tests/integration_docker/test_propose_change_repository.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from infrahub_sdk import InfrahubClient | ||
from infrahub_sdk.protocols import CoreGenericRepository, CoreProposedChange | ||
from infrahub_sdk.schema import NodeSchema, SchemaRoot | ||
from infrahub_sdk.testing.docker import TestInfrahubDockerClient | ||
from infrahub_sdk.testing.repository import GitRepo | ||
from infrahub_sdk.testing.schemas.car_person import ( | ||
TESTING_PERSON, | ||
SchemaCarPerson, | ||
) | ||
|
||
from infrahub.core.constants import InfrahubKind | ||
from tests.helpers.fixtures import get_fixtures_dir | ||
|
||
CURRENT_DIRECTORY = Path(__file__).parent.resolve() | ||
|
||
|
||
class TestProposeChangeRepository(TestInfrahubDockerClient, SchemaCarPerson): | ||
@pytest.fixture(scope="class") | ||
def infrahub_version(self) -> str: | ||
return "local" | ||
|
||
@pytest.fixture(scope="class") | ||
def schema_person_artifact(self, schema_person_base: NodeSchema) -> NodeSchema: | ||
person_schema = schema_person_base.model_copy(deep=True) | ||
person_schema.inherit_from = [InfrahubKind.ARTIFACTTARGET] | ||
return person_schema | ||
|
||
@pytest.fixture(scope="class") | ||
def initial_schema( | ||
self, | ||
schema_car_base: NodeSchema, | ||
schema_person_artifact: NodeSchema, | ||
schema_manufacturer_base: NodeSchema, | ||
) -> SchemaRoot: | ||
return SchemaRoot( | ||
version="1.0", | ||
nodes=[schema_person_artifact, schema_car_base, schema_manufacturer_base], | ||
) | ||
|
||
async def test_load_initial_schema( | ||
self, default_branch: str, client: InfrahubClient, initial_schema: SchemaRoot | ||
) -> None: | ||
await client.schema.wait_until_converged(branch=default_branch) | ||
|
||
resp = await client.schema.load( | ||
schemas=[initial_schema.to_schema_dict()], branch=default_branch, wait_until_converged=True | ||
) | ||
assert resp.errors == {} | ||
|
||
async def test_load_initial_data(self, client: InfrahubClient, default_branch: str, remote_repos_dir: Path) -> None: | ||
data = await self.create_initial_data(client=client, branch=default_branch) | ||
persons = data[TESTING_PERSON] | ||
|
||
# Create Group People | ||
group_people = await client.create( | ||
kind="CoreStandardGroup", name="people", members=[item.id for item in persons] | ||
) | ||
await group_people.save() | ||
|
||
# Add repositories | ||
fixture_dir = get_fixtures_dir() | ||
repo_name = "car-dealership" | ||
repo_dir = fixture_dir / "repos" / repo_name / "initial__main" | ||
repo = GitRepo(name=repo_name, src_directory=repo_dir, dst_directory=remote_repos_dir) | ||
await repo.add_to_infrahub(client=client) | ||
in_sync = await repo.wait_for_sync_to_complete(client=client) | ||
assert in_sync | ||
|
||
repos = await client.all(kind=CoreGenericRepository) | ||
assert repos | ||
|
||
async def test_create_propose_change(self, client: InfrahubClient, default_branch: str) -> None: | ||
branch = await client.branch.create(branch_name="branch2") | ||
john = client.store.get_by_hfid(key=f"{TESTING_PERSON}__John Doe", raise_when_missing=True) | ||
|
||
john_branch = await client.get(kind=TESTING_PERSON, id=john.id, branch=branch.name) | ||
john_branch.description.value = "new description" | ||
await john_branch.save() | ||
|
||
pc = await client.create( | ||
kind=CoreProposedChange, name="pc1", source_branch=branch.name, destination_branch=default_branch | ||
) | ||
await pc.save() | ||
|
||
# breakpoint() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.