def test_setup_build_when_existing_repo_is_shallow_deletes_repo(self): url = 'url' repo_path = 'repo_path' git = Git(url) git._execute_and_raise_on_failure = Mock() git._repo_directory = repo_path git.execute_command_in_project = Mock(side_effect=[('', 0), ('', 0)]) self.patch('os.path.exists').return_value = True self.patch('os.path.isfile').return_value = True mock_fs = self.patch('app.project_type.git.fs') mock_rmtree = self.patch('shutil.rmtree') git._execute_git_remote_command = Mock() mock_fs.create_dir.call_count = 0 # only measure calls made in _setup_build mock_rmtree.call_count = 0 git._setup_build() self.assertEqual(mock_fs.create_dir.call_count, 1) self.assertEqual(mock_rmtree.call_count, 1)