Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix sqltest behavior with bytes inputs
- Loading branch information
Showing
3 changed files
with
63 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
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
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,58 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2005 Zope Foundation and Contributors. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (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 | ||
|
||
from six.moves import UserDict | ||
|
||
|
||
def _sql_quote(v): | ||
return '"%s"' % v | ||
|
||
|
||
class FauxMultiDict(UserDict): | ||
|
||
def getitem(self, key, call): | ||
if key == 'sql_quote__': | ||
return _sql_quote | ||
|
||
v = self[key] | ||
if v is not None: | ||
if call and callable(v): | ||
v = v() | ||
return v | ||
|
||
|
||
class SQLTestTests(unittest.TestCase): | ||
|
||
def _getTargetClass(self): | ||
from Shared.DC.ZRDB.sqltest import SQLTest | ||
return SQLTest | ||
|
||
def _makeOne(self, *args, **kw): | ||
return self._getTargetClass()(*args, **kw) | ||
|
||
def test_simple(self): | ||
tested = self._makeOne('foo type="string"') | ||
self.assertEqual(tested.render(FauxMultiDict(foo='FOO')), | ||
'foo = "FOO"') | ||
|
||
def test_binary(self): | ||
tested = self._makeOne('foo type="string"') | ||
self.assertEqual(tested.render(FauxMultiDict(foo=b'FOO')), | ||
'foo = "FOO"') | ||
|
||
|
||
def test_suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(SQLTestTests)) | ||
return suite |