Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 91fd9cd

Browse files
Update tests
1 parent 7c0bf38 commit 91fd9cd

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

graphql_api/tests/test_owner.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,25 +1196,35 @@ def test_fetch_available_plans_is_enterprise_plan(self):
11961196

11971197
@patch("services.self_hosted.get_config")
11981198
def test_ai_enabled_repositories(self, get_config_mock):
1199-
current_org = OwnerFactory(
1200-
username="random-plan-user",
1201-
service="github",
1202-
)
1203-
12041199
get_config_mock.return_value = [
12051200
{"service": "github", "ai_features_app_id": 12345},
12061201
]
12071202

1203+
ai_app_installation = GithubAppInstallation(
1204+
name="ai-features",
1205+
owner=self.owner,
1206+
repository_service_ids=[],
1207+
installation_id=12345,
1208+
)
1209+
1210+
ai_app_installation.save()
1211+
12081212
query = """{
12091213
owner(username: "%s") {
1210-
aiEnabledRepos
1214+
aiEnabledRepositories(first: 20) {
1215+
edges {
1216+
node {
1217+
name
1218+
}
1219+
}
1220+
}
12111221
}
12121222
}
12131223
1214-
""" % (current_org.username)
1215-
data = self.gql_request(query, owner=current_org)
1216-
assert data["owner"]["aiEnabledRepos"] is None
1217-
1224+
""" % (self.owner.username)
1225+
data = self.gql_request(query, owner=self.owner)
1226+
reps = paginate_connection(data["owner"]["aiEnabledRepositories"])
1227+
assert reps == [{'name': 'a'}, {'name': 'b'}]
12181228

12191229
@patch("services.self_hosted.get_config")
12201230
def test_ai_enabled_repositories_app_not_configured(self, get_config_mock):
@@ -1229,13 +1239,19 @@ def test_ai_enabled_repositories_app_not_configured(self, get_config_mock):
12291239

12301240
query = """{
12311241
owner(username: "%s") {
1232-
aiEnabledRepos
1242+
aiEnabledRepositories {
1243+
edges {
1244+
node {
1245+
name
1246+
}
1247+
}
1248+
}
12331249
}
12341250
}
12351251
12361252
""" % (current_org.username)
12371253
data = self.gql_request(query, owner=current_org)
1238-
assert data["owner"]["aiEnabledRepos"] is None
1254+
assert data["owner"]["aiEnabledRepositories"] is None
12391255

12401256
def test_fetch_owner_with_no_service(self):
12411257
current_org = OwnerFactory(

graphql_api/types/owner/owner.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Owner {
4747
after: String
4848
last: Int
4949
before: String
50-
): RepositoryConnection! @cost(complexity: 25, multipliers: ["first", "last"])
50+
): RepositoryConnection @cost(complexity: 25, multipliers: ["first", "last"])
5151
uploadTokenRequired: Boolean
5252
activatedUserCount: Int
5353
}

graphql_api/types/owner/owner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
Connection,
3333
build_connection_graphql,
3434
queryset_to_connection,
35+
queryset_to_connection_sync,
3536
)
3637
from graphql_api.helpers.mutation import (
3738
require_part_of_org,
@@ -406,7 +407,9 @@ def resolve_activated_user_count(owner: Owner, info: GraphQLResolveInfo) -> int:
406407
def resolve_billing(owner: Owner, info: GraphQLResolveInfo) -> dict | None:
407408
return owner
408409

410+
409411
@owner_bindable.field("aiEnabledRepositories")
412+
@sync_to_async
410413
def resolve_ai_enabled_repositories(
411414
owner: Owner,
412415
info: GraphQLResolveInfo,
@@ -423,15 +426,14 @@ def resolve_ai_enabled_repositories(
423426

424427
current_owner = info.context["request"].current_owner
425428
queryset = Repository.objects.filter(author=owner).viewable_repos(current_owner)
426-
427429
if ai_features_app_install.repository_service_ids:
428430
queryset = queryset.filter(
429431
service_id__in=ai_features_app_install.repository_service_ids
430432
)
431433

432-
return queryset_to_connection(
434+
return queryset_to_connection_sync(
433435
queryset,
434436
ordering=(ordering, RepositoryOrdering.ID),
435437
ordering_direction=ordering_direction,
436438
**kwargs,
437-
)
439+
)

0 commit comments

Comments
 (0)