Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check in test I missed checking in yesterday
sigh
- Loading branch information
Jim Fulton
committed
Nov 18, 2016
1 parent
7396ca0
commit 9cfba5e
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) Zope Foundation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
import unittest | ||
import warnings | ||
|
||
from .._compat import dumps, loads, _protocol | ||
from ..Connection import TransactionMetaData | ||
|
||
class TransactionMetaDataTests(unittest.TestCase): | ||
|
||
def test_basic(self): | ||
t = TransactionMetaData( | ||
u'user\x80', u'description\x80', dict(foo='FOO')) | ||
self.assertEqual(t.user, b'user\xc2\x80') | ||
self.assertEqual(t.description, b'description\xc2\x80') | ||
self.assertEqual(t.extension, dict(foo='FOO')) | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
self.assertEqual(t._extension, t.extension) | ||
self.assertEqual(len(w), 1) | ||
self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) | ||
self.assertTrue("_extension is deprecated" in str(w[-1].message)) | ||
|
||
def test_basic_no_encoding(self): | ||
t = TransactionMetaData( | ||
b'user', b'description', dumps(dict(foo='FOO'), _protocol)) | ||
self.assertEqual(t.user, b'user') | ||
self.assertEqual(t.description, b'description') | ||
self.assertEqual(t.extension, dict(foo='FOO')) | ||
self.assertEqual(t._extension, t.extension) | ||
|
||
def test_constructor_default_args(self): | ||
t = TransactionMetaData() | ||
self.assertEqual(t.user, b'') | ||
self.assertEqual(t.description, b'') | ||
self.assertEqual(t.extension, {}) | ||
self.assertEqual(t._extension, t.extension) | ||
|
||
def test_set_extension(self): | ||
t = TransactionMetaData(u'', u'', b'') | ||
self.assertEqual(t.user, b'') | ||
self.assertEqual(t.description, b'') | ||
self.assertEqual(t.extension, {}) | ||
self.assertEqual(t._extension, t.extension) | ||
|
||
for name in 'extension', '_extension': | ||
data = {name: name + 'foo'} | ||
setattr(t, name, data) | ||
self.assertEqual(t.extension, data) | ||
self.assertEqual(t._extension, t.extension) | ||
data = {} | ||
setattr(t, name, data) | ||
self.assertEqual(t.extension, data) | ||
self.assertEqual(t._extension, t.extension) | ||
|
||
def test_used_by_connection(self): | ||
import ZODB | ||
from ZODB.MappingStorage import MappingStorage | ||
|
||
class Storage(MappingStorage): | ||
def tpc_begin(self, transaction): | ||
self.test_transaction = transaction | ||
return MappingStorage.tpc_begin(self, transaction) | ||
|
||
storage = Storage() | ||
conn = ZODB.connection(storage) | ||
with conn.transaction_manager as t: | ||
t.user = u'user\x80' | ||
t.description = u'description\x80' | ||
t.setExtendedInfo('foo', 'FOO') | ||
conn.root.x = 1 | ||
|
||
t = storage.test_transaction | ||
self.assertEqual(t.__class__, TransactionMetaData) | ||
self.assertEqual(t.user, b'user\xc2\x80') | ||
self.assertEqual(t.description, b'description\xc2\x80') | ||
self.assertEqual(t.extension, dict(foo='FOO')) | ||
|
||
def test_suite(): | ||
return unittest.makeSuite(TransactionMetaDataTests) | ||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='test_suite') | ||
|