def test_using_gzip_if_header_present_and_file_available(loop):
    request = make_mocked_request(
        'GET', URL('http://python.org/logo.png'), headers={
            hdrs.ACCEPT_ENCODING: 'gzip'
        }
    )

    gz_filepath = mock.Mock()
    gz_filepath.open = mock.mock_open()
    gz_filepath.is_file.return_value = True
    gz_filepath.stat.return_value = mock.MagicMock()
    gz_filepath.stat.st_size = 1024

    filepath = mock.Mock()
    filepath.name = 'logo.png'
    filepath.open = mock.mock_open()
    filepath.with_name.return_value = gz_filepath

    file_sender = FileSender()
    file_sender._sendfile = make_mocked_coro(None)

    loop.run_until_complete(file_sender.send(request, filepath))

    assert not filepath.open.called
    assert gz_filepath.open.called
예제 #2
0
def test_gzip_if_header_not_present_and_file_not_available(loop):
    request = make_mocked_request(
        'GET', 'http://python.org/logo.png', headers={
        }
    )

    gz_filepath = mock.Mock()
    gz_filepath.open = mock.mock_open()
    gz_filepath.is_file.return_value = False

    filepath = mock.Mock()
    filepath.name = 'logo.png'
    filepath.open = mock.mock_open()
    filepath.with_name.return_value = gz_filepath
    filepath.stat.return_value = mock.MagicMock()
    filepath.stat.st_size = 1024

    file_sender = FileSender()
    file_sender._sendfile = make_mocked_coro(None)

    loop.run_until_complete(file_sender.send(request, filepath))

    assert filepath.open.called
    assert not gz_filepath.open.called
예제 #3
0
 def f(*args, **kwargs):
     route = add_static(*args, **kwargs)
     file_sender = FileSender()
     file_sender._sendfile = file_sender._sendfile_fallback
     return route
예제 #4
0
 def maker(*args, **kwargs):
     ret = FileSender(*args, **kwargs)
     if request.param == 'fallback':
         ret._sendfile = ret._sendfile_fallback
     return ret
예제 #5
0
 def maker(*args, **kwargs):
     ret = FileSender(*args, **kwargs)
     if request.param == 'fallback':
         ret._sendfile = ret._sendfile_fallback
     return ret
 def f(*args, **kwargs):
     route = add_static(*args, **kwargs)
     file_sender = FileSender()
     file_sender._sendfile = file_sender._sendfile_fallback
     return route