Mercurial > p > roundup > code
diff test/rest_common.py @ 5647:095db27e8064
Trying to make StringIO handle unicode and pass it through to
FieldStorage to eliminate the error:
self = FieldStorage(None, None, ''), line = '{ "data": "Joe Doe 1" }'
def __write(self, line):
"""line is always bytes, not string"""
if self.__file is not None:
if self.__file.tell() + len(line) > 1000:
self.file = self.make_file()
data = self.__file.getvalue()
self.file.write(data)
self.__file = None
if self._binary_file:
# keep bytes
self.file.write(line)
else:
# decode to string
> self.file.write(line.decode(self.encoding, self.errors))
E AttributeError: 'str' object has no attribute 'decode'
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 10 Mar 2019 19:56:35 -0400 |
| parents | 7f4d19867123 |
| children | e8ca7072c629 ba67e397f063 |
line wrap: on
line diff
--- a/test/rest_common.py Sun Mar 10 19:30:03 2019 -0400 +++ b/test/rest_common.py Sun Mar 10 19:56:35 2019 -0400 @@ -14,7 +14,7 @@ from .mocknull import MockNull -from roundup.anypy.strings import StringIO +from io import StringIO import json NEEDS_INSTANCE = 1 @@ -409,7 +409,7 @@ # simulate: /rest/data/user/<id>/realname # use etag in header etag = calculate_etag(self.db.user.getnode(self.joeid)) - body='{ "data": "Joe Doe 1" }' + body=u'{ "data": "Joe Doe 1" }' env = { "CONTENT_TYPE": "application/json", "CONTENT_LENGTH": len(body), "REQUEST_METHOD": "PUT" @@ -442,7 +442,7 @@ # simulate: /rest/data/user/<id>/realname # use etag in payload etag = calculate_etag(self.db.user.getnode(self.joeid)) - body='{ "@etag": "%s", "data": "Joe Doe 2" }'%etag + body=u'{ "@etag": "%s", "data": "Joe Doe 2" }'%etag env = { "CONTENT_TYPE": "application/json", "CONTENT_LENGTH": len(body), "REQUEST_METHOD": "PUT" @@ -510,7 +510,7 @@ self.assertEqual(self.dummy_client.response_code, 200) etag = calculate_etag(self.db.user.getnode(self.joeid)) - body='{ "address": "demo2@example.com", "@etag": "%s"}'%etag + body=u'{ "address": "demo2@example.com", "@etag": "%s"}'%etag env = { "CONTENT_TYPE": "application/json", "CONTENT_LENGTH": len(body), "REQUEST_METHOD": "PATCH" @@ -536,7 +536,7 @@ # and set it back etag = calculate_etag(self.db.user.getnode(self.joeid)) - body='{ "address": "%s", "@etag": "%s"}'%( + body=u'{ "address": "%s", "@etag": "%s"}'%( stored_results['data']['attributes']['address'], etag) # reuse env and headers from prior test. @@ -557,7 +557,7 @@ del(self.headers) # POST to create new issue - body='{ "title": "foo bar", "priority": "critical" }' + body=u'{ "title": "foo bar", "priority": "critical" }' env = { "CONTENT_TYPE": "application/json", "CONTENT_LENGTH": len(body),
