Skip to content

Commit

Permalink
Unbreak 'undo_multiple' under Py3k.
Browse files Browse the repository at this point in the history
Fixes Pylons#181.
  • Loading branch information
tseaver committed Dec 20, 2013
1 parent 6c5ded8 commit fab9065
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions substanced/sdi/views/tests/test_undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,38 @@ def getall(n):
self.assertTrue(txn.committed)
self.assertEqual(txn.user, 1)

def test_undo_multiple_with_text_in_POST(self):
import binascii
request = testing.DummyRequest()
context = testing.DummyResource()
inst = self._makeOne(context, request)
conn = DummyConnection()
def get_connection(req):
self.assertEqual(req, request)
return conn
inst.get_connection = get_connection
def authenticated_userid(req):
self.assertEqual(req, request)
return 1
post = testing.DummyResource()
enca = binascii.b2a_base64(b'a').decode('ascii')
encb = binascii.b2a_base64(b'b').decode('ascii')
info = [enca + ' b', encb + ' f']
def getall(n):
self.assertEqual(n, 'transaction')
return info
post.getall = getall
request.POST = post
request.sdiapi = DummySDIAPI()
inst.authenticated_userid = authenticated_userid
txn = DummyTransaction()
inst.transaction = txn
result = inst.undo_multiple()
self.assertEqual(result.location, '/mgmt_path')
self.assertEqual(conn._db.tids, [b'a', b'b'])
self.assertTrue(txn.committed)
self.assertEqual(txn.user, 1)

def test_undo_multiple_with_exception(self):
import binascii
from ZODB.POSException import POSError
Expand Down
2 changes: 2 additions & 0 deletions substanced/sdi/views/undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def undo_multiple(self):
uid = self.authenticated_userid(request)

for tid in transaction_info:
if not isinstance(tid, bytes): #pragma NO COVER Py3k
tid = tid.encode('ascii', 'surrogateescape')
tid = tid.split(b' ', 1)
if tid:
tids.append(decode64(tid[0]))
Expand Down

0 comments on commit fab9065

Please sign in to comment.