Exemplo n.º 1
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            data = f.read()

        with io.open(filename) as f:
            with pytest.raises(AssertionError):
                resp = send_file(request, f)

        with io.open(filename) as f:
            resp = send_file(request, f, mimetype='text/html')
            assert resp.direct_passthrough
            assert resp.mimetype == 'text/html'
            assert resp.data == data

        with io.open(filename) as f:
            resp = send_file(request, f, attachment_filename='foo.html')
            assert resp.direct_passthrough
            assert resp.mimetype == 'text/html'
            assert resp.data == data

        f = StringIO('Test')
        resp = send_file(request, f, attachment_filename='test')
        assert resp.mimetype == 'application/octet-stream'
        assert resp.data == 'Test'

        f = StringIO('Test')
        resp = send_file(request, f, mimetype='text/plain')
        assert resp.mimetype == 'text/plain'
        assert resp.data == 'Test'
Exemplo n.º 2
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            resp = send_file(request,
                             f,
                             mimetype='text/html',
                             as_attachment=True)
            cd_header = resp.headers['Content-Disposition']
            value, options = parse_options_header(cd_header)
            assert value == 'attachment'

        resp = send_file(request, filename, as_attachment=True)
        cd_header = resp.headers['Content-Disposition']
        value, options = parse_options_header(cd_header)
        assert value == 'attachment'
        assert options['filename'] == 'index.html'

        f = StringIO('Test')
        resp = send_file(request,
                         f,
                         attachment_filename='readme.txt',
                         as_attachment=True)
        assert resp.mimetype == 'text/plain'
        cd_header = resp.headers['Content-Disposition']
        value, options = parse_options_header(cd_header)
        assert value == 'attachment'
        assert options['filename'] == 'readme.txt'
Exemplo n.º 3
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            data = f.read()

        with io.open(filename) as f:
            with pytest.raises(AssertionError):
                resp = send_file(request, f)
        
        with io.open(filename) as f:
            resp = send_file(request, f, mimetype='text/html')
            assert resp.direct_passthrough
            assert resp.mimetype == 'text/html'
            assert resp.data == data
        
        with io.open(filename) as f:
            resp = send_file(request, f, attachment_filename='foo.html')
            assert resp.direct_passthrough
            assert resp.mimetype == 'text/html'
            assert resp.data == data
        
        f = StringIO('Test')
        resp = send_file(request, f, attachment_filename='test')
        assert resp.mimetype == 'application/octet-stream'
        assert resp.data == 'Test'

        f = StringIO('Test')
        resp = send_file(request, f, mimetype='text/plain')
        assert resp.mimetype == 'text/plain'
        assert resp.data == 'Test'
Exemplo n.º 4
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')
        resp = send_file(request, filename)
        assert resp.direct_passthrough
        assert resp.mimetype == 'text/html'
        with io.open(filename) as f:
            assert resp.data == f.read()

        filename = path_join(__file__, 'static/favicon.ico')
        resp = send_file(request, filename)
        assert resp.direct_passthrough
        assert resp.mimetype == 'image/x-icon'
Exemplo n.º 5
0
 def index(request):
     filename = path_join(__file__, 'static/index.html')
     resp = send_file(request, filename)
     assert resp.direct_passthrough
     assert resp.mimetype == 'text/html'
     with io.open(filename) as f:
         assert resp.data == f.read()
     
     filename = path_join(__file__, 'static/favicon.ico')
     resp = send_file(request, filename)
     assert resp.direct_passthrough
     assert resp.mimetype == 'image/x-icon'
Exemplo n.º 6
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            resp = send_file(request, f, mimetype='text/html',
                use_x_sendfile=True)
            assert 'x-sendfile' in resp.headers
            assert resp.headers['x-sendfile'] == filename
            assert resp.mimetype == 'text/html'

        f = StringIO('Test')
        resp = send_file(request, f, mimetype='text/plain',
            use_x_sendfile=True)
        assert 'x-sendfile' not in resp.headers
Exemplo n.º 7
0
 def index(request):
     filename = path_join(__file__, 'static/index.html')
     resp = send_file(request, filename, use_x_sendfile=True)
     assert resp.direct_passthrough
     assert 'x-sendfile' in resp.headers
     assert resp.headers['x-sendfile'] == filename
     assert resp.mimetype == 'text/html'
Exemplo n.º 8
0
 def index(request):
     filename = path_join(__file__, 'static/index.html')
     resp = send_file(request, filename, use_x_sendfile=True)
     assert resp.direct_passthrough
     assert 'x-sendfile' in resp.headers
     assert resp.headers['x-sendfile'] == filename
     assert resp.mimetype == 'text/html'
Exemplo n.º 9
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            resp = send_file(request,
                             f,
                             mimetype='text/html',
                             use_x_sendfile=True)
            assert 'x-sendfile' in resp.headers
            assert resp.headers['x-sendfile'] == filename
            assert resp.mimetype == 'text/html'

        f = StringIO('Test')
        resp = send_file(request,
                         f,
                         mimetype='text/plain',
                         use_x_sendfile=True)
        assert 'x-sendfile' not in resp.headers
Exemplo n.º 10
0
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            resp = send_file(request, f, mimetype='text/html',
                as_attachment=True)
            cd_header = resp.headers['Content-Disposition']
            value, options = parse_options_header(cd_header)
            assert value == 'attachment'

        resp = send_file(request, filename, as_attachment=True)
        cd_header = resp.headers['Content-Disposition']
        value, options = parse_options_header(cd_header)
        assert value == 'attachment'
        assert options['filename'] == 'index.html'

        f = StringIO('Test')
        resp = send_file(request, f, attachment_filename='readme.txt',
            as_attachment=True)
        assert resp.mimetype == 'text/plain'
        cd_header = resp.headers['Content-Disposition']
        value, options = parse_options_header(cd_header)
        assert value == 'attachment'
        assert options['filename'] == 'readme.txt'