Пример #1
0
    def test_has_uncommitted_changes(self):
        def custom_side_effect(arg):
            if arg == 'HEAD':
                return []
            return ['foo.py']

        cg = CivisGit()
        cg.repo = MagicMock(spec=Repo)
        cg.repo().index.diff = MagicMock(side_effect=custom_side_effect)

        self.assertTrue(cg.has_uncommitted_changes())
Пример #2
0
    def get(self):
        response = dict()
        civis_git = CivisGit()

        if not civis_git.is_git_enabled():
            self.set_status(404, 'Not a git enabled notebook')
        else:
            has_changes = False
            try:
                has_changes = civis_git.has_uncommitted_changes()
            except CivisGitError:
                pass

            response['dirty'] = has_changes
            self.set_status(200)
        self.finish(response)
Пример #3
0
 def test_has_uncommitted_changes_throws_error(self):
     cg = CivisGit()
     cg.repo = MagicMock(spec=Repo)
     cg.repo().index.diff = MagicMock(
         side_effect=GitCommandError('diff', 'failed'))
     self.assertRaises(CivisGitError, lambda: cg.has_uncommitted_changes())
Пример #4
0
    def test_has_no_uncommitted_changes(self):
        cg = CivisGit()
        cg.repo = MagicMock(spec=Repo)
        cg.repo().index.diff = MagicMock(return_value=[])

        self.assertFalse(cg.has_uncommitted_changes())
Пример #5
0
 def test_is_git_enabled_returns_true(self):
     self.assertTrue(CivisGit().is_git_enabled())
Пример #6
0
 def test_is_git_enabled_returns_false(self, env):
     env.return_value = None
     cg = CivisGit()
     self.assertFalse(cg.is_git_enabled())
Пример #7
0
    def test_clone_repository_succeeds(self, repo_clone):
        repo_clone.return_value = MagicMock(spec=Repo)
        CivisGit(repo_mount_path=REPO_MOUNT_PATH).clone_repository()

        repo_clone.assert_called_with(REPO_URL, REPO_MOUNT_PATH)
        repo_clone.return_value.git.checkout.assert_called_with(GIT_REPO_REF)
Пример #8
0
 def test_clone_repository_throws_error(self, repo_clone):
     repo_clone.side_effect = GitCommandError('clone', 'failed')
     self.assertRaises(CivisGitError, lambda: CivisGit().clone_repository())
def stage_new_notebook(notebook_file_path):
    civis_git = CivisGit()
    if civis_git.is_git_enabled():
        repo = civis_git.repo()
        repo.index.add([notebook_file_path])