44import re
55
66from pytest import mark , raises
7- from werkzeug .test import Client
8- from werkzeug .wrappers import Response
7+ from webob import Request
98
109from 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 ])
7882def 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/'
0 commit comments