From 0642dcb796313118dd81c3d12e044b4128c2746d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 14 Jun 2006 15:39:46 +0000 Subject: [PATCH] unit tests for dangling subquery, many-to-many clear-and-resave --- test/orm/objectstore.py | 36 ++++++++++++++++++++++++++++++++++++ test/sql/select.py | 5 +++++ 2 files changed, 41 insertions(+) diff --git a/test/orm/objectstore.py b/test/orm/objectstore.py index 83d279a284..4dc9624a98 100644 --- a/test/orm/objectstore.py +++ b/test/orm/objectstore.py @@ -1027,6 +1027,42 @@ class SaveTest(SessionTest): ctx.current.delete(objects[3]) ctx.current.flush() + + + def testmanytomanyupdate(self): + class Keyword(object): + def __init__(self, name): + self.name = name + def __eq__(self, other): + return other.name == self.name + def __repr__(self): + return "Keyword(%s, %s)" % (getattr(self, 'keyword_id', 'None'), self.name) + + mapper(Keyword, keywords) + mapper(Item, orderitems, properties = dict( + keywords = relation(Keyword, secondary=itemkeywords, lazy=False), + )) + + (k1, k2, k3) = (Keyword('keyword 1'), Keyword('keyword 2'), Keyword('keyword 3')) + item = Item() + item.item_name = 'item 1' + item.keywords.append(k1) + item.keywords.append(k2) + item.keywords.append(k3) + ctx.current.flush() + + item.keywords = [] + item.keywords.append(k1) + item.keywords.append(k2) + print item.keywords.unchanged_items() + print item.keywords.added_items() + print item.keywords.deleted_items() + ctx.current.flush() + + ctx.current.clear() + item = ctx.current.query(Item).get(item.item_id) + print [k1, k2] + assert item.keywords == [k1, k2] def testassociation(self): class IKAssociation(object): diff --git a/test/sql/select.py b/test/sql/select.py index 2481e04aed..290e324cf2 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -124,6 +124,11 @@ sq.mytable_description AS sq_mytable_description, sq.myothertable_otherid AS sq_ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") AS sq) AS sq2") def testwheresubquery(self): + # TODO: this tests that you dont get a "SELECT column" without a FROM but its not working yet. + #self.runtest( + # table1.select(table1.c.myid == select([table1.c.myid], table1.c.name=='jack')), "" + #) + self.runtest( table1.select(table1.c.myid == select([table2.c.otherid], table1.c.name == table2.c.othername)), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = (SELECT myothertable.otherid AS otherid FROM myothertable WHERE mytable.name = myothertable.othername)" -- 2.47.2