4
4
import re
5
5
6
6
from pytest import mark , raises
7
- from werkzeug .test import Client
8
- from werkzeug .wrappers import Response
7
+ from webob import Request
9
8
10
9
from sqlalchemy_imageattach .stores .fs import (FileSystemStore ,
11
10
HttpExposedFileSystemStore ,
@@ -54,20 +53,25 @@ def test_http_fs_store(tmpdir):
54
53
actual_data = actual .read ()
55
54
assert expected_data == actual_data
56
55
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'
59
58
)
60
59
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' )
63
65
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 )
68
72
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'
71
75
http_fs_store .delete (image )
72
76
with raises (IOError ):
73
77
http_fs_store .open (image )
@@ -77,33 +81,39 @@ def app(environ, start_response):
77
81
@mark .parametrize ('block_size' , [None , 8192 , 1024 , 1024 * 1024 ])
78
82
def test_static_server (block_size ):
79
83
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' )
83
90
test_dir = os .path .join (os .path .dirname (__file__ ), '..' )
84
91
if block_size :
85
92
app = StaticServerMiddleware (fallback_app , '/static/' , test_dir ,
86
93
block_size )
87
94
else :
88
95
app = StaticServerMiddleware (fallback_app , '/static/' , test_dir )
89
- client = Client (app , Response )
90
96
# 200 OK
91
- response = client .get ('/static/context_test.py' )
97
+ request = Request .blank ('/static/context_test.py' )
98
+ response = request .get_response (app )
92
99
assert response .status_code == 200
93
- assert response .mimetype == 'text/x-python'
100
+ assert response .content_type == 'text/x-python'
94
101
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 ()
96
103
assert response .content_length == f .tell ()
97
104
# 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 )
99
107
assert response .status_code == 200
100
- assert response .mimetype == 'text/x-python'
108
+ assert response .content_type == 'text/x-python'
101
109
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 ()
103
111
assert response .content_length == f .tell ()
104
112
# 404 Not Found
105
- response = client .get ('/static/not-exist' )
113
+ request = Request .blank ('/static/not-exist' )
114
+ response = request .get_response (app )
106
115
assert response .status_code == 404
107
116
# 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/'
0 commit comments