Esempio n. 1
0
def test_load_settings_collaborators_override(mocker):
    cached_arequest = mocker.patch('jenkins_epo.repository.cached_arequest',
                                   CoroutineMock())
    GITHUB = mocker.patch('jenkins_epo.repository.GITHUB')

    from jenkins_epo.repository import Repository

    GITHUB.fetch_file_contents.side_effect = [
        repr(dict(settings=dict(branches=['master'], collaborators=['octo']))),
    ]

    repo = Repository('owner', 'repo1')
    repo.load_settings()

    assert not cached_arequest.mock_calls
Esempio n. 2
0
def test_load_settings_no_yml(mocker):
    GITHUB = mocker.patch('jenkins_epo.repository.GITHUB')
    unpaginate = mocker.patch(
        'jenkins_epo.repository.unpaginate',
        CoroutineMock(return_value=[]),
    )
    from jenkins_epo.repository import ApiNotFoundError, Repository

    GITHUB.fetch_file_contents = CoroutineMock(
        side_effect=ApiNotFoundError('url', Mock(), Mock()))

    repo = Repository('owner', 'repo1')
    yield from repo.load_settings()

    assert GITHUB.fetch_file_contents.mock_calls
    assert unpaginate.mock_calls
Esempio n. 3
0
def test_load_settings_collaborators_denied(mocker):
    GITHUB = mocker.patch('jenkins_epo.repository.GITHUB')
    unpaginate = mocker.patch(
        'jenkins_epo.repository.unpaginate',
        CoroutineMock(),
    )
    from jenkins_epo.repository import (
        Repository,
        ApiNotFoundError,
        UnauthorizedRepository,
    )

    GITHUB.fetch_file_contents = CoroutineMock(
        return_value=repr(dict(settings=dict(branches=['master']))))
    unpaginate.side_effect = ApiNotFoundError('u', Mock(), Mock())

    repo = Repository('owner', 'repo1')
    with pytest.raises(UnauthorizedRepository):
        yield from repo.load_settings()

    assert GITHUB.fetch_file_contents.mock_calls
    assert unpaginate.mock_calls
Esempio n. 4
0
def test_load_settings_already_loaded():
    from jenkins_epo.repository import Repository

    repo = Repository('owner', 'repo1')
    repo.SETTINGS.update({'COLLABORATORS': ['bdfl']})
    repo.load_settings()