@@ -392,3 +392,81 @@ def test_cli_api_openapi_diagnostics(monkeypatch, capsys):
392392 assert rc == 0
393393 out = capsys .readouterr ().out
394394 assert "suggest --param for: q,limit" in out
395+
396+
397+ def test_extract_name_string_passthrough ():
398+ from zyra .connectors .discovery .api_search import _extract_name
399+
400+ assert _extract_name ("hello" ) == "hello"
401+ assert _extract_name (None ) is None
402+ assert _extract_name (42 ) == "42"
403+
404+
405+ def test_extract_name_drills_into_dict ():
406+ from zyra .connectors .discovery .api_search import _extract_name
407+
408+ assert (
409+ _extract_name ({"name" : "Synoptic-UAS" , "path" : "data/Synoptic-UAS" })
410+ == "Synoptic-UAS"
411+ )
412+ assert _extract_name ({"path" : "data/Synoptic-UAS" }) == "data/Synoptic-UAS"
413+ assert _extract_name ({"title" : "My Title" }) == "My Title"
414+ assert _extract_name ({"id" : "abc123" }) == "abc123"
415+ assert _extract_name ({"label" : "Atmospheric CO2" }) == "Atmospheric CO2"
416+ # Non-string values in name-like keys should be stringified
417+ assert _extract_name ({"id" : 123 }) == "123"
418+ assert _extract_name ({"name" : 42 }) == "42"
419+ # Nested dict in a name-like key is recursively drilled into
420+ assert _extract_name ({"name" : {"id" : "x" }}) == "x"
421+ assert _extract_name ({"name" : {"title" : "inner" , "id" : "y" }}) == "inner"
422+
423+
424+ def test_normalize_item_nested_dataset_dict ():
425+ from zyra .connectors .discovery .api_search import _normalize_item
426+
427+ item = {
428+ "dataset" : {"path" : "data/Synoptic-UAS" , "name" : "Synoptic-UAS" },
429+ "score" : 1 ,
430+ }
431+ row = _normalize_item (item , "example.com" )
432+ assert row ["dataset" ] == "Synoptic-UAS"
433+ assert row ["source" ] == "example.com"
434+
435+
436+ def test_normalize_item_nested_dataset_dict_no_name ():
437+ from zyra .connectors .discovery .api_search import _normalize_item
438+
439+ item = {"dataset" : {"path" : "data/foo" }}
440+ row = _normalize_item (item , "host" )
441+ assert row ["dataset" ] == "data/foo"
442+
443+
444+ def test_normalize_item_nested_description_and_link ():
445+ from zyra .connectors .discovery .api_search import _normalize_item
446+
447+ item = {
448+ "name" : "DS1" ,
449+ "description" : {"title" : "A long description object" },
450+ "uri" : {"path" : "http://example.com/ds1" },
451+ }
452+ row = _normalize_item (item , "host" )
453+ assert row ["dataset" ] == "DS1"
454+ assert row ["description" ] == "A long description object"
455+ assert row ["link" ] == "http://example.com/ds1"
456+
457+
458+ def test_extract_name_url_like_dict_keys ():
459+ from zyra .connectors .discovery .api_search import _extract_name
460+
461+ assert _extract_name ({"url" : "http://x/data" }) == "http://x/data"
462+ assert _extract_name ({"href" : "http://x/ref" }) == "http://x/ref"
463+ assert _extract_name ({"uri" : "http://x/uri" }) == "http://x/uri"
464+ assert _extract_name ({"link" : "http://x/link" }) == "http://x/link"
465+
466+
467+ def test_normalize_item_href_link ():
468+ from zyra .connectors .discovery .api_search import _normalize_item
469+
470+ item = {"name" : "DS" , "href" : "http://example.com/ds" }
471+ row = _normalize_item (item , "host" )
472+ assert row ["link" ] == "http://example.com/ds"
0 commit comments