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
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,6 @@ max-complexity = 17
"tests/integration/test_convert_object_type.py" = ["ANN001"] # 3 errors
"tests/integration/test_repository.py" = ["ANN001"] # 1 error

# tests/unit/ctl/ - 25 errors total
"tests/unit/ctl/test_repository_app.py" = ["ANN001"] # 11 errors
"tests/unit/ctl/test_render_app.py" = ["ANN001"] # 5 errors
"tests/unit/ctl/test_cli.py" = ["ANN001"] # 5 errors
"tests/unit/ctl/test_branch_app.py" = ["ANN001"] # 3 errors
"tests/unit/ctl/test_branch_report.py" = ["ANN001"] # 1 error

"tasks.py" = [
"PLC0415", # `import` should be at the top-level of a file
]
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/ctl/test_branch_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from pytest_httpx import HTTPXMock
from typer.testing import CliRunner

Expand All @@ -6,13 +8,13 @@
runner = CliRunner()


def test_branch_list(mock_branches_list_query) -> None:
def test_branch_list(mock_branches_list_query: HTTPXMock) -> None:
result = runner.invoke(app=app, args=["list"])
assert result.exit_code == 0
assert "cr1234" in result.stdout


def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_payload) -> None:
def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_payload: dict[str, Any]) -> None:
httpx_mock.add_response(
status_code=401,
method="POST",
Expand All @@ -24,7 +26,7 @@ def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_paylo
assert "Authentication is required" in result.stdout


def test_branch_create_wrong_name(mock_branch_create_error) -> None:
def test_branch_create_wrong_name(mock_branch_create_error: HTTPXMock) -> None:
result = runner.invoke(app=app, args=["create", "branch2"])

assert result.exit_code == 1
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ctl/test_branch_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_branch_report_command_without_proposed_change(
assert "No proposed changes for this branch" in result.stdout


def test_branch_report_command_main_branch(mock_branch_report_default_branch) -> None:
def test_branch_report_command_main_branch(mock_branch_report_default_branch: HTTPXMock) -> None:
"""Test branch report CLI command on main branch."""
runner = CliRunner()
result = runner.invoke(app, ["report", "main"])
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/ctl/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pytest_httpx import HTTPXMock
from typer.testing import CliRunner

from infrahub_sdk.ctl.cli import app
Expand Down Expand Up @@ -32,7 +33,7 @@ def test_version_command() -> None:
assert "Python SDK: v" in result.stdout


def test_info_command_success(mock_query_infrahub_version, mock_query_infrahub_user) -> None:
def test_info_command_success(mock_query_infrahub_version: HTTPXMock, mock_query_infrahub_user: HTTPXMock) -> None:
result = runner.invoke(app, ["info"], env={"INFRAHUB_API_TOKEN": "foo"})
assert result.exit_code == 0
for expected in ["Connection Status", "Python Version", "SDK Version", "Infrahub Version"]:
Expand All @@ -45,14 +46,16 @@ def test_info_command_failure() -> None:
assert "Connection Error" in result.stdout


def test_info_detail_command_success(mock_query_infrahub_version, mock_query_infrahub_user) -> None:
def test_info_detail_command_success(
mock_query_infrahub_version: HTTPXMock, mock_query_infrahub_user: HTTPXMock
) -> None:
result = runner.invoke(app, ["info", "--detail"], env={"INFRAHUB_API_TOKEN": "foo"})
assert result.exit_code == 0
for expected in ["Connection Status", "Version Information", "Client Info", "Infrahub Info", "Groups:"]:
assert expected in result.stdout, f"'{expected}' not found in detailed info command output"


def test_anonymous_info_detail_command_success(mock_query_infrahub_version) -> None:
def test_anonymous_info_detail_command_success(mock_query_infrahub_version: HTTPXMock) -> None:
result = runner.invoke(app, ["info", "--detail"])
assert result.exit_code == 0
for expected in ["Connection Status", "Version Information", "Client Info", "Infrahub Info", "anonymous"]:
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/ctl/test_render_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

import pytest
from pytest_httpx._httpx_mock import HTTPXMock
from pytest_httpx import HTTPXMock
from typer.testing import CliRunner

from infrahub_sdk.ctl.cli_commands import app
Expand Down Expand Up @@ -80,7 +80,12 @@ def test_validate_template_not_found(test_case: RenderAppFailure, httpx_mock: HT
],
)
def test_render_branch_selection(
monkeypatch, httpx_mock: HTTPXMock, cli_branch, env_branch, from_git, expected_branch
monkeypatch: pytest.MonkeyPatch,
httpx_mock: HTTPXMock,
cli_branch: str | None,
env_branch: str | None,
from_git: bool,
expected_branch: str,
) -> None:
"""Test that the render command uses the correct branch source."""

Expand Down
13 changes: 7 additions & 6 deletions tests/unit/ctl/test_repository_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock

import pytest
from pytest_httpx import HTTPXMock
from typer.testing import CliRunner

from infrahub_sdk.client import InfrahubClient
Expand All @@ -26,7 +27,7 @@ class TestInfrahubctlRepository:
"""Groups the 'infrahubctl repository' test cases."""

@mock.patch("infrahub_sdk.ctl.repository.initialize_client")
def test_repo_no_username_or_password(self, mock_init_client, mock_client) -> None:
def test_repo_no_username_or_password(self, mock_init_client: mock.Mock, mock_client: mock.Mock) -> None:
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
mock_cred = mock.AsyncMock()
mock_cred.id = "1234"
Expand Down Expand Up @@ -73,7 +74,7 @@ def test_repo_no_username_or_password(self, mock_init_client, mock_client) -> No
)

