示例#1
0
def test_http_fs_store(tmpdir, **kwargs):
    http_fs_store = HttpExposedFileSystemStore(tmpdir.strpath, **kwargs)
    image = TestingImage(thing_id=1234, width=405, height=640,
                         mimetype='image/jpeg', original=True,
                         created_at=utcnow())
    image_path = os.path.join(sample_images_dir, 'iu.jpg')
    with open(image_path, 'rb') as image_file:
        expected_data = image_file.read()
        image_file.seek(0)
        http_fs_store.store(image, image_file)
    with http_fs_store.open(image) as actual:
        actual_data = actual.read()
    assert expected_data == actual_data
    expected_urls = (
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpe',
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpg'
    )
    return http_fs_store, image, expected_data, expected_urls
示例#2
0
def test_http_fs_store(tmpdir, **kwargs):
    http_fs_store = HttpExposedFileSystemStore(tmpdir.strpath, **kwargs)
    image = TestingImage(thing_id=1234,
                         width=405,
                         height=640,
                         mimetype='image/jpeg',
                         original=True,
                         created_at=utcnow())
    image_path = os.path.join(sample_images_dir, 'iu.jpg')
    with open(image_path, 'rb') as image_file:
        expected_data = image_file.read()
        image_file.seek(0)
        http_fs_store.store(image, image_file)
    with http_fs_store.open(image) as actual:
        actual_data = actual.read()
    assert expected_data == actual_data
    expected_urls = (
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpe',
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpg')
    return http_fs_store, image, expected_data, expected_urls
示例#3
0
def test_http_fs_store(tmpdir):
    http_fs_store = HttpExposedFileSystemStore(tmpdir.strpath)
    image = TestingImage(thing_id=1234,
                         width=405,
                         height=640,
                         mimetype='image/jpeg',
                         original=True,
                         created_at=utcnow())
    image_path = os.path.join(sample_images_dir, 'iu.jpg')
    with open(image_path, 'rb') as image_file:
        expected_data = image_file.read()
        image_file.seek(0)
        http_fs_store.store(image, image_file)
    with http_fs_store.open(image) as actual:
        actual_data = actual.read()
    assert expected_data == actual_data
    expected_urls = (
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpe',
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpg')

    def app(environ, start_response):
        start_response('200 OK',
                       [('Content-Type', 'text/plain; charset=utf-8')])
        yield http_fs_store.locate(image).encode('utf-8')

    app = http_fs_store.wsgi_middleware(app)
    request = Request.blank('/')
    response = request.get_response(app)
    actual_url = response.text
    assert remove_query(actual_url) in expected_urls
    request = Request.blank('/__images__/testing/234/1/1234.405x640.jpe')
    response = request.get_response(app)
    assert response.status_code == 200
    assert response.body == expected_data
    assert response.content_type == 'image/jpeg'
    http_fs_store.delete(image)
    with raises(IOError):
        http_fs_store.open(image)
    tmpdir.remove()
def test_http_fs_store(tmpdir):
    http_fs_store = HttpExposedFileSystemStore(tmpdir.strpath)
    image = TestingImage(thing_id=1234, width=405, height=640,
                         mimetype='image/jpeg', original=True,
                         created_at=utcnow())
    image_path = os.path.join(sample_images_dir, 'iu.jpg')
    with open(image_path, 'rb') as image_file:
        expected_data = image_file.read()
        image_file.seek(0)
        http_fs_store.store(image, image_file)
    with http_fs_store.open(image) as actual:
        actual_data = actual.read()
    assert expected_data == actual_data
    expected_urls = (
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpe',
        'http://localhost:80/__images__/testing/234/1/1234.405x640.jpg'
    )

    def app(environ, start_response):
        start_response(
            '200 OK',
            [('Content-Type', 'text/plain; charset=utf-8')]
        )
        yield http_fs_store.locate(image).encode('utf-8')
    app = http_fs_store.wsgi_middleware(app)
    request = Request.blank('/')
    response = request.get_response(app)
    actual_url = response.text
    assert remove_query(actual_url) in expected_urls
    request = Request.blank('/__images__/testing/234/1/1234.405x640.jpe')
    response = request.get_response(app)
    assert response.status_code == 200
    assert response.body == expected_data
    assert response.content_type == 'image/jpeg'
    http_fs_store.delete(image)
    with raises(IOError):
        http_fs_store.open(image)
    tmpdir.remove()