def test_return_body_if_valid(self): response_mock = ResponseMock(body='body', code=200) callback_mock = mock.Mock() ctx = Context(None, None, None) loader.return_contents(response_mock, 'some-url', callback_mock, ctx) result = callback_mock.call_args[0][0] expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_equal('body')
def test_return_body_if_valid(self): response_mock = ResponseMock(body='body', code=200) callback_mock = mock.Mock() ctx = Context(None, None, None) loader.return_contents(response_mock, 'some-url', callback_mock, ctx) result = callback_mock.call_args[0][0] expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_equal('body')
def test_return_none_on_error(self): response_mock = ResponseMock(error='Error', code=599) callback_mock = mock.Mock() ctx = Context(None, None, None) loader.return_contents(response_mock, 'some-url', callback_mock, ctx) result = callback_mock.call_args[0][0] expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_be_null() expect(result.successful).to_be_false()
def test_return_none_on_error(self): response_mock = ResponseMock(error='Error', code=599) callback_mock = mock.Mock() ctx = Context(None, None, None) loader.return_contents(response_mock, 'some-url', callback_mock, ctx) result = callback_mock.call_args[0][0] expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_be_null() expect(result.successful).to_be_false()
def test_return_upstream_error_on_body_empty(self): response_mock = ResponseMock(body='', code=200) callback_mock = mock.Mock() ctx = Context(None, None, None) loader.return_contents(response_mock, 'some-url', callback_mock, ctx) result = callback_mock.call_args[0][0] expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_be_null() expect(result.successful).to_be_false() expect(result.error).to_equal(LoaderResult.ERROR_UPSTREAM)
def test_return_upstream_error_on_body_none(self): response_mock = ResponseMock(body=None, code=200) callback_mock = mock.Mock() ctx = Context(None, None, None) loader.return_contents(response_mock, 'some-url', callback_mock, ctx) result = callback_mock.call_args[0][0] expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_be_null() expect(result.successful).to_be_false() expect(result.error).to_equal(LoaderResult.ERROR_UPSTREAM)
def test_return_none_on_error(self): response_mock = ResponseMock(error="Error", code=599) ctx = Context(None, None, None) result = loader.return_contents(response_mock, "some-url", ctx) expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_be_null() expect(result.successful).to_be_false()
def test_return_upstream_error_on_body_empty(self): response_mock = ResponseMock(body="", code=200) ctx = Context(None, None, None) result = loader.return_contents(response_mock, "some-url", ctx) expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_be_null() expect(result.successful).to_be_false() expect(result.error).to_equal(LoaderResult.ERROR_UPSTREAM)
def _return_contents(response, url, context, req_start=None): result = http_loader.return_contents(response, url, context, req_start) if result.metadata is None: return result cache_control = result.metadata.get("Cache-Control") if cache_control is not None: _update_max_age(context, cache_control) else: context.request.max_age = 0 return result
def return_contents(response, url, callback, context, f): # pragma: no cover excerpt_length = context.config.LOADER_EXCERPT_LENGTH f.seek(0) body = f.read(excerpt_length) f.close() # First kb of the body for MIME detection response._body = body if len(body) == excerpt_length: logger.debug('[HTTPS] return_contents: %s' % f.name) context.wikimedia_original_file = f tornado.ioloop.IOLoop.instance().call_later( context.config.HTTP_LOADER_TEMP_FILE_TIMEOUT, partial(cleanup_temp_file, context.wikimedia_original_file.name) ) else: # If the body is small we can delete the temp file immediately logger.debug('[HTTPS] return_contents: small body') cleanup_temp_file(f.name) return http_loader.return_contents(response, url, callback, context)
def topic(self, callback): mock = ResponseMock(body='body', code=200) ctx = Context(None, None, None) return loader.return_contents(mock, 'some-url', callback, ctx)
def topic(self, callback): mock = ResponseMock(body='body') return loader.return_contents(mock, 'some-url', callback)
def topic(self, callback): mock = ResponseMock(error='Error') return loader.return_contents(mock, 'some-url', callback)
def topic(self, callback): return loader.return_contents(ResponseMock(body='body'), callback)
def topic(self, callback): mock = ResponseMock(body='body') return loader.return_contents(mock, 'some-url', callback)
def topic(self, callback): mock = ResponseMock(error='Error') return loader.return_contents(mock, 'some-url', callback)
def topic(self, callback): return loader.return_contents(ResponseMock(error='Error'), callback)
def topic(self, callback): return loader.return_contents(ResponseMock(body='body'), callback)
def topic(self, callback): return loader.return_contents(ResponseMock(content_type='application/json'), callback)
def topic(self, callback): return loader.return_contents(ResponseMock(error='Error'), callback)
def topic(self, callback): mock = ResponseMock(error='Error', code=599) ctx = Context(None, None, None) return loader.return_contents(mock, 'some-url', callback, ctx)
def topic(self, callback): mock = ResponseMock(error='Error', code=599) ctx = Context(None, None, None) return loader.return_contents(mock, 'some-url', callback, ctx)
def return_contents(response, url, callback, context): return http_loader.return_contents(response, url, callback, context)
def topic(self, callback): mock = ResponseMock(body='body', code=200) ctx = Context(None, None, None) return loader.return_contents(mock, 'some-url', callback, ctx)
def test_return_body_if_valid(self): response_mock = ResponseMock(body="body", code=200) ctx = Context(None, None, None) result = loader.return_contents(response_mock, "some-url", ctx) expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).to_equal("body")
def topic(self, callback): return loader.return_contents( ResponseMock(content_type='application/json'), callback)
def return_contents(response, url, callback, context): return http_loader.return_contents(response, url, callback, context)
def return_contents(response, url, callback, context): # pragma: no cover return http_loader.return_contents(response, url, callback, context)