@@ -20,27 +20,43 @@ def expected_resource_namespaces() -> set[str]:
2020 }
2121
2222
23+ def expected_resource_surface () -> dict [str , dict [str , object ]]:
24+ spec = load_json (NORMALIZED_SPEC_PATH )
25+ resources : dict [str , dict [str , object ]] = {}
26+ for path_item in spec .get ("paths" , {}).values ():
27+ for method , operation in path_item .items ():
28+ if method .startswith ("x-" ):
29+ continue
30+
31+ namespace = operation ["x-sdk-resource" ]
32+ resource = resources .setdefault (
33+ namespace ,
34+ {
35+ "class_name" : operation ["x-sdk-class-name" ],
36+ "method_names" : set (),
37+ },
38+ )
39+ resource ["method_names" ].add (operation ["x-sdk-method-name" ])
40+ return resources
41+
42+
2343def test_generated_resource_registry_matches_public_api_surface ():
24- assert set ( RESOURCE_CLASSES ) = = expected_resource_namespaces ()
25- assert { "douyin" , "douyin_xingtu" , "xiaohongshu_pgy" , "twitter" }. issubset (
26- RESOURCE_CLASSES
27- )
44+ expected_namespaces = expected_resource_namespaces ()
45+
46+ assert expected_namespaces
47+ assert set ( RESOURCE_CLASSES ) == expected_namespaces
2848
2949
3050def test_client_exposes_generated_resources ():
3151 client = JustOneAPIClient (token = "test-token" )
3252 try :
33- assert type (client .douyin ).__name__ == "DouyinResource"
34- assert type (client .douyin_xingtu ).__name__ == "DouyinXingtuResource"
35- assert type (client .xiaohongshu_pgy ).__name__ == "XiaohongshuPgyResource"
36- assert hasattr (client .search , "search_v1" )
37- assert hasattr (client .weixin , "get_article_comment_v1" )
38- assert hasattr (client .weixin , "get_article_feedback_v1" )
39- assert hasattr (client .weixin , "get_user_post_v1" )
40- assert hasattr (client .bilibili , "get_user_relation_stat_v1" )
41- assert hasattr (client .bilibili , "get_video_caption_v2" )
42- assert hasattr (client .douyin , "get_video_detail_v2" )
43- assert hasattr (client .twitter , "get_user_posts_v1" )
53+ for namespace , expected in expected_resource_surface ().items ():
54+ assert hasattr (client , namespace )
55+
56+ resource = getattr (client , namespace )
57+ assert type (resource ).__name__ == expected ["class_name" ]
58+ for method_name in expected ["method_names" ]:
59+ assert hasattr (resource , method_name )
4460 finally :
4561 client .close ()
4662
0 commit comments