Ejemplo n.º 1
0
def test_response_file_body_tell_text():
    from webob.response import ResponseBodyFile

    rbo = ResponseBodyFile(Response())
    assert rbo.tell() == 0
    rbo.write("123456789")
    assert rbo.tell() == 9
Ejemplo n.º 2
0
def test_response_file_body_writelines():
    from webob.response import ResponseBodyFile
    res = Response(app_iter=[b'foo'])
    rbo = ResponseBodyFile(res)
    rbo.writelines(['bar', 'baz'])
    assert res.app_iter == [b'foo', b'bar', b'baz']
    rbo.flush() # noop
    assert res.app_iter, [b'foo', b'bar', b'baz']
Ejemplo n.º 3
0
def test_body_file_write_no_charset():
    from webob.response import ResponseBodyFile

    class FakeReponse:
        charset = None

    rbo = ResponseBodyFile(FakeReponse())
    assert_raises(TypeError, rbo.write, u'foo')
Ejemplo n.º 4
0
def test_response_file_body_tell():
    import zipfile
    from webob.response import ResponseBodyFile
    rbo = ResponseBodyFile(Response())
    eq_(rbo.tell(), 0)
    writer = zipfile.ZipFile(rbo, 'w')
    writer.writestr('zinfo_or_arcname', b'foo')
    writer.close()
    eq_(rbo.tell(), 133)
Ejemplo n.º 5
0
def test_response_file_body_writelines():
    from webob.response import ResponseBodyFile

    res = Response(app_iter=[b"foo"])
    rbo = ResponseBodyFile(res)
    rbo.writelines(["bar", "baz"])
    assert res.app_iter == [b"foo", b"bar", b"baz"]
    rbo.flush()  # noop
    assert res.app_iter, [b"foo", b"bar", b"baz"]
Ejemplo n.º 6
0
def test_response_file_body_write_non_str():
    from webob.response import ResponseBodyFile

    class FakeResponse:
        pass

    res = FakeResponse()
    rbo = ResponseBodyFile(res)
    assert_raises(TypeError, rbo.write, object())
Ejemplo n.º 7
0
def test_response_file_body_tell():
    import zipfile
    from webob.response import ResponseBodyFile

    rbo = ResponseBodyFile(Response())
    assert rbo.tell() == 0
    writer = zipfile.ZipFile(rbo, "w")
    writer.writestr("zinfo_or_arcname", b"foo")
    writer.close()
    assert rbo.tell() == 133
Ejemplo n.º 8
0
def test_response_file_body_write_empty_body():
    from webob.response import ResponseBodyFile

    class FakeResponse:
        body = ''

    res = FakeResponse()
    res._app_iter = res.app_iter = None
    rbo = ResponseBodyFile(res)
    rbo.write('baz')
    eq_(res.app_iter, ['baz'])
Ejemplo n.º 9
0
def test_response_file_body_writelines():
    from webob.response import ResponseBodyFile

    class FakeResponse:
        pass

    res = FakeResponse()
    res._app_iter = res.app_iter = ['foo']
    rbo = ResponseBodyFile(res)
    rbo.writelines(['bar', 'baz'])
    eq_(res.app_iter, ['foo', 'bar', 'baz'])
Ejemplo n.º 10
0
def test_body_file_write_unicode_encodes():
    from webob.response import ResponseBodyFile

    class FakeReponse:
        charset = 'utf-8'
        _app_iter = app_iter = []

    s = unicode('La Pe\xc3\xb1a', 'utf-8')
    res = FakeReponse()
    rbo = ResponseBodyFile(res)
    rbo.write(s)
    eq_(res.app_iter, ['La Pe\xc3\xb1a'])
Ejemplo n.º 11
0
def test_response_file_body_repr():
    from webob.response import ResponseBodyFile
    rbo = ResponseBodyFile('yo')
    eq_(repr(rbo), "<body_file for 'yo'>")
Ejemplo n.º 12
0
def test_response_file_body_close_not_implemented():
    from webob.response import ResponseBodyFile
    rbo = ResponseBodyFile(None)
    assert_raises(NotImplementedError, rbo.close)
Ejemplo n.º 13
0
def test_response_file_body_flush_is_no_op():
    from webob.response import ResponseBodyFile
    rbo = ResponseBodyFile(None)
    rbo.flush()