@@ -154,22 +154,25 @@ async def mock_getiter(*args, **kwargs):
154154@pytest .fixture
155155def get_mock_github_api ():
156156 def _get_mock_github_api (return_data , installation_id = 12345 ):
157- from django_github_app .github import SyncGitHubAPI
158-
159- mock_api = MagicMock (spec = SyncGitHubAPI )
157+ # For sync tests, we still need an async mock because get_gh_client
158+ # always returns AsyncGitHubAPI, even when used through async_to_sync.
159+ # long term, we'll probably need to just duplicate the code between
160+ # sync and async versions instead of relying on async_to_sync/sync_to_async
161+ # from asgiref, so we'll keep this separate sync mock github api client
162+ # around so we can swap the internals out without changing tests (hopefully)
163+ mock_api = AsyncMock (spec = AsyncGitHubAPI )
160164
161- def mock_getitem (* args , ** kwargs ):
165+ async def mock_getitem (* args , ** kwargs ):
162166 return return_data
163167
164- def mock_getiter (* args , ** kwargs ):
165- yield from return_data
166-
167- def mock_post (* args , ** kwargs ):
168- pass
168+ async def mock_getiter (* args , ** kwargs ):
169+ for data in return_data :
170+ yield data
169171
170172 mock_api .getitem = mock_getitem
171173 mock_api .getiter = mock_getiter
172- mock_api .post = mock_post
174+ mock_api .__aenter__ .return_value = mock_api
175+ mock_api .__aexit__ .return_value = None
173176 mock_api .installation_id = installation_id
174177
175178 return mock_api
@@ -178,11 +181,11 @@ def mock_post(*args, **kwargs):
178181
179182
180183@pytest .fixture
181- def installation (aget_mock_github_api , baker ):
184+ def installation (get_mock_github_api , baker ):
182185 installation = baker .make (
183186 "django_github_app.Installation" , installation_id = seq .next ()
184187 )
185- mock_github_api = aget_mock_github_api (
188+ mock_github_api = get_mock_github_api (
186189 [
187190 {"id" : seq .next (), "node_id" : "node1" , "full_name" : "owner/repo1" },
188191 {"id" : seq .next (), "node_id" : "node2" , "full_name" : "owner/repo2" },
@@ -210,14 +213,14 @@ async def ainstallation(aget_mock_github_api, baker):
210213
211214
212215@pytest .fixture
213- def repository (installation , aget_mock_github_api , baker ):
216+ def repository (installation , get_mock_github_api , baker ):
214217 repository = baker .make (
215218 "django_github_app.Repository" ,
216219 repository_id = seq .next (),
217220 full_name = "owner/repo" ,
218221 installation = installation ,
219222 )
220- mock_github_api = aget_mock_github_api (
223+ mock_github_api = get_mock_github_api (
221224 [
222225 {
223226 "number" : 1 ,
0 commit comments