1010from infrahub_sdk .utils import get_fixtures_dir
1111
1212
13+ def load_object_file (name : str ) -> ObjectFile :
14+ files = ObjectFile .load_from_disk (paths = [get_fixtures_dir () / "spec_objects" / name ])
15+ assert len (files ) == 1
16+ return files [0 ]
17+
18+
1319class TestSpecObject (TestInfrahubDockerClient , SchemaAnimal ):
20+ @pytest .fixture (scope = "class" )
21+ def branch_name (self ) -> str :
22+ return "branch2"
23+
1424 @pytest .fixture (scope = "class" )
1525 def spec_objects_fixtures_dir (self ) -> Path :
1626 return get_fixtures_dir () / "spec_objects"
@@ -24,98 +34,66 @@ async def initial_schema(self, default_branch: str, client: InfrahubClient, sche
2434 )
2535 assert resp .errors == {}
2636
27- async def test_load_tags (
28- self , client : InfrahubClient , default_branch : str , initial_schema : None , spec_objects_fixtures_dir : Path
29- ):
30- files = ObjectFile .load_from_disk (paths = [spec_objects_fixtures_dir / "animal_tags01.yml" ])
31- assert len (files ) == 1
32- obj_file = files [0 ]
37+ async def test_create_branch (self , client : InfrahubClient , initial_schema : None , branch_name : str ):
38+ await client .branch .create (branch_name = branch_name , sync_with_git = False )
3339
34- obj_file .validate_content ()
40+ async def test_load_tags (self , client : InfrahubClient , branch_name : str , initial_schema : None ):
41+ obj_file = load_object_file ("animal_tags01.yml" )
42+ await obj_file .validate_format (client = client , branch = branch_name )
3543
3644 # Check that the nodes are not present in the database before loading the file
37- assert len (await client .all (kind = obj_file .spec .kind )) == 0
45+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 0
3846
39- schema = await client .schema .get (kind = obj_file .spec .kind , branch = default_branch )
40- for item in obj_file .spec .data :
41- await obj_file .spec .create_node (client = client , schema = schema , data = item , branch = default_branch )
47+ await obj_file .process (client = client , branch = branch_name )
4248
43- assert len (await client .all (kind = obj_file .spec .kind )) == 3
49+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 3
4450
45- async def test_update_tags (
46- self , client : InfrahubClient , default_branch : str , initial_schema : None , spec_objects_fixtures_dir : Path
47- ):
48- files = ObjectFile .load_from_disk (paths = [spec_objects_fixtures_dir / "animal_tags02.yml" ])
49- assert len (files ) == 1
50- obj_file = files [0 ]
51-
52- obj_file .validate_content ()
51+ async def test_update_tags (self , client : InfrahubClient , branch_name : str , initial_schema : None ):
52+ obj_file = load_object_file ("animal_tags02.yml" )
53+ await obj_file .validate_format (client = client , branch = branch_name )
5354
5455 # Check that the nodes are not present in the database before loading the file
55- assert len (await client .all (kind = obj_file .spec .kind )) == 3
56+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 3
5657
57- schema = await client .schema .get (kind = obj_file .spec .kind , branch = default_branch )
58- for item in obj_file .spec .data :
59- await obj_file .spec .create_node (client = client , schema = schema , data = item , branch = default_branch )
58+ await obj_file .process (client = client , branch = branch_name )
6059
61- tags = await client .all (kind = obj_file .spec .kind )
60+ tags = await client .all (kind = obj_file .spec .kind , branch = branch_name )
6261 tags_by_name = {"__" .join (tag .get_human_friendly_id ()): tag for tag in tags }
6362 assert len (tags_by_name ) == 4
6463 assert tags_by_name ["Veterinarian" ].description .value == "Licensed animal healthcare professional"
6564
66- async def test_load_persons (
67- self , client : InfrahubClient , default_branch : str , initial_schema : None , spec_objects_fixtures_dir : Path
68- ):
69- files = ObjectFile .load_from_disk (paths = [spec_objects_fixtures_dir / "animal_person01.yml" ])
70- assert len (files ) == 1
71- obj_file = files [0 ]
72-
73- obj_file .validate_content ()
65+ async def test_load_persons (self , client : InfrahubClient , branch_name : str , initial_schema : None ):
66+ obj_file = load_object_file ("animal_person01.yml" )
67+ await obj_file .validate_format (client = client , branch = branch_name )
7468
7569 # Check that the nodes are not present in the database before loading the file
76- assert await client .all (kind = obj_file .spec .kind ) == []
70+ assert len ( await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 0
7771
78- schema = await client .schema .get (kind = obj_file .spec .kind , branch = default_branch )
79- for item in obj_file .spec .data :
80- await obj_file .spec .create_node (client = client , schema = schema , data = item , branch = default_branch )
72+ await obj_file .process (client = client , branch = branch_name )
8173
82- assert len (await client .all (kind = obj_file .spec .kind )) == 3
74+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 3
8375
84- async def test_load_dogs (
85- self , client : InfrahubClient , default_branch : str , initial_schema : None , spec_objects_fixtures_dir : Path
86- ):
87- files = ObjectFile .load_from_disk (paths = [spec_objects_fixtures_dir / "animal_dog01.yml" ])
88- assert len (files ) == 1
89- obj_file = files [0 ]
90-
91- obj_file .validate_content ()
76+ async def test_load_dogs (self , client : InfrahubClient , branch_name : str , initial_schema : None ):
77+ obj_file = load_object_file ("animal_dog01.yml" )
78+ await obj_file .validate_format (client = client , branch = branch_name )
9279
9380 # Check that the nodes are not present in the database before loading the file
94- assert await client .all (kind = obj_file .spec .kind ) == []
95-
96- schema = await client .schema .get (kind = obj_file .spec .kind , branch = default_branch )
97- for item in obj_file .spec .data :
98- await obj_file .spec .create_node (client = client , schema = schema , data = item , branch = default_branch )
81+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 0
9982
100- assert len ( await client . all ( kind = obj_file . spec . kind )) == 4
83+ await obj_file . process ( client = client , branch = branch_name )
10184
102- async def test_load_persons02 (
103- self , client : InfrahubClient , default_branch : str , initial_schema : None , spec_objects_fixtures_dir : Path
104- ):
105- files = ObjectFile .load_from_disk (paths = [spec_objects_fixtures_dir / "animal_person02.yml" ])
106- assert len (files ) == 1
107- obj_file = files [0 ]
85+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 4
10886
109- obj_file .validate_content ()
87+ async def test_load_persons02 (self , client : InfrahubClient , branch_name : str , initial_schema : None ):
88+ obj_file = load_object_file ("animal_person02.yml" )
89+ await obj_file .validate_format (client = client , branch = branch_name )
11090
11191 # Check that the nodes are not present in the database before loading the file
112- assert len (await client .all (kind = obj_file .spec .kind )) == 4
92+ assert len (await client .all (kind = obj_file .spec .kind , branch = branch_name )) == 4
11393
114- schema = await client .schema .get (kind = obj_file .spec .kind , branch = default_branch )
115- for item in obj_file .spec .data :
116- await obj_file .spec .create_node (client = client , schema = schema , data = item , branch = default_branch )
94+ await obj_file .process (client = client , branch = branch_name )
11795
118- persons = await client .all (kind = obj_file .spec .kind )
96+ persons = await client .all (kind = obj_file .spec .kind , branch = branch_name )
11997 person_by_name = {"__" .join (person .get_human_friendly_id ()): person for person in persons }
12098 assert len (persons ) == 5
12199
0 commit comments