test(git): align route mocks with async services
This commit is contained in:
@@ -434,20 +434,19 @@ class TestHandleSync:
|
||||
mock_env.name = "Test Env"
|
||||
mock_cm.get_environment.return_value = mock_env
|
||||
|
||||
with patch('src.plugins.git_plugin.run_blocking') as mock_run_blocking:
|
||||
# Mock git repo
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tmpdir
|
||||
mock_repo.git = MagicMock()
|
||||
mock_repo.git.add = MagicMock()
|
||||
# Mock git repo
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tmpdir
|
||||
mock_repo.git = MagicMock()
|
||||
mock_repo.git.add = MagicMock()
|
||||
|
||||
with patch.object(plugin.git_service, 'get_repo', new_callable=AsyncMock) as mock_get_repo, \
|
||||
patch('src.plugins.git_plugin.run_blocking') as mock_run_blocking:
|
||||
|
||||
mock_get_repo.return_value = mock_repo
|
||||
|
||||
# Setup run_blocking side effects based on kind
|
||||
async def run_blocking_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
if kind == 'git' and fn == mock_repo.git.add:
|
||||
return None
|
||||
if fn.__name__ == '_create_sync_backup':
|
||||
return None
|
||||
if fn.__name__ == '_delete_managed_files':
|
||||
@@ -486,10 +485,10 @@ class TestHandleSync:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
mock_repo.git = MagicMock()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
async def rb_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
if kind == 'git' and fn == mock_repo.git.add:
|
||||
return None
|
||||
return None
|
||||
@@ -521,15 +520,16 @@ class TestHandleSync:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
mock_repo.git = MagicMock()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
mock_repo.git.add = MagicMock()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
call_count = 0
|
||||
|
||||
async def rb_side(kind='file', fn=None, **kwargs):
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
if kind == 'git' and fn == mock_repo.git.add:
|
||||
raise RuntimeError("git add failed")
|
||||
return None
|
||||
@@ -559,10 +559,10 @@ class TestHandleSync:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
mock_repo.git = MagicMock()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
async def run_blocking_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
if fn.__name__ == '_extract_zip_to_repo':
|
||||
raise ValueError("Unzip failed")
|
||||
if fn.__name__ == '_restore_sync_backup':
|
||||
@@ -595,10 +595,10 @@ class TestHandleSync:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
mock_repo.git = MagicMock()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
async def rb_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
return None
|
||||
|
||||
mock_run_blocking.side_effect = rb_side
|
||||
@@ -630,10 +630,10 @@ class TestHandleDeploy:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
mock_repo.git = MagicMock()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
async def rb_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
if fn.__name__ == '_pack_deploy_zip':
|
||||
return None
|
||||
if fn == Path.write_bytes:
|
||||
@@ -669,10 +669,10 @@ class TestHandleDeploy:
|
||||
with patch('src.plugins.git_plugin.run_blocking') as mock_run_blocking:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
async def rb_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
if fn.__name__ == '_pack_deploy_zip':
|
||||
return None
|
||||
if fn == Path.write_bytes:
|
||||
@@ -712,10 +712,10 @@ class TestHandleDeploy:
|
||||
with patch('src.plugins.git_plugin.run_blocking') as mock_run_blocking:
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.working_dir = tempfile.mkdtemp()
|
||||
plugin.git_service.get_repo = AsyncMock(return_value=mock_repo)
|
||||
|
||||
async def rb_side(kind='file', fn=None, **kwargs):
|
||||
if kind == 'git' and fn == plugin.git_service.get_repo:
|
||||
return mock_repo
|
||||
|
||||
return None
|
||||
|
||||
mock_run_blocking.side_effect = rb_side
|
||||
|
||||
Reference in New Issue
Block a user