66import pytest
77from git import GitCommandError
88
9- from infrahub .core .constants import InfrahubKind , RepositoryObjects , RepositoryOperationalStatus
9+ from infrahub .core .constants import InfrahubKind , RepositoryOperationalStatus
1010from infrahub .core .manager import NodeManager
1111from infrahub .core .node import Node
1212from infrahub .exceptions import RepositoryError
1515from tests .helpers .file_repo import FileRepo
1616from tests .helpers .schema import CAR_SCHEMA , load_schema
1717from tests .helpers .test_app import TestInfrahubApp
18+ from tests .integration .git .utils import check_repo_correctly_created
1819
1920if TYPE_CHECKING :
2021 from pathlib import Path
@@ -50,6 +51,7 @@ async def test_create_repository(
5051 initial_dataset : None ,
5152 git_repos_source_dir_module_scope : Path ,
5253 client : InfrahubClient ,
54+ default_branch ,
5355 ) -> None :
5456 """Validate that we can create a repository, that it gets updated with the commit id and that objects are created."""
5557 client_repository = await client .create (
@@ -59,66 +61,23 @@ async def test_create_repository(
5961 await client_repository .save ()
6062
6163 repository : CoreRepository = await NodeManager .get_one (
62- db = db , id = client_repository .id , kind = InfrahubKind .REPOSITORY , raise_on_error = True
63- )
64-
65- check_definition : CoreCheckDefinition = await NodeManager .get_one_by_default_filter (
66- db = db , id = "car_description_check" , kind = InfrahubKind .CHECKDEFINITION , raise_on_error = True
67- )
68-
69- assert repository .commit .value
70- assert repository .internal_status .value == "active"
71- assert repository .operational_status .value == "online"
72- assert check_definition .file_path .value == "checks/car_overview.py"
73-
74- person_ethan = await NodeManager .get_one_by_default_filter (
75- db = db , id = "Ethan Carter" , kind = "TestingPerson" , raise_on_error = True
76- )
77- assert person_ethan .name .value == "Ethan Carter"
78- assert person_ethan .height .value == 180
79-
80- manufacturer_mercedes = await NodeManager .get_one_by_default_filter (
81- db = db , id = "Mercedes" , kind = "TestingManufacturer" , raise_on_error = True , prefetch_relationships = True
82- )
83- assert manufacturer_mercedes .name .value == "Mercedes"
84- assert list ((await manufacturer_mercedes .customers .get_peers (db = db )).values ())[0 ].name .value == "Ethan Carter"
85-
86- repository_group = await NodeManager .get_one_by_default_filter (
8764 db = db ,
88- id = f"group-repo-{ RepositoryObjects .OBJECT .value } -{ repository .id } " ,
89- kind = "CoreRepositoryGroup" ,
90- raise_on_error = True ,
91- prefetch_relationships = True ,
92- )
93- assert repository_group .content .value == RepositoryObjects .OBJECT .value
94- members = (await repository_group .members .get_peers (db = db )).values ()
95- assert len (members ) == 4
96- assert manufacturer_mercedes .id in {m .id for m in members }
97- assert person_ethan .id in {m .id for m in members }
98-
99- # TODO Retrieve menus
100-
101- repository_group_menus = await NodeManager .get_one_by_default_filter (
102- db = db ,
103- id = f"group-repo-{ RepositoryObjects .MENU .value } -{ repository .id } " ,
104- kind = "CoreRepositoryGroup" ,
65+ id = client_repository .id ,
66+ kind = InfrahubKind .REPOSITORY ,
10567 raise_on_error = True ,
106- prefetch_relationships = True ,
10768 )
108-
109- assert repository_group_menus .content .value == RepositoryObjects .MENU .value
110-
111- _ = await NodeManager .get_one_by_hfid (
69+ check_definition : CoreCheckDefinition = await NodeManager .get_one_by_default_filter (
11270 db = db ,
113- hfid = [ "Testing" , "Manufacturer" ] ,
114- kind = "CoreMenu" ,
71+ id = "car_description_check" ,
72+ kind = InfrahubKind . CHECKDEFINITION ,
11573 raise_on_error = True ,
116- prefetch_relationships = True ,
11774 )
75+ assert repository .commit .value
76+ assert repository .internal_status .value == "active" , f"{ repository .internal_status .value = } "
77+ assert repository .operational_status .value == "online"
78+ assert check_definition .file_path .value == "checks/car_overview.py"
11879
119- _ = await NodeManager .get_one_by_hfid (
120- db = db , hfid = ["Testing" , "Person" ], kind = "CoreMenu" , raise_on_error = True , prefetch_relationships = True
121- )
80+ await check_repo_correctly_created (repo_id = client_repository .id , db = db , branch_name = default_branch .name )
12281
12382 # TODO add a test with invalid yml file OR invalid order of objects in the yml file, and make sure the repository ends
12483 # up in error import state
0 commit comments