def test_method_selection(self, mocker, method): """Test method selection propagation.""" utils.retryable(method, 'http://some.thing') getattr(self.session, method).assert_called_once_with('http://some.thing', verify=mocker.ANY)
def test_ssl_validate(self, monkeypatch, ssl_verify): """Should respect SSL_VERIFY settings.""" monkeypatch.setattr(utils, 'SSL_VERIFY', ssl_verify) utils.retryable('get', 'http://some.thing') self.session.get.assert_called_once_with('http://some.thing', verify=ssl_verify)
def test_retry(self): """Should retry when first request fails.""" self.response.raise_for_status.side_effect = \ [requests.HTTPError(), None] utils.retryable('get', 'http://some.thing') assert self.session.get.call_count == 2
def test_retry_failed(self): """Should retry as many as MAX_RETRIES.""" self.response.raise_for_status.side_effect = requests.HTTPError() with pytest.raises(utils.RetryFailedError): utils.retryable('get', 'http://some.thing') assert self.session.get.call_count == utils.MAX_RETRIES assert utils.MAX_RETRIES > 1
def test_response(self, mocker): """Test a response can be received.""" resp = utils.retryable('get', 'http://some.thing') self.session.get.assert_called_once_with('http://some.thing', verify=mocker.ANY) assert resp == self.response