def test_build_requirement_from_name_second_server(galaxy_server, monkeypatch):
    mock_get_versions = MagicMock()
    mock_get_versions.return_value = ['1.0.1', '1.0.2', '1.0.3']
    monkeypatch.setattr(galaxy_server, 'get_collection_versions',
                        mock_get_versions)

    broken_server = copy.copy(galaxy_server)
    broken_server.api_server = 'https://broken.com/'
    mock_404 = MagicMock()
    mock_404.side_effect = api.GalaxyError(
        urllib_error.HTTPError('https://galaxy.server.com', 404, 'msg', {},
                               StringIO()), "custom msg")
    monkeypatch.setattr(broken_server, 'get_collection_versions', mock_404)

    actual = collection.CollectionRequirement.from_name(
        'namespace.collection', [broken_server, galaxy_server], '>1.0.1',
        False, True)

    assert actual.namespace == u'namespace'
    assert actual.name == u'collection'
    assert actual.b_path is None
    # assert actual.api == galaxy_server
    assert actual.skip is False
    assert actual.versions == set([u'1.0.2', u'1.0.3'])
    assert actual.latest_version == u'1.0.3'
    assert actual.dependencies == {}

    assert mock_404.call_count == 1
    assert mock_404.mock_calls[0][1] == ('namespace', 'collection')

    assert mock_get_versions.call_count == 1
    assert mock_get_versions.mock_calls[0][1] == ('namespace', 'collection')
Esempio n. 2
0
def test_initialise_unknown(monkeypatch):
    mock_open = MagicMock()
    mock_open.side_effect = [
        urllib_error.HTTPError('https://galaxy.assible.com/api/', 500, 'msg',
                               {}, StringIO(u'{"msg":"raw error"}')),
        urllib_error.HTTPError('https://galaxy.assible.com/api/api/', 500,
                               'msg', {}, StringIO(u'{"msg":"raw error"}')),
    ]
    monkeypatch.setattr(galaxy_api, 'open_url', mock_open)

    api = GalaxyAPI(None,
                    "test",
                    "https://galaxy.assible.com/api/",
                    token=GalaxyToken(token='my_token'))

    expected = "Error when finding available api versions from test (%s) (HTTP Code: 500, Message: msg)" \
        % api.api_server
    with pytest.raises(AssibleError, match=re.escape(expected)):
        api.authenticate("github_token")
def test_build_requirement_from_name_401_unauthorized(galaxy_server,
                                                      monkeypatch):
    mock_open = MagicMock()
    mock_open.side_effect = api.GalaxyError(
        urllib_error.HTTPError('https://galaxy.server.com', 401, 'msg', {},
                               StringIO()), "error")

    monkeypatch.setattr(galaxy_server, 'get_collection_versions', mock_open)

    expected = "error (HTTP Code: 401, Message: msg)"
    with pytest.raises(api.GalaxyError, match=re.escape(expected)):
        collection.CollectionRequirement.from_name(
            'namespace.collection', [galaxy_server, galaxy_server], '*', False)
def test_build_requirement_from_name_missing(galaxy_server, monkeypatch):
    mock_open = MagicMock()
    mock_open.side_effect = api.GalaxyError(
        urllib_error.HTTPError('https://galaxy.server.com', 404, 'msg', {},
                               StringIO()), "")

    monkeypatch.setattr(galaxy_server, 'get_collection_versions', mock_open)

    expected = "Failed to find collection namespace.collection:*"
    with pytest.raises(AssibleError, match=expected):
        collection.CollectionRequirement.from_name(
            'namespace.collection', [galaxy_server, galaxy_server], '*', False,
            True)
Esempio n. 5
0
def test_publish_failure(api_version, collection_url, response, expected,
                         collection_artifact, monkeypatch):
    api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version)

    expected_url = '%s/api/%s/%s' % (api.api_server, api_version,
                                     collection_url)

    mock_open = MagicMock()
    mock_open.side_effect = urllib_error.HTTPError(
        expected_url, 500, 'msg', {}, StringIO(to_text(json.dumps(response))))
    monkeypatch.setattr(galaxy_api, 'open_url', mock_open)

    with pytest.raises(GalaxyError,
                       match=re.escape(to_native(expected % api.api_server))):
        api.publish_collection(collection_artifact)