diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-04-19 19:47:02 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-04-19 19:47:02 +0000 |
commit | f85681d8a9ff78ac936ca4ba05147e2468804a4b (patch) | |
tree | 3043b004cc0c79d8ed0556686c83eddcf302935c | |
parent | d1fa8fe3272de79f120d9cf5e9e4a7f69bbcf343 (diff) | |
download | sqlalchemy-f85681d8a9ff78ac936ca4ba05147e2468804a4b.tar.gz |
what a strange thing to not be in there....
-rw-r--r-- | test/selectresults.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/selectresults.py b/test/selectresults.py new file mode 100644 index 000000000..6a3d9dd4d --- /dev/null +++ b/test/selectresults.py @@ -0,0 +1,68 @@ +from testbase import PersistTest +import testbase + +from sqlalchemy import * + +from sqlalchemy.mods.selectresults import SelectResultsExt + +class Foo(object): + pass + +class SelectResultsTest(PersistTest): + def setUpAll(self): + global foo + foo = Table('foo', testbase.db, + Column('id', Integer, Sequence('foo_id_seq'), primary_key=True), + Column('bar', Integer)) + + assign_mapper(Foo, foo, extension=SelectResultsExt()) + foo.create() + for i in range(100): + Foo(bar=i) + objectstore.commit() + + def setUp(self): + self.orig = Foo.mapper.select_whereclause() + self.res = Foo.select() + + def tearDownAll(self): + global foo + foo.drop() + + def test_slice(self): + assert self.res[1] == self.orig[1] + assert list(self.res[10:20]) == self.orig[10:20] + assert list(self.res[10:]) == self.orig[10:] + assert list(self.res[:10]) == self.orig[:10] + assert list(self.res[:10]) == self.orig[:10] + assert list(self.res[10:40:3]) == self.orig[10:40:3] + assert list(self.res[-5:]) == self.orig[-5:] + + def test_aggregate(self): + assert self.res.count() == 100 + assert self.res.filter(foo.c.bar<30).min(foo.c.bar) == 0 + assert self.res.filter(foo.c.bar<30).max(foo.c.bar) == 29 + # this one fails in mysql as the result comes back as a string + assert self.res.filter(foo.c.bar<30).sum(foo.c.bar) == 435 + # this one fails with postgres, the floating point comparison fails + assert self.res.filter(foo.c.bar<30).avg(foo.c.bar) == 14.5 + + def test_filter(self): + assert self.res.count() == 100 + assert self.res.filter(Foo.c.bar < 30).count() == 30 + res2 = self.res.filter(Foo.c.bar < 30).filter(Foo.c.bar > 10) + assert res2.count() == 19 + + def test_order_by(self): + assert self.res.order_by([Foo.c.bar])[0].bar == 0 + assert self.res.order_by([desc(Foo.c.bar)])[0].bar == 99 + + def test_offset(self): + assert list(self.res.order_by([Foo.c.bar]).offset(10))[0].bar == 10 + + def test_offset(self): + assert len(list(self.res.limit(10))) == 10 + + +if __name__ == "__main__": + testbase.main() |