15
15
class ReadMultipartTestCase (unittest .TestCase ):
16
16
17
17
def test_flat (self ):
18
- text = '''\
18
+ text = b '''\
19
19
Content-Type: multipart/mixed; boundary="===============1946781859=="
20
20
21
21
--===============1946781859==
@@ -47,18 +47,18 @@ def test_flat(self):
47
47
if num == 0 :
48
48
self .assertEqual ('bar' , headers ['content-id' ])
49
49
self .assertEqual ('"1-4229094393"' , headers ['etag' ])
50
- self .assertEqual ('{\n "_id": "bar",\n '
51
- '"_rev": "1-4229094393"\n }' , payload )
50
+ self .assertEqual (b '{\n "_id": "bar",\n '
51
+ b '"_rev": "1-4229094393"\n }' , payload )
52
52
elif num == 1 :
53
53
self .assertEqual ('foo' , headers ['content-id' ])
54
54
self .assertEqual ('"1-2182689334"' , headers ['etag' ])
55
- self .assertEqual ('{\n "_id": "foo",\n "_rev": "1-2182689334",'
56
- '\n "something": "cool"\n }' , payload )
55
+ self .assertEqual (b '{\n "_id": "foo",\n "_rev": "1-2182689334",'
56
+ b '\n "something": "cool"\n }' , payload )
57
57
num += 1
58
58
self .assertEqual (num , 2 )
59
59
60
60
def test_nested (self ):
61
- text = '''\
61
+ text = b '''\
62
62
Content-Type: multipart/mixed; boundary="===============1946781859=="
63
63
64
64
--===============1946781859==
@@ -111,8 +111,8 @@ def test_nested(self):
111
111
self .assertEqual ('application/json' , headers ['content-type' ])
112
112
self .assertEqual ('bar' , headers ['content-id' ])
113
113
self .assertEqual ('"1-4229094393"' , headers ['etag' ])
114
- self .assertEqual ('{\n "_id": "bar", \n '
115
- '"_rev": "1-4229094393"\n }' , payload )
114
+ self .assertEqual (b '{\n "_id": "bar", \n '
115
+ b '"_rev": "1-4229094393"\n }' , payload )
116
116
elif num == 1 :
117
117
self .assertEqual (is_multipart , True )
118
118
self .assertEqual ('foo' , headers ['content-id' ])
@@ -124,14 +124,14 @@ def test_nested(self):
124
124
if partnum == 0 :
125
125
self .assertEqual ('application/json' ,
126
126
headers ['content-type' ])
127
- self .assertEqual ('{\n "_id": "foo", \n "_rev": '
128
- '"1-919589747", \n "something": '
129
- '"cool"\n }' , payload )
127
+ self .assertEqual (b '{\n "_id": "foo", \n "_rev": '
128
+ b '"1-919589747", \n "something": '
129
+ b '"cool"\n }' , payload )
130
130
elif partnum == 1 :
131
131
self .assertEqual ('text/plain' , headers ['content-type' ])
132
132
self .assertEqual ('mail.txt' , headers ['content-id' ])
133
- self .assertEqual ('Hello, friends.\n How are you doing?'
134
- '\n \n Regards, Chris' , payload )
133
+ self .assertEqual (b 'Hello, friends.\n How are you doing?'
134
+ b '\n \n Regards, Chris' , payload )
135
135
136
136
partnum += 1
137
137
@@ -140,16 +140,16 @@ def test_nested(self):
140
140
self .assertEqual ('application/json' , headers ['content-type' ])
141
141
self .assertEqual ('baz' , headers ['content-id' ])
142
142
self .assertEqual ('"1-3482142493"' , headers ['etag' ])
143
- self .assertEqual ('{\n "_id": "baz", \n '
144
- '"_rev": "1-3482142493"\n }' , payload )
143
+ self .assertEqual (b '{\n "_id": "baz", \n '
144
+ b '"_rev": "1-3482142493"\n }' , payload )
145
145
146
146
147
147
num += 1
148
148
self .assertEqual (num , 3 )
149
149
150
150
def test_unicode_headers (self ):
151
151
# http://code.google.com/p/couchdb-python/issues/detail?id=179
152
- dump = '''Content-Type: multipart/mixed; boundary="==123456789=="
152
+ dump = u '''Content-Type: multipart/mixed; boundary="==123456789=="
153
153
154
154
--==123456789==
155
155
Content-ID: =?utf-8?b?5paH5qGj?=
@@ -159,7 +159,7 @@ def test_unicode_headers(self):
159
159
160
160
{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
161
161
'''
162
- parts = multipart .read_multipart (StringIO (dump ))
162
+ parts = multipart .read_multipart (StringIO (dump . encode ( 'utf-8' ) ))
163
163
for headers , is_multipart , payload in parts :
164
164
self .assertEqual (headers ['content-id' ], u'文档' )
165
165
break
@@ -172,7 +172,7 @@ def test_unicode_content(self):
172
172
envelope = multipart .write_multipart (buf , boundary = '==123456789==' )
173
173
envelope .add ('text/plain' , u'Iñtërnâtiônàlizætiøn' )
174
174
envelope .close ()
175
- self .assertEqual ('''Content-Type: multipart/mixed; boundary="==123456789=="
175
+ self .assertEqual (u '''Content-Type: multipart/mixed; boundary="==123456789=="
176
176
177
177
--==123456789==
178
178
Content-Length: 27
@@ -181,7 +181,7 @@ def test_unicode_content(self):
181
181
182
182
Iñtërnâtiônàlizætiøn
183
183
--==123456789==--
184
- ''' , buf .getvalue ().replace ('\r \n ' , '\n ' ))
184
+ ''' . encode ( 'utf-8' ) , buf .getvalue ().replace (b '\r \n ' , b '\n ' ))
185
185
186
186
def test_unicode_content_ascii (self ):
187
187
buf = StringIO ()
@@ -197,7 +197,7 @@ def test_unicode_headers(self):
197
197
'{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09",'
198
198
' "_id": "文档"}' ,
199
199
headers = {'Content-ID' : u"文档" })
200
- self .assertEqual ('''Content-Type: multipart/mixed; boundary="==123456789=="
200
+ self .assertEqual (u '''Content-Type: multipart/mixed; boundary="==123456789=="
201
201
202
202
--==123456789==
203
203
Content-ID: =?utf-8?b?5paH5qGj?=
@@ -206,7 +206,7 @@ def test_unicode_headers(self):
206
206
Content-Type: application/json;charset=utf-8
207
207
208
208
{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
209
- ''' , buf .getvalue ().replace ('\r \n ' , '\n ' ))
209
+ ''' . encode ( 'utf-8' ) , buf .getvalue ().replace (b '\r \n ' , b '\n ' ))
210
210
211
211
212
212
def suite ():
0 commit comments