Example #1
0
    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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    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)
Example #5
0
    def test_create(self):
        from gitfs.views import current as current_view
        old_chmod = current_view.PassthroughView.chmod
        mock_chmod = lambda self, path, mode: "done"
        current_view.PassthroughView.chmod = mock_chmod

        mocked_open = MagicMock()
        mocked_open.return_value = "done"
        current = CurrentView(repo="repo", uid=1, gid=1,
                              repo_path="repo_path",
                              ignore=CachedIgnore())
        current.dirty = {
            '/path': {
                'content': "here"
            }
        }
        current.open_for_write = mocked_open

        assert current.create("/path", "mode") == "done"
        current_view.PassthroughView.chmod = old_chmod
Example #6
0
    def test_write(self):
        from gitfs.views import current as current_view

        mocked_write = lambda self, path, buf, offste, fh: "done"
        old_write = current_view.PassthroughView.write
        current_view.PassthroughView.write = mocked_write

        current = CurrentView(
            repo="repo",
            uid=1,
            gid=1,
            repo_path="repo_path",
            read_only=Event(),
            ignore=CachedIgnore(),
        )
        current.max_offset = 20
        current.max_size = 20
        current.dirty = {1: {}}

        assert current.write("/path", "buf", 3, 1) == "done"
        assert current.dirty == {1: {"message": "Update /path", "stage": True}}
        current_view.PassthroughView.write = old_write
Example #7
0
    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)
Example #8
0
    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'])])
Example #9
0
    def test_chmod_on_dir(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_full = MagicMock(return_value="repo/path/to/dir")
        mocked_repo = MagicMock(_full_path=mocked_full)

        with patch('gitfs.views.current.os') as mocked_os:
            mocked_os.path.isdir.return_value = True

            current = CurrentView(repo=mocked_repo,
                                  uid=1,
                                  gid=1,
                                  repo_path="repo_path",
                                  ignore=CachedIgnore())
            assert current.chmod(
                "/path/to/dir",
                0o040755,
            ) == "done"

            mocked_os.path.isdir.assert_called_once_with('repo/path/to/dir')

        current_view.PassthroughView.chmod = old_chmod
Example #10
0
 def test_rename_in_git_dir(self):
     current = CurrentView(repo="repo",
                           repo_path="repo_path",
                           ignore=CachedIgnore())
     with pytest.raises(FuseOSError):
         current.rename(".git/", ".git/")
Example #11
0
    def test_unlink_from_git_dir(self):
        current = CurrentView(repo="repo", repo_path="repo_path",
                              ignore=CachedIgnore())

        with pytest.raises(FuseOSError):
            current.unlink(".git/")
Example #12
0
 def test_chmod_in_git_dir(self):
     current = CurrentView(repo="repo", uid=1, gid=1,
                           repo_path="repo_path",
                           ignore=CachedIgnore())
     with pytest.raises(FuseOSError):
         current.chmod(".git/", "mode")