def test_stage(self): mocked_repo = MagicMock() mocked_sanitize = MagicMock() mocked_queue = MagicMock() mocked_files = MagicMock(return_value=None) mocked_sanitize.return_value = ["to-stage"] current = CurrentView( repo=mocked_repo, repo_path="repo_path", queue=mocked_queue, ignore=CachedIgnore(), ) current._sanitize = mocked_sanitize current._get_files_from_path = mocked_files current._stage("message", ["add"], ["remove"]) mocked_queue.commit.assert_called_once_with(add=["to-stage"], remove=["to-stage"], message="message") mocked_repo.index.add.assert_called_once_with(["to-stage"]) mocked_repo.index.remove.assert_called_once_with(["to-stage"]) mocked_files.has_calls([call(["add"])]) mocked_sanitize.has_calls([call(["add"]), call(["remove"])])
def test_rename(self): mocked_re = MagicMock() mocked_index = MagicMock() mocked_os = MagicMock() mocked_result = MagicMock() mocked_result.rename.return_value = True mocked_re.sub.return_value = "new" mocked_os.path.split.return_value = [1, 1] with patch.multiple('gitfs.views.current', re=mocked_re, os=mocked_os): from gitfs.views import current as current_view old_rename = current_view.PassthroughView.rename current_view.PassthroughView.rename = lambda self, old, new: True current = CurrentView(regex="regex", repo="repo", repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_index result = current.rename("old", "new") assert result is True mocked_index.assert_called_once_with(**{ 'remove': 1, 'add': "new", "message": "Rename old to new" }) mocked_os.path.split.assert_called_once_with("old") current_view.PassthroughView.rename = old_rename
def test_chmod(self): from gitfs.views import current as current_view old_chmod = current_view.PassthroughView.chmod current_view.PassthroughView.chmod = lambda self, path, mode: "done" mocked_index = MagicMock() mocked_full = MagicMock(return_value="/path") mocked_repo = MagicMock(_full_path=mocked_full) current = CurrentView(repo=mocked_repo, uid=1, gid=1, repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_index assert current.chmod( "/path", 0o100644, ) == "done" message = 'Chmod to 0%o on %s' % (0o644, "/path") mocked_index.assert_called_once_with(add="/path", message=message) current_view.PassthroughView.chmod = old_chmod
def test_stage(self): mocked_repo = MagicMock() mocked_sanitize = MagicMock() mocked_queue = MagicMock() mocked_sanitize.return_value = ["to-stage"] current = CurrentView(repo=mocked_repo, repo_path="repo_path", queue=mocked_queue, ignore=CachedIgnore("f")) current._sanitize = mocked_sanitize current._stage("message", ["add"], ["remove"]) mocked_queue.commit.assert_called_once_with(add=['to-stage'], remove=['to-stage'], message="message") mocked_repo.index.add.assert_called_once_with(["to-stage"]) mocked_repo.index.remove.assert_called_once_with(["to-stage"]) mocked_sanitize.has_calls([call(['add']), call(['remove'])])
def test_unlink(self): from gitfs.views import current as current_view old_unlink = current_view.PassthroughView.unlink current_view.PassthroughView.unlink = lambda me, path: "done" mocked_index = MagicMock() current = CurrentView(repo="repo", uid=1, gid=1, repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_index assert current.unlink("/path") == "done" message = "Deleted /path" mocked_index.assert_called_once_with(remove="/path", message=message) current_view.PassthroughView.unlink = old_unlink
def test_fsync(self): from gitfs.views import current as current_view old_fsync = current_view.PassthroughView.fsync current_view.PassthroughView.fsync = lambda me, path, data, fh: "done" mocked_index = MagicMock() current = CurrentView(repo="repo", uid=1, gid=1, repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_index assert current.fsync("/path", "data", 1) == "done" message = "Fsync /path" mocked_index.assert_called_once_with(add="/path", message=message) current_view.PassthroughView.fsync = old_fsync
def test_release_without_stage(self): message = "No need to stage this" mocked_os = MagicMock() mocked_stage = MagicMock() mocked_os.close.return_value = 0 with patch.multiple('gitfs.views.current', os=mocked_os): current = CurrentView(repo="repo", repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_stage current.dirty = {4: {'message': message, 'stage': False}} assert current.release("/path", 4) == 0 mocked_os.close.assert_called_once_with(4) assert mocked_stage.call_count == 0
def test_release_with_stage(self): message = "I need to stage this" mocked_os = MagicMock() mocked_stage = MagicMock() mocked_os.close.return_value = 0 with patch.multiple("gitfs.views.current", os=mocked_os): current = CurrentView(repo="repo", repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_stage current.dirty = {4: {"message": message, "stage": True}} assert current.release("/path", 4) == 0 mocked_os.close.assert_called_once_with(4) mocked_stage.assert_called_once_with(add="/path", message=message)
def test_symlink(self): mocked_index = MagicMock() mocked_repo = MagicMock() mocked_full_path = MagicMock() mocked_full_path.return_value = "full_path" mocked_repo._full_path = mocked_full_path with patch('gitfs.views.current.os') as mocked_os: mocked_os.symlink.return_value = "done" current = CurrentView(repo=mocked_repo, repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_index assert current.symlink("name", "target") == "done" mocked_os.symlink.assert_called_once_with("target", "full_path") mocked_full_path.assert_called_once_with("name") message = "Create symlink to target for name" mocked_index.assert_called_once_with(add="name", message=message)
def test_chmod(self): from gitfs.views import current as current_view old_chmod = current_view.PassthroughView.chmod current_view.PassthroughView.chmod = lambda self, path, mode: "done" mocked_index = MagicMock() mocked_full = MagicMock(return_value="/path") mocked_repo = MagicMock(_full_path=mocked_full) current = CurrentView(repo=mocked_repo, uid=1, gid=1, repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_index assert current.chmod("/path", 0100644) == "done" message = 'Chmod to %s on %s' % (str(oct(0644))[-4:], "/path") mocked_index.assert_called_once_with(add="/path", message=message) current_view.PassthroughView.chmod = old_chmod
def test_release(self): message = "I need to stage this" mocked_os = MagicMock() mocked_stage = MagicMock() mocked_os.close.return_value = 0 with patch.multiple('gitfs.views.current', os=mocked_os): current = CurrentView(repo="repo", repo_path="repo_path", ignore=CachedIgnore()) current._stage = mocked_stage current.dirty = { 4: { 'message': message } } assert current.release("/path", 4) == 0 mocked_os.close.assert_called_once_with(4) mocked_stage.assert_called_once_with(add="/path", message=message)