summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMalaclypse The Younger <pat-androidsrc@flyingcarsandstuff.com>2017-03-30 10:54:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-30 12:33:33 -0400
commit74f6c21747d07a8cf9902900df9280a84aadc2bb (patch)
treeed015e93b69651ac81ca55d4b2162b4589418634 /test
parenta4c17c1397c68d109bcf0603644f3200ab2e82f5 (diff)
downloadsqlalchemy-74f6c21747d07a8cf9902900df9280a84aadc2bb.tar.gz
Add bindparams support for baked Result count() method
Added support for bound parameters, e.g. those normally set up via :meth:`.Query.params`, to the :meth:`.baked.Result.count` method. Previously, support for parameters were omitted. Pull request courtesy Pat Deegan. Change-Id: I8c33548cf2a483699767e459731694c8cadebff6 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/350
Diffstat (limited to 'test')
-rw-r--r--test/ext/test_baked.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ext/test_baked.py b/test/ext/test_baked.py
index 4a1f086a5..a5eb31495 100644
--- a/test/ext/test_baked.py
+++ b/test/ext/test_baked.py
@@ -288,6 +288,34 @@ class LikeQueryTest(BakedTest):
set([(8, 'ed'), (9, 'fred')])
)
+ def test_count_with_bindparams(self):
+ User = self.classes.User
+
+ bq = self.bakery(lambda s: s.query(User))
+
+ sess = Session()
+
+ eq_(
+ bq(sess).count(),
+ 4
+ )
+
+ bq += lambda q: q.filter(User.name == bindparam("uname"))
+ # calling with *args
+ eq_(
+ bq(sess).params(uname='fred').count(), 1
+ )
+ # with multiple params, the **kwargs will be used
+ bq += lambda q: q.filter(User.id == bindparam("anid"))
+ eq_(
+ bq(sess).params(uname='fred', anid=9).count(), 1
+ )
+ eq_(
+ # wrong id, so 0 results:
+ bq(sess).params(uname='fred', anid=8).count(), 0
+ )
+
+
def test_get_pk_w_null(self):
"""test the re-implementation of logic to do get with IS NULL."""