44
55from  infrahub_sdk  import  InfrahubClient 
66from  infrahub_sdk .schema  import  SchemaRoot 
7+ from  infrahub_sdk .spec .menu  import  MenuFile 
78from  infrahub_sdk .spec .object  import  ObjectFile 
89from  infrahub_sdk .testing .docker  import  TestInfrahubDockerClient 
910from  infrahub_sdk .testing .schemas .animal  import  SchemaAnimal 
@@ -16,6 +17,12 @@ def load_object_file(name: str) -> ObjectFile:
1617    return  files [0 ]
1718
1819
20+ def  load_menu_file (name : str ) ->  MenuFile :
21+     files  =  MenuFile .load_from_disk (paths = [get_fixtures_dir () /  "spec_objects"  /  name ])
22+     assert  len (files ) ==  1 
23+     return  files [0 ]
24+ 
25+ 
1926class  TestSpecObject (TestInfrahubDockerClient , SchemaAnimal ):
2027    @pytest .fixture (scope = "class" ) 
2128    def  branch_name (self ) ->  str :
@@ -115,3 +122,17 @@ async def test_load_persons02(self, client: InfrahubClient, branch_name: str, in
115122        await  person_by_name ["Emily Parker" ].animals .fetch ()
116123        animals_emily  =  [animal .display_label  for  animal  in  person_by_name ["Emily Parker" ].animals .peers ]
117124        assert  sorted (animals_emily ) ==  sorted (["Max Golden Retriever" , "Whiskers Siamese #FFD700" ])
125+ 
126+     async  def  test_load_menu (self , client : InfrahubClient , branch_name : str , initial_schema : None ):
127+         menu_file  =  load_menu_file ("animal_menu01.yml" )
128+         await  menu_file .validate_format (client = client , branch = branch_name )
129+ 
130+         await  menu_file .process (client = client , branch = branch_name )
131+ 
132+         menu  =  await  client .filters (kind = menu_file .spec .kind , protected__value = False , branch = branch_name )
133+         assert  len (menu ) ==  3 
134+ 
135+         menu_by_name  =  {menu .display_label : menu  for  menu  in  menu }
136+         await  menu_by_name ["Animals" ].children .fetch ()
137+         peer_labels  =  [peer .display_label  for  peer  in  menu_by_name ["Animals" ].children .peers ]
138+         assert  sorted (peer_labels ) ==  sorted (["Dog" , "Cat" ])
0 commit comments