@mock.patch("infrahub_sdk.ctl.repository.initialize_client")
def test_repo_no_username(self, mock_init_client, mock_client) -> None:
def test_repo_no_username(self, mock_init_client: mock.Mock, mock_client: mock.Mock) -> None:
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
mock_cred = mock.AsyncMock()
mock_cred.id = "1234"
Expand Down Expand Up @@ -132,7 +133,7 @@ def test_repo_no_username(self, mock_init_client, mock_client) -> None:
)

@mock.patch("infrahub_sdk.ctl.repository.initialize_client")
def test_repo_username(self, mock_init_client, mock_client) -> None:
def test_repo_username(self, mock_init_client: mock.Mock, mock_client: mock.Mock) -> None:
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
mock_cred = mock.AsyncMock()
mock_cred.id = "1234"
Expand Down Expand Up @@ -193,7 +194,7 @@ def test_repo_username(self, mock_init_client, mock_client) -> None:
)

@mock.patch("infrahub_sdk.ctl.repository.initialize_client")
def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
def test_repo_readonly_true(self, mock_init_client: mock.Mock, mock_client: mock.Mock) -> None:
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
mock_cred = mock.AsyncMock()
mock_cred.id = "1234"
Expand Down Expand Up @@ -253,7 +254,7 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
)

@mock.patch("infrahub_sdk.ctl.repository.initialize_client")
def test_repo_description_commit_branch(self, mock_init_client, mock_client) -> None:
def test_repo_description_commit_branch(self, mock_init_client: mock.Mock, mock_client: mock.Mock) -> None:
"""Case allow no username to be passed in and set it as None rather than blank string that fails."""
mock_cred = mock.AsyncMock()
mock_cred.id = "1234"
Expand Down Expand Up @@ -317,7 +318,7 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
tracker="mutation-repository-create",
)

def test_repo_list(self, mock_repositories_list) -> None:
def test_repo_list(self, mock_repositories_list: HTTPXMock) -> None:
result = runner.invoke(app, ["repository", "list"])
assert result.exit_code == 0
assert strip_color(result.stdout) == read_fixture("output.txt", "integration/test_infrahubctl/repository_list")
Expand Down