Exemplo n.º 1
0
def test_restful_fail(monkeypatch):
    class MockResponse:
        def p(self):
            raise HTTPError("foo")

        def __init__(self):
            self.status_code = 500
            self.raise_for_status = self.p

    def mock_response(uri, headers, data, params, proxies, timeout):
        return MockResponse()

    commands = CommandSequence(
        CommandSequenceBase("test-cleanup-list",
                            [{CALL_PROPERTY: {"uri": 'http://foo', "method": 'PUT', "data": 'data'}}]))
    assert commands is not None
    with monkeypatch.context() as m:
        m.setattr("requests.put", mock_response)
        commands.run()
        assert commands.check([]) == 1
Exemplo n.º 2
0
def test_restful_fail(monkeypatch):
    class MockResponse:
        def p(self):
            raise HTTPError("foo")

        def __init__(self):
            self.status_code = 500
            self.raise_for_status = self.p

    def mock_response(verb, uri, headers, data):
        return MockResponse()

    commands = CommandSequence(
        CommandSequenceBase("test-cleanup-list",
                            [{'command': ['http://foo', 'PUT', 'data']}]))
    assert commands is not None
    with monkeypatch.context() as m:
        m.setattr("opengrok_tools.utils.restful.do_api_call",
                  mock_response)
        commands.run()
        assert commands.check([]) == 1