Exemplo n.º 1
0
def test_plugin_open_url_json_fail_other(monkeypatch):
    robot.open_url = MagicMock(side_effect=Exception('buh!'))
    plugin = MagicMock()

    with pytest.raises(robot.PluginException) as exc:
        robot.plugin_open_url_json(plugin, 'https://foo/bar')

    assert exc.value.error_message == 'Failed request to Hetzner Robot server endpoint https://foo/bar: buh!'
Exemplo n.º 2
0
def test_plugin_open_url_json_fail_other_2(monkeypatch):
    response = MagicMock()
    response.read = MagicMock(side_effect=AttributeError('read'))
    robot.open_url = MagicMock(side_effect=robot.HTTPError(
        'https://foo/bar', 400, 'Error!', {}, response))
    plugin = MagicMock()

    with pytest.raises(robot.PluginException) as exc:
        robot.plugin_open_url_json(plugin, 'https://foo/bar')

    assert exc.value.error_message == 'Cannot retrieve content from https://foo/bar'
Exemplo n.º 3
0
def test_plugin_open_url_json_fail(monkeypatch, return_value, accept_errors,
                                   result):
    response = MagicMock()
    response.read = MagicMock(return_value=return_value[1].get('body', ''))
    robot.open_url = MagicMock(side_effect=robot.HTTPError(
        'https://foo/bar', 400, 'Error!', {}, response))
    plugin = MagicMock()

    with pytest.raises(robot.PluginException) as exc:
        robot.plugin_open_url_json(plugin,
                                   'https://foo/bar',
                                   accept_errors=accept_errors)

    assert exc.value.error_message == result
Exemplo n.º 4
0
def test_plugin_open_url_json(monkeypatch, return_value, accept_errors,
                              result):
    response = MagicMock()
    response.read = MagicMock(return_value=return_value[1]['body'])
    robot.open_url = MagicMock(return_value=response)
    plugin = MagicMock()

    assert robot.plugin_open_url_json(plugin,
                                      'https://foo/bar',
                                      accept_errors=accept_errors) == result
Exemplo n.º 5
0
 def get_servers(self):
     try:
         return plugin_open_url_json(self, '{0}/server'.format(BASE_URL))[0]
     except PluginException as e:
         raise AnsibleError(e.error_message)