Skip to content

Commit 7cd3ca5

Browse files
committed
Use WebOb instead of patched Werkzeug for py32
1 parent e9ba274 commit 7cd3ca5

File tree

4 files changed

+38
-52
lines changed

4 files changed

+38
-52
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ before_install:
1919
- sudo apt-get update -qq
2020
- sudo apt-get install -qq s3cmd rubygems
2121
install:
22-
- pip install pytest Werkzeug pytest-capturelog pytest-cov coveralls $DRIVER
22+
- pip install pytest WebOb pytest-capturelog pytest-cov coveralls $DRIVER
2323
- pip install -e .
2424
- gem install --user-install --no-ri --no-rdoc fakes3
2525
before_script:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def run_tests(self):
5757
license='MIT License',
5858
packages=find_packages(exclude=['tests']),
5959
install_requires=install_requires,
60-
tests_require=['pytest >= 2.3.0', 'Werkzeug >= 0.8'],
60+
tests_require=['pytest >= 2.3.0', 'WebOb'],
6161
dependency_links=dependency_links,
6262
classifiers=[
6363
'Development Status :: 3 - Alpha',

tests/stores/fs_test.py

+35-25
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import re
55

66
from pytest import mark, raises
7-
from werkzeug.test import Client
8-
from werkzeug.wrappers import Response
7+
from webob import Request
98

109
from sqlalchemy_imageattach.stores.fs import (FileSystemStore,
1110
HttpExposedFileSystemStore,
@@ -54,20 +53,25 @@ def test_http_fs_store(tmpdir):
5453
actual_data = actual.read()
5554
assert expected_data == actual_data
5655
expected_urls = (
57-
'http://localhost/__images__/testing/234/1/1234.405x640.jpe',
58-
'http://localhost/__images__/testing/234/1/1234.405x640.jpg'
56+
'http://localhost:80/__images__/testing/234/1/1234.405x640.jpe',
57+
'http://localhost:80/__images__/testing/234/1/1234.405x640.jpg'
5958
)
6059
def app(environ, start_response):
61-
start_response('200 OK', [('Content-Type', 'text/plain')])
62-
yield http_fs_store.locate(image)
60+
start_response(
61+
'200 OK',
62+
[('Content-Type', 'text/plain; charset=utf-8')]
63+
)
64+
yield http_fs_store.locate(image).encode('utf-8')
6365
app = http_fs_store.wsgi_middleware(app)
64-
client = Client(app, Response)
65-
actual_url = client.get('/').data
66-
assert remove_query(actual_url.decode()) in expected_urls
67-
response = client.get('/__images__/testing/234/1/1234.405x640.jpe')
66+
request = Request.blank('/')
67+
response = request.get_response(app)
68+
actual_url = response.text
69+
assert remove_query(actual_url) in expected_urls
70+
request = Request.blank('/__images__/testing/234/1/1234.405x640.jpe')
71+
response = request.get_response(app)
6872
assert response.status_code == 200
69-
assert response.data == expected_data
70-
assert response.mimetype == 'image/jpeg'
73+
assert response.body == expected_data
74+
assert response.content_type == 'image/jpeg'
7175
http_fs_store.delete(image)
7276
with raises(IOError):
7377
http_fs_store.open(image)
@@ -77,33 +81,39 @@ def app(environ, start_response):
7781
@mark.parametrize('block_size', [None, 8192, 1024, 1024 * 1024])
7882
def test_static_server(block_size):
7983
def fallback_app(environ, start_response):
80-
start_response('200 OK', [('Content-Type', 'text/plain')])
81-
yield 'fallback: '
82-
yield environ['PATH_INFO']
84+
start_response(
85+
'200 OK',
86+
[('Content-Type', 'text/plain; charset=utf-8')]
87+
)
88+
yield b'fallback: '
89+
yield environ['PATH_INFO'].encode('utf-8')
8390
test_dir = os.path.join(os.path.dirname(__file__), '..')
8491
if block_size:
8592
app = StaticServerMiddleware(fallback_app, '/static/', test_dir,
8693
block_size)
8794
else:
8895
app = StaticServerMiddleware(fallback_app, '/static/', test_dir)
89-
client = Client(app, Response)
9096
# 200 OK
91-
response = client.get('/static/context_test.py')
97+
request = Request.blank('/static/context_test.py')
98+
response = request.get_response(app)
9299
assert response.status_code == 200
93-
assert response.mimetype == 'text/x-python'
100+
assert response.content_type == 'text/x-python'
94101
with open(os.path.join(test_dir, 'context_test.py'), 'rb') as f:
95-
assert response.data == f.read()
102+
assert response.body == f.read()
96103
assert response.content_length == f.tell()
97104
# 200 OK: subdirectory
98-
response = client.get('/static/stores/fs_test.py')
105+
request = Request.blank('/static/stores/fs_test.py')
106+
response = request.get_response(app)
99107
assert response.status_code == 200
100-
assert response.mimetype == 'text/x-python'
108+
assert response.content_type == 'text/x-python'
101109
with open(os.path.join(test_dir, 'stores', 'fs_test.py'), 'rb') as f:
102-
assert response.data == f.read()
110+
assert response.body == f.read()
103111
assert response.content_length == f.tell()
104112
# 404 Not Found
105-
response = client.get('/static/not-exist')
113+
request = Request.blank('/static/not-exist')
114+
response = request.get_response(app)
106115
assert response.status_code == 404
107116
# fallback app
108-
response = client.get('/static-not/')
109-
assert response.data == b'fallback: /static-not/'
117+
request = Request.blank('/static-not/')
118+
response = request.get_response(app)
119+
assert response.text == 'fallback: /static-not/'

tox.ini

+1-25
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,5 @@ envlist = py26, py27, py32, py33, pypy
44
[testenv]
55
deps =
66
pytest>=2.3.0
7+
WebOb
78
commands = py.test {posargs:--durations=5}
8-
9-
[py2x]
10-
deps =
11-
{[testenv]deps}
12-
Werkzeug>=0.8
13-
14-
[py3x]
15-
deps =
16-
{[testenv]deps}
17-
https://github.com/puzzlet/werkzeug/archive/py3-dev.tar.gz#egg=Werkzeug
18-
19-
[testenv:py26]
20-
deps = {[py2x]deps}
21-
22-
[testenv:py27]
23-
deps = {[py2x]deps}
24-
25-
[testenv:pypy]
26-
deps = {[py2x]deps}
27-
28-
[testenv:py32]
29-
deps = {[py3x]deps}
30-
31-
[testenv:py33]
32-
deps = {[py3x]deps}

0 commit comments

Comments
 (0)