@@ -392,3 +392,63 @@ async def test_display_schema_load_errors_details_namespace(mock_get_node) -> No
392392 Node: OuTInstance | namespace (OuT) | String should match pattern '^[A-Z]+$' (string_pattern_mismatch)
393393"""
394394 assert output == expected_console
395+
396+
397+ @mock .patch (
398+ "infrahub_sdk.ctl.schema.get_node" ,
399+ return_value = {
400+ "name" : "TailscaleSSHRule" ,
401+ "namespace" : "Security" ,
402+ "icon" : "mdi:security" ,
403+ "inherit_from" : ["SecurityRule" ],
404+ "attributes" : [
405+ {
406+ "name" : "check_period" ,
407+ "kind" : "Number" ,
408+ "optional" : True ,
409+ "default_value" : 720 ,
410+ "min_value" : 0 ,
411+ "max_value" : 10080 ,
412+ },
413+ {"name" : "accept_env" , "kind" : "List" , "optional" : True },
414+ {
415+ "name" : "action" ,
416+ "optional" : True ,
417+ "kind" : "Dropdown" ,
418+ "default_value" : "allow" ,
419+ "choices" : [
420+ {"label" : "allow" , "name" : "allow" },
421+ {"label" : "check" , "name" : "check" },
422+ ],
423+ },
424+ ],
425+ },
426+ )
427+ async def test_display_schema_load_errors_details_when_error_is_in_attribute_or_relationship (mock_get_node ) -> None :
428+ """Validate error message with details when loading schema and errors are in attribute or relationship."""
429+ error = {
430+ "detail" : [
431+ {
432+ "type" : "extra_forbidden" ,
433+ "loc" : ["body" , "schemas" , 0 , "nodes" , 4 , "attributes" , "min_value" ],
434+ "msg" : "Extra inputs are not permitted" ,
435+ "input" : 0 ,
436+ },
437+ {
438+ "type" : "extra_forbidden" ,
439+ "loc" : ["body" , "schemas" , 0 , "nodes" , 4 , "attributes" , "max_value" ],
440+ "msg" : "Extra inputs are not permitted" ,
441+ "input" : 10080 ,
442+ },
443+ ]
444+ }
445+
446+ with mock .patch ("infrahub_sdk.ctl.schema.console" , Console (file = StringIO (), width = 1000 )) as console :
447+ display_schema_load_errors (response = error , schemas_data = [])
448+ assert mock_get_node .call_count == 2
449+ output = console .file .getvalue ()
450+ expected_console = """Unable to load the schema:
451+ Node: SecurityTailscaleSSHRule | Attribute: check_period (0) | Extra inputs are not permitted (extra_forbidden)
452+ Node: SecurityTailscaleSSHRule | Attribute: check_period (10080) | Extra inputs are not permitted (extra_forbidden)
453+ """
454+ assert output == expected_console
0 commit comments