Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
8c5f35f9
Commit
8c5f35f9
authored
Sep 02, 2005
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collector #556: sqlvar now returns 'null' rather than 'None'.
parent
8d8da935
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
0 deletions
+139
-0
lib/python/Shared/DC/ZRDB/sqlvar.py
lib/python/Shared/DC/ZRDB/sqlvar.py
+3
-0
lib/python/Shared/DC/ZRDB/tests/test_sqlvar.py
lib/python/Shared/DC/ZRDB/tests/test_sqlvar.py
+136
-0
No files found.
lib/python/Shared/DC/ZRDB/sqlvar.py
View file @
8c5f35f9
...
...
@@ -98,6 +98,9 @@ class SQLVar:
raise
raise
ValueError
,
'Missing input variable, <em>%s</em>'
%
name
if
v
is
None
:
return
'null'
if
t
==
'int'
:
try
:
if
type
(
v
)
is
StringType
:
...
...
lib/python/Shared/DC/ZRDB/tests/test_sqlvar.py
0 → 100644
View file @
8c5f35f9
##############################################################################
#
# Copyright (c) 2005 Zope Corporation 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
from
UserDict
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
SQLVarTests
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
from
Shared.DC.ZRDB.sqlvar
import
SQLVar
return
SQLVar
def
_makeOne
(
self
,
*
args
,
**
kw
):
return
self
.
_getTargetClass
()(
*
args
,
**
kw
)
def
test_constructor_no_type
(
self
):
from
DocumentTemplate.DT_Util
import
ParseError
self
.
assertRaises
(
ParseError
,
self
.
_makeOne
,
'foo'
)
def
test_constructor_invalid_type
(
self
):
from
DocumentTemplate.DT_Util
import
ParseError
self
.
assertRaises
(
ParseError
,
self
.
_makeOne
,
'foo type="nonesuch"'
)
def
test_constructor_valid_type
(
self
):
from
DocumentTemplate.DT_Util
import
ParseError
v
=
self
.
_makeOne
(
'foo type="string"'
)
self
.
assertEqual
(
v
.
__name__
,
'foo'
)
self
.
assertEqual
(
v
.
expr
,
'foo'
)
self
.
assertEqual
(
v
.
args
[
'type'
],
'string'
)
def
test_render_name_returns_value
(
self
):
v
=
self
.
_makeOne
(
'foo type="string"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
'FOO'
)),
'"FOO"'
)
def
test_render_name_missing_required_raises_ValueError
(
self
):
v
=
self
.
_makeOne
(
'foo type="string"'
)
self
.
assertRaises
(
ValueError
,
v
.
render
,
FauxMultiDict
())
def
test_render_name_missing_optional_returns_null
(
self
):
v
=
self
.
_makeOne
(
'foo type="string" optional'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
()),
'null'
)
def
test_render_expr_returns_value
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="string"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
'FOO'
)),
'"FOO"'
)
def
test_render_expr_missing_required_raises_NameError
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="string"'
)
self
.
assertRaises
(
NameError
,
v
.
render
,
FauxMultiDict
())
def
test_render_expr_missing_optional_returns_null
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="string" optional'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
()),
'null'
)
def
test_render_int_returns_int_without_quoting
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="int"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
42
)),
'42'
)
def
test_render_int_with_long_returns_value_without_L
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="int"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
'42L'
)),
'42'
)
def
test_render_int_required_invalid_raises_ValueError
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="int"'
)
self
.
assertRaises
(
ValueError
,
v
.
render
,
FauxMultiDict
(
foo
=
''
))
def
test_render_int_optional_invalid_returns_null
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="int" optional'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
''
)),
'null'
)
def
test_render_float_returns_float_without_quoting
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="float"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
3.1415
)),
'3.1415'
)
def
test_render_float_with_long_returns_value_without_L
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="float"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
'42L'
)),
'42'
)
def
test_render_float_required_invalid_raises_ValueError
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="float"'
)
self
.
assertRaises
(
ValueError
,
v
.
render
,
FauxMultiDict
(
foo
=
''
))
def
test_render_float_optional_invalid_returns_null
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="float" optional'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
''
)),
'null'
)
def
test_render_nb_required_with_blank_raises_ValueError
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="nb"'
)
self
.
assertRaises
(
ValueError
,
v
.
render
,
FauxMultiDict
(
foo
=
''
))
def
test_render_nb_optional_with_blank_returns_null
(
self
):
v
=
self
.
_makeOne
(
'expr="foo" type="nb" optional'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
''
)),
'null'
)
def
test_render_name_with_none_returns_null
(
self
):
# Collector #556, patch from Dieter Maurer
v
=
self
.
_makeOne
(
'foo type="string"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
None
)),
'null'
)
def
test_render_expr_with_none_returns_null
(
self
):
# Collector #556, patch from Dieter Maurer
v
=
self
.
_makeOne
(
'expr="foo" type="string"'
)
self
.
assertEqual
(
v
.
render
(
FauxMultiDict
(
foo
=
None
)),
'null'
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
SQLVarTests
))
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment