def test_clone_repo_ssh_fail(self):
        type(self.bi).ssh_clone_url = 'ssh_url'
        type(self.bi).https_clone_url = 'https_url'
        ex = Exception('foo')

        mock_repo = Mock(name='mock_repo')
        mock_repo.head.ref.name = 'rname'
        mock_repo.head.ref.commit.hexsha = 'mysha'

        def se_clone(url, path, branch=None):
            if url == 'ssh_url':
                raise ex
            return mock_repo

        with patch('%s.path_for_repo' % pb) as mock_path, \
                patch('%s.Repo.clone_from' % pbm) as mock_clone:
            mock_path.return_value = '/repo/path'
            mock_clone.side_effect = se_clone
            res = self.cls.clone_repo(branch='mybranch')
        assert mock_path.mock_calls == [call()]
        assert mock_clone.mock_calls[0] == call.clone_from(
            'ssh_url', '/repo/path', branch='mybranch'
        )
        assert mock_clone.mock_calls[1] == call.clone_from(
            'https_url', '/repo/path', branch='mybranch'
        )
        assert res == ('/repo/path', '<https_url> rname (mysha)')
    def test_clone_repo_all_fail(self):
        type(self.bi).ssh_clone_url = 'ssh_url'
        type(self.bi).https_clone_url = 'https_url'
        ex1 = Exception('foo')
        ex2 = Exception('bar')

        def se_clone(url, path, branch=None):
            if url == 'ssh_url':
                raise ex1
            raise ex2

        with patch('%s.path_for_repo' % pb) as mock_path, \
                patch('%s.Repo' % pbm) as mock_repo:
            mock_path.return_value = '/repo/path'
            mock_repo.clone_from.side_effect = se_clone
            with pytest.raises(Exception) as excinfo:
                self.cls.clone_repo(branch='mybranch')
        assert mock_path.mock_calls == [call()]
        assert mock_repo.mock_calls == [
            call.clone_from('ssh_url', '/repo/path', branch='mybranch'),
            call.clone_from('https_url', '/repo/path', branch='mybranch'),
        ]
        assert excinfo.value == ex2