Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
import json
import os
import shutil
import sys
import tempfile
from pathlib import Path

import pytest
from git import Repo
from pytest_httpx._httpx_mock import HTTPXMock
from typer.testing import Any, CliRunner
from typer.testing import CliRunner

from infrahub_sdk.ctl.cli_commands import app

from .utils import change_directory, strip_color
from tests.helpers.utils import change_directory, strip_color

runner = CliRunner()


FIXTURE_BASE_DIR = Path(Path(os.path.abspath(__file__)).parent / ".." / "fixtures" / "integration" / "test_infrahubctl")
FIXTURE_BASE_DIR = Path(
Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl"
)


def read_fixture(file_name: str, fixture_subdir: str = ".") -> Any:
def read_fixture(file_name: str, fixture_subdir: str = ".") -> str:
"""Read the contents of a fixture."""
with Path(FIXTURE_BASE_DIR / fixture_subdir / file_name).open("r", encoding="utf-8") as fhd:
fixture_contents = fhd.read()
Expand All @@ -38,7 +40,7 @@ def tags_transform_dir():
shutil.copytree(fixture_path, temp_dir, dirs_exist_ok=True)
# Initialize fixture as git repo. This is necessary to run some infrahubctl commands.
with change_directory(temp_dir):
Repo.init(".")
Repo.init(".", initial_branch="main")

yield temp_dir

Expand All @@ -64,6 +66,7 @@ def test_transform_not_exist_in_infrahub_yml(tags_transform_dir: str) -> None:
assert output.exit_code == 1

@staticmethod
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_transform_python_file_not_defined(tags_transform_dir: str) -> None:
"""Case transform python file not defined."""
# Remove transform file
Expand All @@ -78,6 +81,7 @@ def test_transform_python_file_not_defined(tags_transform_dir: str) -> None:
assert output.exit_code == 1

@staticmethod
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_transform_python_class_not_defined(tags_transform_dir: str) -> None:
"""Case transform python class not defined."""
# Rename transform inside of python file so the class name searched for no longer exists
Expand All @@ -97,6 +101,7 @@ def test_transform_python_class_not_defined(tags_transform_dir: str) -> None:
assert output.exit_code == 1

@staticmethod
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_gql_query_not_defined(tags_transform_dir: str) -> None:
"""Case GraphQL Query is not defined"""
# Remove GraphQL Query file
Expand All @@ -110,6 +115,7 @@ def test_gql_query_not_defined(tags_transform_dir: str) -> None:
assert output.exit_code == 1

@staticmethod
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_infrahubctl_transform_cmd_success(httpx_mock: HTTPXMock, tags_transform_dir: str) -> None:
"""Case infrahubctl transform command executes successfully"""
httpx_mock.add_response(
Expand Down