def test_body_get_is_none(): res = Response() res._app_iter = None with pytest.raises(TypeError): Response(app_iter=iter(['a']), body="somebody") with pytest.raises(AttributeError): res.__getattribute__('body')
def test_has_body(): empty = Response() assert not empty.has_body with_list = Response(app_iter=['1']) assert with_list.has_body with_empty_list = Response(app_iter=[b'']) assert not with_empty_list.has_body with_body = Response(body='Seomthing') assert with_body.has_body with_none_app_iter = Response(app_iter=None) assert not with_none_app_iter.has_body with_none_body = Response(body=None) assert not with_none_body.has_body # key feature: has_body should not read app_iter app_iter = iter(['1', '2']) not_iterating = Response(app_iter=app_iter) assert not_iterating.has_body assert next(app_iter) == '1' # messed with private attribute but method should nonetheless not # return True messing_with_privates = Response() messing_with_privates._app_iter = None assert not messing_with_privates.has_body
def test_body_get_body_is_None_len_app_iter_is_zero(): res = Response() res._app_iter = io.BytesIO() res._body = None result = res.body assert result == b''
def test_body_get_is_none(): res = Response() res._app_iter = None assert_raises(TypeError, Response, app_iter=iter(['a']), body="somebody") assert_raises(AttributeError, res.__getattribute__, 'body')
def test_body_get_is_none(): res = Response() res._app_iter = None assert_raises(TypeError, Response, app_iter=iter(['a']), body="somebody") assert_raises(AttributeError, res.__getattribute__, 'body')
def test_body_get_body_is_None_len_app_iter_is_zero(): res = Response() res._app_iter = io.BytesIO() res._body = None result = res.body eq_(result, b"")