From 901829a7e3cd4be6bcd506e900f0fd814bab3562 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 9 Dec 2007 16:11:21 +0000 Subject: [PATCH] - added a test for boolean saves/retrieves --- test/orm/memusage.py | 2 +- test/orm/unitofwork.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/test/orm/memusage.py b/test/orm/memusage.py index e8d98aa426..756074010b 100644 --- a/test/orm/memusage.py +++ b/test/orm/memusage.py @@ -75,7 +75,7 @@ class MemUsageTest(AssertMixin): A(col2="a3", bs=[B(col2="b3")]) ], alist) - + for a in alist: sess.delete(a) sess.flush() diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index 0464e2364e..8f5d5d2c44 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -10,6 +10,8 @@ from testlib import tables, fixtures """tests unitofwork operations""" +# TODO: convert suite to not use Session.mapper, use fixtures.Base +# with explicit session.save() Session = scoped_session(sessionmaker(autoflush=True, transactional=True)) mapper = Session.mapper @@ -1732,6 +1734,43 @@ class SaveTest3(ORMTest): Session.commit() assert t2.count().scalar() == 0 +class BooleanColTest(ORMTest): + def define_tables(self, metadata): + global t + t =Table('t1', metadata, + Column('id', Integer, primary_key=True), + Column('name', String(30)), + Column('value', Boolean)) + + def test_boolean(self): + # use the regular mapper + from sqlalchemy.orm import mapper + + class T(fixtures.Base): + pass + mapper(T, t) + + sess = create_session() + t1 = T(value=True, name="t1") + t2 = T(value=False, name="t2") + t3 = T(value=True, name="t3") + sess.save(t1) + sess.save(t2) + sess.save(t3) + + sess.flush() + + for clear in (False, True): + if clear: + sess.clear() + self.assertEquals(sess.query(T).all(), [T(value=True, name="t1"), T(value=False, name="t2"), T(value=True, name="t3")]) + if clear: + sess.clear() + self.assertEquals(sess.query(T).filter(T.value==True).all(), [T(value=True, name="t1"),T(value=True, name="t3")]) + if clear: + sess.clear() + self.assertEquals(sess.query(T).filter(T.value==False).all(), [T(value=False, name="t2")]) + class RowSwitchTest(ORMTest): def define_tables(self, metadata): global t1, t2, t3, t1t3 -- 2.47.3