1010from infrahub .core .constants import InfrahubKind , RepositoryInternalStatus
1111from infrahub .exceptions import RepositoryError
1212from infrahub .git import InfrahubRepository
13+ from infrahub .git .models import GitRepositoryPullReadOnly
1314from infrahub .git .repository import InfrahubReadOnlyRepository
15+ from infrahub .git .tasks import pull_read_only
1416from infrahub .lock import InfrahubLockRegistry
1517from infrahub .message_bus import Meta , messages
1618from infrahub .message_bus .operations import git
17- from infrahub .services import InfrahubServices
19+ from infrahub .services import InfrahubServices , services
20+ from infrahub .services .adapters .workflow .local import WorkflowLocalExecution
1821from tests .helpers .test_client import dummy_async_request
1922
2023# pylint: disable=redefined-outer-name
@@ -230,16 +233,18 @@ class TestPullReadOnly:
230233 def setup_method (self ):
231234 self .client = AsyncMock (spec = InfrahubClient )
232235 self .git_report = AsyncContextManagerMock ()
233- self .services = InfrahubServices (client = self .client )
234- self .services .git_report = self .git_report
236+ self .original_services = services .service
237+ services .service = InfrahubServices (client = self .client , workflow = WorkflowLocalExecution ())
238+ services .service .git_report = self .git_report
239+
235240 self .commit = str (UUIDT ())
236241 self .infrahub_branch_name = "read-only-branch"
237242 self .repo_id = str (UUIDT ())
238243 self .location = "/some/directory/over/here"
239244 self .repo_name = "dont-update-this-dude"
240245 self .ref = "stable-branch"
241246
242- self .message = messages . GitRepositoryPullReadOnly (
247+ self .model = GitRepositoryPullReadOnly (
243248 location = self .location ,
244249 repository_id = self .repo_id ,
245250 repository_name = self .repo_name ,
@@ -248,31 +253,30 @@ def setup_method(self):
248253 infrahub_branch_name = self .infrahub_branch_name ,
249254 )
250255
251- lock_patcher = patch ("infrahub.message_bus.operations. git.repository .lock" )
256+ lock_patcher = patch ("infrahub.git.tasks .lock" )
252257 self .mock_infra_lock = lock_patcher .start ()
253- self .mock_infra_lock .registry = AsyncMock (spec = InfrahubLockRegistry )
254- repo_class_patcher = patch (
255- "infrahub.message_bus.operations.git.repository.InfrahubReadOnlyRepository" , spec = InfrahubReadOnlyRepository
256- )
258+ self .mock_infra_lock .registry = AsyncMock (spec = InfrahubLockRegistry ) # TODO fix mock?
259+ repo_class_patcher = patch ("infrahub.git.tasks.InfrahubReadOnlyRepository" , spec = InfrahubReadOnlyRepository )
257260 self .mock_repo_class = repo_class_patcher .start ()
258261 self .mock_repo = AsyncMock (spec = InfrahubReadOnlyRepository )
259262 self .mock_repo_class .new .return_value = self .mock_repo
260263 self .mock_repo_class .init .return_value = self .mock_repo
261264
262265 def teardown_method (self ):
263266 patch .stopall ()
267+ services .service = self .original_services
264268
265269 async def test_improper_message (self ):
266- self .message .ref = None
267- self .message .commit = None
270+ self .model .ref = None
271+ self .model .commit = None
268272
269- await git . repository . pull_read_only (message = self .message , service = self . services )
273+ await pull_read_only (model = self .model )
270274
271275 self .mock_repo_class .new .assert_not_awaited ()
272276 self .mock_repo_class .init .assert_not_awaited ()
273277
274278 async def test_existing_repository (self ):
275- await git . repository . pull_read_only (message = self .message , service = self . services )
279+ await pull_read_only (model = self .model )
276280
277281 self .mock_infra_lock .registry .get (name = self .repo_name , namespace = "repository" )
278282 self .mock_repo_class .init .assert_awaited_once_with (
@@ -292,7 +296,7 @@ async def test_existing_repository(self):
292296 async def test_new_repository (self ):
293297 self .mock_repo_class .init .side_effect = RepositoryError (self .repo_name , "it is broken" )
294298
295- await git . repository . pull_read_only (message = self .message , service = self . services )
299+ await pull_read_only (model = self .model )
296300
297301 self .mock_infra_lock .registry .get (name = self .repo_name , namespace = "repository" )
298302 self .mock_repo_class .init .assert_awaited_once_with (
0 commit comments