Skip to content

Commit 7c64a79

Browse files
committed
Python 3: multipart tests deal with bytes, as well.
1 parent aa9f393 commit 7c64a79

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

couchdb/tests/multipart.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class ReadMultipartTestCase(unittest.TestCase):
1616

1717
def test_flat(self):
18-
text = '''\
18+
text = b'''\
1919
Content-Type: multipart/mixed; boundary="===============1946781859=="
2020
2121
--===============1946781859==
@@ -47,18 +47,18 @@ def test_flat(self):
4747
if num == 0:
4848
self.assertEqual('bar', headers['content-id'])
4949
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)
5252
elif num == 1:
5353
self.assertEqual('foo', headers['content-id'])
5454
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)
5757
num += 1
5858
self.assertEqual(num, 2)
5959

6060
def test_nested(self):
61-
text = '''\
61+
text = b'''\
6262
Content-Type: multipart/mixed; boundary="===============1946781859=="
6363
6464
--===============1946781859==
@@ -111,8 +111,8 @@ def test_nested(self):
111111
self.assertEqual('application/json', headers['content-type'])
112112
self.assertEqual('bar', headers['content-id'])
113113
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)
116116
elif num == 1:
117117
self.assertEqual(is_multipart, True)
118118
self.assertEqual('foo', headers['content-id'])
@@ -124,14 +124,14 @@ def test_nested(self):
124124
if partnum == 0:
125125
self.assertEqual('application/json',
126126
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)
130130
elif partnum == 1:
131131
self.assertEqual('text/plain', headers['content-type'])
132132
self.assertEqual('mail.txt', headers['content-id'])
133-
self.assertEqual('Hello, friends.\nHow are you doing?'
134-
'\n\nRegards, Chris', payload)
133+
self.assertEqual(b'Hello, friends.\nHow are you doing?'
134+
b'\n\nRegards, Chris', payload)
135135

136136
partnum += 1
137137

@@ -140,16 +140,16 @@ def test_nested(self):
140140
self.assertEqual('application/json', headers['content-type'])
141141
self.assertEqual('baz', headers['content-id'])
142142
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)
145145

146146

147147
num += 1
148148
self.assertEqual(num, 3)
149149

150150
def test_unicode_headers(self):
151151
# 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=="
153153
154154
--==123456789==
155155
Content-ID: =?utf-8?b?5paH5qGj?=
@@ -159,7 +159,7 @@ def test_unicode_headers(self):
159159
160160
{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
161161
'''
162-
parts = multipart.read_multipart(StringIO(dump))
162+
parts = multipart.read_multipart(StringIO(dump.encode('utf-8')))
163163
for headers, is_multipart, payload in parts:
164164
self.assertEqual(headers['content-id'], u'文档')
165165
break
@@ -172,7 +172,7 @@ def test_unicode_content(self):
172172
envelope = multipart.write_multipart(buf, boundary='==123456789==')
173173
envelope.add('text/plain', u'Iñtërnâtiônàlizætiøn')
174174
envelope.close()
175-
self.assertEqual('''Content-Type: multipart/mixed; boundary="==123456789=="
175+
self.assertEqual(u'''Content-Type: multipart/mixed; boundary="==123456789=="
176176
177177
--==123456789==
178178
Content-Length: 27
@@ -181,7 +181,7 @@ def test_unicode_content(self):
181181
182182
Iñtërnâtiônàlizætiøn
183183
--==123456789==--
184-
''', buf.getvalue().replace('\r\n', '\n'))
184+
'''.encode('utf-8'), buf.getvalue().replace(b'\r\n', b'\n'))
185185

186186
def test_unicode_content_ascii(self):
187187
buf = StringIO()
@@ -197,7 +197,7 @@ def test_unicode_headers(self):
197197
'{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09",'
198198
' "_id": "文档"}',
199199
headers={'Content-ID': u"文档"})
200-
self.assertEqual('''Content-Type: multipart/mixed; boundary="==123456789=="
200+
self.assertEqual(u'''Content-Type: multipart/mixed; boundary="==123456789=="
201201
202202
--==123456789==
203203
Content-ID: =?utf-8?b?5paH5qGj?=
@@ -206,7 +206,7 @@ def test_unicode_headers(self):
206206
Content-Type: application/json;charset=utf-8
207207
208208
{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
209-
''', buf.getvalue().replace('\r\n', '\n'))
209+
'''.encode('utf-8'), buf.getvalue().replace(b'\r\n', b'\n'))
210210

211211

212212
def suite():

0 commit comments

Comments
 (0)