def test_fetch_project_when_existing_repo_is_shallow_deletes_repo(self): self.os_path_isfile_mock.return_value = True self.os_path_exists_mock.return_value = True mock_fs = self.patch('app.project_type.git.fs') mock_rmtree = self.patch('shutil.rmtree') git = Git('url') git._repo_directory = 'fake/repo_path' git._execute_and_raise_on_failure = MagicMock() git.execute_command_in_project = Mock(return_value=('', 0)) mock_fs.create_dir.call_count = 0 # only measure calls made in _fetch_project mock_rmtree.call_count = 0 git._fetch_project() mock_rmtree.assert_called_once_with('fake/repo_path') mock_fs.create_dir.assert_called_once_with('fake/repo_path', Git.DIRECTORY_PERMISSIONS)
def test_fetch_project_when_existing_repo_is_shallow_deletes_repo(self): self.patch('app.project_type.git.os.path.exists').return_value = True self.patch('app.project_type.git.os.path.isfile').return_value = True self.patch('app.project_type.git._GitRemoteCommandExecutor') mock_fs = self.patch('app.project_type.git.fs') mock_rmtree = self.patch('shutil.rmtree') git = Git('url') git._repo_directory = 'repo_path' git._execute_and_raise_on_failure = Mock() git.execute_command_in_project = Mock(return_value=('', 0)) mock_fs.create_dir.call_count = 0 # only measure calls made in _fetch_project mock_rmtree.call_count = 0 git._fetch_project() self.assertEqual(mock_fs.create_dir.call_count, 1) self.assertEqual(mock_rmtree.call_count, 1)
def test_fetch_project_with_pre_shallow_cloned_repo(self, shallow_clone, should_delete_clone): Configuration['shallow_clones'] = shallow_clone self.os_path_isfile_mock.return_value = True self.os_path_exists_mock.return_value = True mock_fs = self.patch('app.project_type.git.fs') mock_rmtree = self.patch('shutil.rmtree') git = Git('url') git._repo_directory = 'fake/repo_path' git._execute_and_raise_on_failure = MagicMock() git.execute_command_in_project = Mock(return_value=('', 0)) mock_fs.create_dir.call_count = 0 # only measure calls made in _fetch_project mock_rmtree.call_count = 0 git._fetch_project() if should_delete_clone: mock_rmtree.assert_called_once_with('fake/repo_path') else: self.assertFalse(mock_rmtree.called)
def test_fetch_project_with_pre_shallow_cloned_repo( self, shallow_clone, should_delete_clone): Configuration['shallow_clones'] = shallow_clone self.os_path_isfile_mock.return_value = True self.os_path_exists_mock.return_value = True mock_fs = self.patch('app.project_type.git.fs') mock_rmtree = self.patch('shutil.rmtree') git = Git('url') git._repo_directory = 'fake/repo_path' git._execute_and_raise_on_failure = MagicMock() git.execute_command_in_project = Mock(return_value=('', 0)) mock_fs.create_dir.call_count = 0 # only measure calls made in _fetch_project mock_rmtree.call_count = 0 git._fetch_project() if should_delete_clone: mock_rmtree.assert_called_once_with('fake/repo_path') else: self.assertFalse(mock_rmtree.called)