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
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def event_loop():


@pytest.fixture(scope="session", autouse=True)
def execute_before_any_test():
def execute_before_any_test() -> None:
config.SETTINGS.load_and_exit()
config.SETTINGS.active.server_address = "http://mock"

Expand Down
34 changes: 17 additions & 17 deletions tests/integration/test_infrahub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def base_dataset(
cat_bella,
dog_daisy,
dog_rocky,
):
) -> None:
await client.branch.create(branch_name="branch01")

@pytest.fixture
Expand All @@ -39,7 +39,7 @@ async def set_pagination_size3(self, client: InfrahubClient):
yield
client.pagination_size = original_pagination_size

async def test_query_branches(self, client: InfrahubClient, base_dataset):
async def test_query_branches(self, client: InfrahubClient, base_dataset) -> None:
branches = await client.branch.all()
main = await client.branch.get(branch_name="main")

Expand All @@ -50,7 +50,7 @@ async def test_query_branches(self, client: InfrahubClient, base_dataset):
assert "main" in branches
assert "branch01" in branches

async def test_branch_delete(self, client: InfrahubClient, base_dataset):
async def test_branch_delete(self, client: InfrahubClient, base_dataset) -> None:
async_branch = "async-delete-branch"
await client.branch.create(branch_name=async_branch)
pre_delete = await client.branch.all()
Expand All @@ -59,7 +59,7 @@ async def test_branch_delete(self, client: InfrahubClient, base_dataset):
assert async_branch in pre_delete.keys()
assert async_branch not in post_delete.keys()

async def test_get_all(self, client: InfrahubClient, base_dataset):
async def test_get_all(self, client: InfrahubClient, base_dataset) -> None:
nodes = await client.all(kind=TESTING_CAT)
assert len(nodes) == 2
assert isinstance(nodes[0], InfrahubNode)
Expand All @@ -80,7 +80,7 @@ async def test_get_all(self, client: InfrahubClient, base_dataset):
# assert isinstance(nodes[0], InfrahubNode)
# assert {node.name.value for node in nodes} == {"Bella", "Luna"}

