@@ -1063,3 +1063,134 @@ async def test_delete_analysis(self):
10631063 resp ["confirm_delete_url" ],
10641064 "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/41?confirm_delete" ,
10651065 )
1066+
1067+ async def test_codeql_databases (self ):
1068+ response = create_response ()
1069+ response .json .return_value = [
1070+ {
1071+ "id" : 1 ,
1072+ "name" : "database.zip" ,
1073+ "language" : "java" ,
1074+ "uploader" : {
1075+ "login" : "octocat" ,
1076+ "id" : 1 ,
1077+ "node_id" : "MDQ6VXNlcjE=" ,
1078+ "avatar_url" : "https://github.com/images/error/octocat_happy.gif" ,
1079+ "gravatar_id" : "" ,
1080+ "url" : "https://api.github.com/users/octocat" ,
1081+ "html_url" : "https://github.com/octocat" ,
1082+ "followers_url" : "https://api.github.com/users/octocat/followers" ,
1083+ "following_url" : "https://api.github.com/users/octocat/following{/other_user}" ,
1084+ "gists_url" : "https://api.github.com/users/octocat/gists{/gist_id}" ,
1085+ "starred_url" : "https://api.github.com/users/octocat/starred{/owner}{/repo}" ,
1086+ "subscriptions_url" : "https://api.github.com/users/octocat/subscriptions" ,
1087+ "organizations_url" : "https://api.github.com/users/octocat/orgs" ,
1088+ "repos_url" : "https://api.github.com/users/octocat/repos" ,
1089+ "events_url" : "https://api.github.com/users/octocat/events{/privacy}" ,
1090+ "received_events_url" : "https://api.github.com/users/octocat/received_events" ,
1091+ "type" : "User" ,
1092+ "site_admin" : False ,
1093+ },
1094+ "content_type" : "application/zip" ,
1095+ "size" : 1024 ,
1096+ "created_at" : "2022-09-12T12:14:32Z" ,
1097+ "updated_at" : "2022-09-12T12:14:32Z" ,
1098+ "url" : "https://api.github.com/repos/octocat/Hello-World/code-scanning/codeql/databases/java" ,
1099+ "commit_oid" : 12345678901234567000 ,
1100+ },
1101+ {
1102+ "id" : 2 ,
1103+ "name" : "database.zip" ,
1104+ "language" : "ruby" ,
1105+ "uploader" : {
1106+ "login" : "octocat" ,
1107+ "id" : 1 ,
1108+ "node_id" : "MDQ6VXNlcjE=" ,
1109+ "avatar_url" : "https://github.com/images/error/octocat_happy.gif" ,
1110+ "gravatar_id" : "" ,
1111+ "url" : "https://api.github.com/users/octocat" ,
1112+ "html_url" : "https://github.com/octocat" ,
1113+ "followers_url" : "https://api.github.com/users/octocat/followers" ,
1114+ "following_url" : "https://api.github.com/users/octocat/following{/other_user}" ,
1115+ "gists_url" : "https://api.github.com/users/octocat/gists{/gist_id}" ,
1116+ "starred_url" : "https://api.github.com/users/octocat/starred{/owner}{/repo}" ,
1117+ "subscriptions_url" : "https://api.github.com/users/octocat/subscriptions" ,
1118+ "organizations_url" : "https://api.github.com/users/octocat/orgs" ,
1119+ "repos_url" : "https://api.github.com/users/octocat/repos" ,
1120+ "events_url" : "https://api.github.com/users/octocat/events{/privacy}" ,
1121+ "received_events_url" : "https://api.github.com/users/octocat/received_events" ,
1122+ "type" : "User" ,
1123+ "site_admin" : False ,
1124+ },
1125+ "content_type" : "application/zip" ,
1126+ "size" : 1024 ,
1127+ "created_at" : "2022-09-12T12:14:32Z" ,
1128+ "updated_at" : "2022-09-12T12:14:32Z" ,
1129+ "url" : "https://api.github.com/repos/octocat/Hello-World/code-scanning/codeql/databases/ruby" ,
1130+ "commit_oid" : 23456789012345680000 ,
1131+ },
1132+ ]
1133+
1134+ self .client .get_all .return_value = AsyncIteratorMock ([response ])
1135+
1136+ async_it = aiter (self .api .codeql_databases ("foo/bar" ))
1137+ db = await anext (async_it )
1138+ self .assertEqual (db .id , 1 )
1139+ alert = await anext (async_it )
1140+ self .assertEqual (alert .id , 2 )
1141+
1142+ with self .assertRaises (StopAsyncIteration ):
1143+ await anext (async_it )
1144+
1145+ self .client .get_all .assert_called_once_with (
1146+ "/repos/foo/bar/code-scanning/codeql/databases" ,
1147+ params = {
1148+ "per_page" : "100" ,
1149+ },
1150+ )
1151+
1152+ async def test_codeql_database (self ):
1153+ response = create_response ()
1154+ response .json .return_value = {
1155+ "id" : 1 ,
1156+ "name" : "database.zip" ,
1157+ "language" : "java" ,
1158+ "uploader" : {
1159+ "login" : "octocat" ,
1160+ "id" : 1 ,
1161+ "node_id" : "MDQ6VXNlcjE=" ,
1162+ "avatar_url" : "https://github.com/images/error/octocat_happy.gif" ,
1163+ "gravatar_id" : "" ,
1164+ "url" : "https://api.github.com/users/octocat" ,
1165+ "html_url" : "https://github.com/octocat" ,
1166+ "followers_url" : "https://api.github.com/users/octocat/followers" ,
1167+ "following_url" : "https://api.github.com/users/octocat/following{/other_user}" ,
1168+ "gists_url" : "https://api.github.com/users/octocat/gists{/gist_id}" ,
1169+ "starred_url" : "https://api.github.com/users/octocat/starred{/owner}{/repo}" ,
1170+ "subscriptions_url" : "https://api.github.com/users/octocat/subscriptions" ,
1171+ "organizations_url" : "https://api.github.com/users/octocat/orgs" ,
1172+ "repos_url" : "https://api.github.com/users/octocat/repos" ,
1173+ "events_url" : "https://api.github.com/users/octocat/events{/privacy}" ,
1174+ "received_events_url" : "https://api.github.com/users/octocat/received_events" ,
1175+ "type" : "User" ,
1176+ "site_admin" : False ,
1177+ },
1178+ "content_type" : "application/zip" ,
1179+ "size" : 1024 ,
1180+ "created_at" : "2022-09-12T12:14:32Z" ,
1181+ "updated_at" : "2022-09-12T12:14:32Z" ,
1182+ "url" : "https://api.github.com/repos/octocat/Hello-World/code-scanning/codeql/databases/java" ,
1183+ "commit_oid" : 12345678901234567000 ,
1184+ }
1185+ self .client .get .return_value = response
1186+
1187+ alert = await self .api .codeql_database (
1188+ "foo/bar" ,
1189+ "java" ,
1190+ )
1191+
1192+ self .client .get .assert_awaited_once_with (
1193+ "/repos/foo/bar/code-scanning/codeql/databases/java" ,
1194+ )
1195+
1196+ self .assertEqual (alert .id , 1 )
0 commit comments