summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2017-01-30 17:27:21 -0500
committerGerrit Code Review <gerrit@awstats.zzzcomputing.com>2017-01-30 17:27:21 -0500
commit5ef2fde8fb25e30452e06764bf0ec022eb23c15d (patch)
tree5ec2f3bf339813aafde7353de71eb8e7e0d2ea40 /test
parentf411cac35001e0d40a6217846d3df40f676a2d4d (diff)
parentecfda6512cf8a50238529168932586444b657954 (diff)
downloadsqlalchemy-5ef2fde8fb25e30452e06764bf0ec022eb23c15d.tar.gz
Merge "Add count(), scalar() to baked query"
Diffstat (limited to 'test')
-rw-r--r--test/ext/test_baked.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/test/ext/test_baked.py b/test/ext/test_baked.py
index 818019de2..337fd4a12 100644
--- a/test/ext/test_baked.py
+++ b/test/ext/test_baked.py
@@ -6,7 +6,7 @@ from sqlalchemy import testing
from test.orm import _fixtures
from sqlalchemy.ext.baked import BakedQuery, baked_lazyload, BakedLazyLoader
from sqlalchemy.ext import baked
-from sqlalchemy import bindparam, func
+from sqlalchemy import bindparam, func, literal_column
from sqlalchemy.orm import exc as orm_exc
import itertools
from sqlalchemy.testing import mock
@@ -241,6 +241,43 @@ class LikeQueryTest(BakedTest):
eq_(u2.name, 'ed')
self.assert_sql_count(testing.db, go, 1)
+ def test_scalar(self):
+ User = self.classes.User
+
+ bq = self.bakery(lambda s: s.query(User.id))
+
+ sess = Session()
+
+ bq += lambda q: q.filter(User.id == 7)
+
+ eq_(
+ bq(sess).scalar(), 7
+ )
+
+ def test_count(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.id.in_([8, 9]))
+
+ eq_(
+ bq(sess).count(), 2
+ )
+
+ # original query still works
+ eq_(
+ set([(u.id, u.name) for u in bq(sess).all()]),
+ set([(8, 'ed'), (9, 'fred')])
+ )
+
def test_get_pk_w_null(self):
"""test the re-implementation of logic to do get with IS NULL."""