1
- from cStringIO import StringIO
1
+ from io import BytesIO as StringIO
2
2
import os
3
3
4
4
@@ -12,27 +12,26 @@ def test_no_file_uploaded(self, client):
12
12
assert r .status_code == 400
13
13
14
14
def test_missing_filename (self , client ):
15
- file = StringIO ("the quick brown fox jumps over the lazy dog" )
15
+ file = StringIO (b "the quick brown fox jumps over the lazy dog" )
16
16
r = client .post ("/save" , data = dict (file = (file , "" )))
17
17
assert r .status_code == 400
18
18
19
19
def test_save_prefix (self , client ):
20
20
prefix = "hello"
21
- file = StringIO ("the quick brown fox jumps over the lazy dog" )
22
- url = client .post (
23
- "/save" , data = dict (file = (file , "hello.txt" ), prefix = prefix )).data
24
- assert url [:len (prefix )] == prefix
21
+ file = StringIO (b"the quick brown fox jumps over the lazy dog" )
22
+ url = client .post ("/save" , data = dict (file = (file , "hello.txt" ), prefix = prefix )).data
23
+ assert url [:len (prefix )].decode () == prefix
25
24
26
25
def test_save_suffix (self , client ):
27
26
suffix = "hello.txt"
28
- file = StringIO ("the quick brown fox jumps over the lazy dog" )
29
- url = client .post (
30
- "/save" , data = dict (file = (file , "hello.txt" ), suffix = suffix )).data
31
- assert url [- len (suffix ):] == suffix
27
+ file = StringIO (b"the quick brown fox jumps over the lazy dog" )
28
+ url = client .post ("/save" , data = dict (file = (file , "hello.txt" ), suffix = suffix )).data
29
+ assert url [- len (suffix ):].decode () == suffix
32
30
33
31
def test_retrieved (self , app , client ):
34
- data = "the quick brown fox jumps over the lazy dog"
32
+ data = b "the quick brown fox jumps over the lazy dog"
35
33
file = StringIO (data )
36
34
url = client .post ("/save" , data = dict (file = (file , "hello.txt" ))).data
37
- with open (os .path .join (app .config ["UPLOAD_FOLDER" ], url ), "r" ) as f :
38
- assert f .read () == data
35
+ path = os .path .join (app .config ["UPLOAD_FOLDER" ], url .decode ())
36
+ with open (path , "r" ) as f :
37
+ assert f .read () == data .decode ()
0 commit comments