summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-01-28 14:20:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-01-28 14:20:25 -0500
commitc6e07f6a591b7172382370a09ca511e94d239723 (patch)
tree92adb4058910c90a080a777c321d7597ab4e4605 /test
parent029ae72b2fffc5a69acf7fc610377cd0a148870e (diff)
downloadsqlalchemy-c6e07f6a591b7172382370a09ca511e94d239723.tar.gz
- [bug] Fixed issue where the "required" exception
would not be raised for bindparam() with required=True, if the statement were given no parameters at all. [ticket:2381]
Diffstat (limited to 'test')
-rw-r--r--test/sql/test_compiler.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 9a53dd89c..b84a566d5 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -1918,6 +1918,48 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
{'x':12}
)
+ def test_bind_params_missing(self):
+ assert_raises_message(exc.InvalidRequestError,
+ r"A value is required for bind parameter 'x'",
+ select([table1]).where(
+ and_(
+ table1.c.myid==bindparam("x", required=True),
+ table1.c.name==bindparam("y", required=True)
+ )
+ ).compile().construct_params,
+ params=dict(y=5)
+ )
+
+ assert_raises_message(exc.InvalidRequestError,
+ r"A value is required for bind parameter 'x'",
+ select([table1]).where(
+ table1.c.myid==bindparam("x", required=True)
+ ).compile().construct_params
+ )
+
+ assert_raises_message(exc.InvalidRequestError,
+ r"A value is required for bind parameter 'x', "
+ "in parameter group 2",
+ select([table1]).where(
+ and_(
+ table1.c.myid==bindparam("x", required=True),
+ table1.c.name==bindparam("y", required=True)
+ )
+ ).compile().construct_params,
+ params=dict(y=5),
+ _group_number=2
+ )
+
+ assert_raises_message(exc.InvalidRequestError,
+ r"A value is required for bind parameter 'x', "
+ "in parameter group 2",
+ select([table1]).where(
+ table1.c.myid==bindparam("x", required=True)
+ ).compile().construct_params,
+ _group_number=2
+ )
+
+
@testing.emits_warning('.*empty sequence.*')
def test_in(self):