async def test_get_one(self, client: InfrahubClient, base_dataset, cat_luna, person_sophia):
async def test_get_one(self, client: InfrahubClient, base_dataset, cat_luna, person_sophia) -> None:
node1 = await client.get(kind=TESTING_CAT, id=cat_luna.id)
assert isinstance(node1, InfrahubNode)
assert node1.name.value == "Luna"
Expand All @@ -89,7 +89,7 @@ async def test_get_one(self, client: InfrahubClient, base_dataset, cat_luna, per
assert isinstance(node2, InfrahubNode)
assert node2.name.value == "Sophia Walker"

async def test_filters_partial_match(self, client: InfrahubClient, base_dataset):
async def test_filters_partial_match(self, client: InfrahubClient, base_dataset) -> None:
nodes = await client.filters(kind=TESTING_PERSON, name__value="Walker")
assert not nodes

Expand All @@ -98,25 +98,25 @@ async def test_filters_partial_match(self, client: InfrahubClient, base_dataset)
assert isinstance(nodes[0], InfrahubNode)
assert sorted([node.name.value for node in nodes]) == ["Liam Walker", "Sophia Walker"]

async def test_get_generic(self, client: InfrahubClient, base_dataset):
async def test_get_generic(self, client: InfrahubClient, base_dataset) -> None:
nodes = await client.all(kind=TESTING_ANIMAL)
assert len(nodes) == 4

async def test_get_generic_fragment(self, client: InfrahubClient, base_dataset):
async def test_get_generic_fragment(self, client: InfrahubClient, base_dataset) -> None:
nodes = await client.all(kind=TESTING_ANIMAL, fragment=True)
assert len(nodes)
assert nodes[0].typename in [TESTING_DOG, TESTING_CAT]
assert nodes[0].breed.value is not None

async def test_get_related_nodes(self, client: InfrahubClient, base_dataset, person_ethan):
async def test_get_related_nodes(self, client: InfrahubClient, base_dataset, person_ethan) -> None:
ethan = await client.get(kind=TESTING_PERSON, id=person_ethan.id)
assert ethan

assert ethan.animals.peers == []
await ethan.animals.fetch()
assert len(ethan.animals.peers) == 3

async def test_profile(self, client: InfrahubClient, base_dataset, person_liam):
async def test_profile(self, client: InfrahubClient, base_dataset, person_liam) -> None:
profile_schema_kind = f"Profile{TESTING_DOG}"
profile_schema = await client.schema.get(kind=profile_schema_kind)
assert isinstance(profile_schema, ProfileSchemaAPI)
Expand All @@ -137,30 +137,30 @@ async def test_profile(self, client: InfrahubClient, base_dataset, person_liam):
obj1 = await client.get(kind=TESTING_DOG, id=obj.id)
assert obj1.color.value == "#111111"

async def test_create_branch(self, client: InfrahubClient, base_dataset):
async def test_create_branch(self, client: InfrahubClient, base_dataset) -> None:
branch = await client.branch.create(branch_name="new-branch-1")
assert isinstance(branch, BranchData)
assert branch.id is not None

async def test_create_branch_async(self, client: InfrahubClient, base_dataset):
async def test_create_branch_async(self, client: InfrahubClient, base_dataset) -> None:
task_id = await client.branch.create(branch_name="new-branch-2", wait_until_completion=False)
assert isinstance(task_id, str)

async def test_count(self, client: InfrahubClient, base_dataset):
async def test_count(self, client: InfrahubClient, base_dataset) -> None:
count = await client.count(kind=TESTING_PERSON)
assert count == 3

async def test_count_with_filter(self, client: InfrahubClient, base_dataset):
async def test_count_with_filter(self, client: InfrahubClient, base_dataset) -> None:
count = await client.count(kind=TESTING_PERSON, name__values=["Liam Walker", "Ethan Carter"])
assert count == 2

async def test_query_unexisting_branch(self, client: InfrahubClient):
async def test_query_unexisting_branch(self, client: InfrahubClient) -> None:
with pytest.raises(URLNotFoundError, match=r"/graphql/unexisting` not found."):
await client.execute_graphql(query="unused", branch_name="unexisting")

async def test_create_generic_rel_with_hfid(
self, client: InfrahubClient, base_dataset, cat_luna, person_sophia, schema_animal, schema_cat
):
) -> None:
# See https://github.com/opsmill/infrahub-sdk-python/issues/277
assert schema_animal.human_friendly_id != schema_cat.human_friendly_id, (
"Inherited node schema should have a different hfid than generic one for this test to be relevant"
Expand All @@ -170,7 +170,7 @@ async def test_create_generic_rel_with_hfid(
person_sophia = await client.get(kind=TESTING_PERSON, id=person_sophia.id, prefetch_relationships=True)
assert person_sophia.favorite_animal.id == cat_luna.id

async def test_task_query(self, client: InfrahubClient, base_dataset, set_pagination_size3):
async def test_task_query(self, client: InfrahubClient, base_dataset, set_pagination_size3) -> None:
nbr_tasks = await client.task.count()
assert nbr_tasks

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_infrahubctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def base_dataset(
dog_daisy,
dog_rocky,
ctl_client_config,
):
) -> None:
await client.branch.create(branch_name="branch01")

@pytest.fixture(scope="class")
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def initial_schema(self, default_branch: str, client: InfrahubClient, sche

async def test_node_create(
self, client: InfrahubClient, initial_schema: None, schema_manufacturer_base: NodeSchema
):
) -> None:
schema_manufacturer = NodeSchemaAPI(**schema_manufacturer_base.model_dump(exclude_unset=True))
data = {
"name": "Fiat",
Expand All @@ -34,7 +34,7 @@ async def test_node_delete(
self,
client: InfrahubClient,
initial_schema: None,
):
) -> None:
obj = await client.create(kind=TESTING_MANUFACTURER, name="Dacia")
await obj.save()

Expand All @@ -52,7 +52,7 @@ async def test_node_create_with_relationships(
initial_schema: None,
manufacturer_mercedes,
person_joe,
):
) -> None:
node = await client.create(
kind=TESTING_CAR, name="Tiguan", color="Black", manufacturer=manufacturer_mercedes.id, owner=person_joe.id
)
Expand All @@ -71,7 +71,7 @@ async def test_node_create_with_relationships_using_related_node(
manufacturer_mercedes,
car_golf,
person_joe,
):
) -> None:
related_node = car_golf.owner
node = await client.create(
kind=TESTING_CAR, name="Tiguan", color="Black", manufacturer=manufacturer_mercedes, owner=related_node
Expand All @@ -90,7 +90,7 @@ async def test_node_update_with_original_data(
default_branch: str,
client: InfrahubClient,
initial_schema: None,
):
) -> None:
person_marina = await client.create(kind="TestingPerson", name="marina", age=20)
await person_marina.save()

Expand Down Expand Up @@ -183,7 +183,7 @@ async def test_node_update(
tag_blue,
tag_red,
tag_green,
):
) -> None:
car_golf.color.value = "White"
await car_golf.tags.fetch()
car_golf.tags.add(tag_blue.id)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class TestInfrahubRepository(TestInfrahubDockerClient):
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir):
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir) -> None:
src_directory = get_fixtures_dir() / "integration/mock_repo"
repo = GitRepo(name="mock_repo", src_directory=src_directory, dst_directory=remote_repos_dir)
commit = repo._repo.git[repo._repo.git.head()]
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
#
class TestInfrahubSchema(TestInfrahubDockerClient):
async def test_query_schema_for_branch_not_found(self, client: InfrahubClient):
async def test_query_schema_for_branch_not_found(self, client: InfrahubClient) -> None:
with pytest.raises(BranchNotFoundError) as exc:
await client.all(kind="BuiltinTag", branch="I-do-not-exist")

Expand Down
16 changes: 8 additions & 8 deletions tests/integration/test_spec_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def load_menu_file(name: str) -> MenuFile:
return files[0]


def test_load_nested_folders_order():
def test_load_nested_folders_order() -> None:
files = YamlFile.load_from_disk(paths=[get_fixtures_dir() / "nested_spec_objects"])
assert len(files) == 6
assert Path(files[0].location).name == "3_file.yml"
Expand Down Expand Up @@ -53,10 +53,10 @@ async def initial_schema(self, default_branch: str, client: InfrahubClient, sche
)
assert resp.errors == {}

async def test_create_branch(self, client: InfrahubClient, initial_schema: None, branch_name: str):
async def test_create_branch(self, client: InfrahubClient, initial_schema: None, branch_name: str) -> None:
await client.branch.create(branch_name=branch_name, sync_with_git=False)

async def test_load_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None):
async def test_load_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
obj_file = load_object_file("animal_tags01.yml")
await obj_file.validate_format(client=client, branch=branch_name)

Expand All @@ -67,7 +67,7 @@ async def test_load_tags(self, client: InfrahubClient, branch_name: str, initial

assert len(await client.all(kind=obj_file.spec.kind, branch=branch_name)) == 3

async def test_update_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None):
async def test_update_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
obj_file = load_object_file("animal_tags02.yml")
await obj_file.validate_format(client=client, branch=branch_name)

Expand All @@ -81,7 +81,7 @@ async def test_update_tags(self, client: InfrahubClient, branch_name: str, initi
assert len(tags_by_name) == 4
assert tags_by_name["Veterinarian"].description.value == "Licensed animal healthcare professional"

async def test_load_persons(self, client: InfrahubClient, branch_name: str, initial_schema: None):
async def test_load_persons(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
obj_file = load_object_file("animal_person01.yml")
await obj_file.validate_format(client=client, branch=branch_name)

Expand All @@ -92,7 +92,7 @@ async def test_load_persons(self, client: InfrahubClient, branch_name: str, init

assert len(await client.all(kind=obj_file.spec.kind, branch=branch_name)) == 3

async def test_load_dogs(self, client: InfrahubClient, branch_name: str, initial_schema: None):
async def test_load_dogs(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
obj_file = load_object_file("animal_dog01.yml")
await obj_file.validate_format(client=client, branch=branch_name)

Expand All @@ -103,7 +103,7 @@ async def test_load_dogs(self, client: InfrahubClient, branch_name: str, initial

assert len(await client.all(kind=obj_file.spec.kind, branch=branch_name)) == 4

async def test_load_persons02(self, client: InfrahubClient, branch_name: str, initial_schema: None):
async def test_load_persons02(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
obj_file = load_object_file("animal_person02.yml")
await obj_file.validate_format(client=client, branch=branch_name)

Expand Down Expand Up @@ -135,7 +135,7 @@ async def test_load_persons02(self, client: InfrahubClient, branch_name: str, in
animals_emily = [animal.display_label for animal in person_by_name["Emily Parker"].animals.peers]
assert sorted(animals_emily) == sorted(["Max Golden Retriever", "Whiskers Siamese #FFD700"])

async def test_load_menu(self, client: InfrahubClient, branch_name: str, initial_schema: None):
async def test_load_menu(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
menu_file = load_menu_file("animal_menu01.yml")
await menu_file.validate_format(client=client, branch=branch_name)

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/ctl/test_branch_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
runner = CliRunner()


def test_branch_list(mock_branches_list_query):
def test_branch_list(mock_branches_list_query) -> 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):
def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_payload) -> None:
httpx_mock.add_response(
status_code=401,
method="POST",
Expand All @@ -24,7 +24,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):
def test_branch_create_wrong_name(mock_branch_create_error) -> None:
result = runner.invoke(app=app, args=["create", "branch2"])

assert result.exit_code == 1
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/ctl/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@
pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True)


def test_main_app():
def test_main_app() -> None:
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] COMMAND [ARGS]" in result.stdout


def test_validate_all_commands_have_names():
def test_validate_all_commands_have_names() -> None:
assert app.registered_commands
for command in app.registered_commands:
assert command.name


def test_validate_all_groups_have_names():
def test_validate_all_groups_have_names() -> None:
assert app.registered_groups
for group in app.registered_groups:
assert group.name


def test_version_command():
def test_version_command() -> None:
result = runner.invoke(app, ["version"])
assert result.exit_code == 0
assert "Python SDK: v" in result.stdout


def test_info_command_success(mock_query_infrahub_version, mock_query_infrahub_user):
def test_info_command_success(mock_query_infrahub_version, mock_query_infrahub_user) -> None:
result = runner.invoke(app, ["info"])
assert result.exit_code == 0
for expected in ["Connection Status", "Python Version", "SDK Version", "Infrahub Version"]:
assert expected in result.stdout, f"'{expected}' not found in info command output"


def test_info_command_failure():
def test_info_command_failure() -> None:
result = runner.invoke(app, ["info"])
assert result.exit_code == 0
assert "Connection Error" in result.stdout


def test_info_detail_command_success(mock_query_infrahub_version, mock_query_infrahub_user):
def test_info_detail_command_success(mock_query_infrahub_version, mock_query_infrahub_user) -> None:
result = runner.invoke(app, ["info", "--detail"])
assert result.exit_code == 0
for expected in [
Expand All @@ -58,7 +58,7 @@ def test_info_detail_command_success(mock_query_infrahub_version, mock_query_inf
assert expected in result.stdout, f"'{expected}' not found in detailed info command output"


def test_info_detail_command_failure():
def test_info_detail_command_failure() -> None:
result = runner.invoke(app, ["info", "--detail"])
assert result.exit_code == 0
assert "Error Reason" in result.stdout
Loading