[Sqlalchemy-commits] [1233] sqlalchemy/trunk/test: added unit test for the old commit that was in [c
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-03-31 23:43:36
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1233] sqlalchemy/trunk/test: added unit test for the old commit that was in [changeset:1186].</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1233</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-03-31 17:43:20 -0600 (Fri, 31 Mar 2006)</dd> </dl> <h3>Log Message</h3> <pre>added unit test for the old commit that was in [changeset:1186]. modified its behavior a bit to not delete private relationships unless they were already marked as deleted at the attribute manipulation level. got "switching" behavior from one private relationship to another to work, added a unit test for that.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunklibsqlalchemymappingpropertiespy">sqlalchemy/trunk/lib/sqlalchemy/mapping/properties.py</a></li> <li><a href="#sqlalchemytrunklibsqlalchemymappingunitofworkpy">sqlalchemy/trunk/lib/sqlalchemy/mapping/unitofwork.py</a></li> <li><a href="#sqlalchemytrunktestobjectstorepy">sqlalchemy/trunk/test/objectstore.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunklibsqlalchemymappingpropertiespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/mapping/properties.py (1232 => 1233)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/mapping/properties.py 2006-03-31 22:28:17 UTC (rev 1232) +++ sqlalchemy/trunk/lib/sqlalchemy/mapping/properties.py 2006-03-31 23:43:20 UTC (rev 1233) </span><span class="lines">@@ -451,7 +451,10 @@ </span><span class="cx"> for child in childlist.deleted_items() + childlist.unchanged_items(): </span><span class="cx"> if child is None: </span><span class="cx"> continue </span><del>- uowcommit.register_object(child, isdelete=True) </del><ins>+ # if private child object, and is in the uow's "deleted" list, + # insure its in the list of items to be deleted + if child in uowcommit.uow.deleted: + uowcommit.register_object(child, isdelete=True) </ins><span class="cx"> elif self.post_update: </span><span class="cx"> # post_update means we have to update our row to not reference the child object </span><span class="cx"> # before we can DELETE the row </span><span class="lines">@@ -462,16 +465,15 @@ </span><span class="cx"> # head object is being deleted, and we manage its list of child objects </span><span class="cx"> # the child objects have to have their foreign key to the parent set to NULL </span><span class="cx"> if self.private and not self.post_update: </span><del>- # if we are privately managed, then all our objects should - # have been marked as "todelete" already and no attribute adjustment is needed. - # however, if they say objectstore.commit(x), i.e. on an individual object, - # then this extra step is more important. </del><span class="cx"> for obj in deplist: </span><span class="cx"> childlist = getlist(obj, False) </span><span class="cx"> for child in childlist.deleted_items() + childlist.unchanged_items(): </span><span class="cx"> if child is None: </span><span class="cx"> continue </span><del>- uowcommit.register_object(child, isdelete=True) </del><ins>+ # if private child object, and is in the uow's "deleted" list, + # insure its in the list of items to be deleted + if child in uowcommit.uow.deleted: + uowcommit.register_object(child, isdelete=True) </ins><span class="cx"> else: </span><span class="cx"> for obj in deplist: </span><span class="cx"> childlist = getlist(obj, False) </span><span class="lines">@@ -529,8 +531,6 @@ </span><span class="cx"> for child in childlist.deleted_items(): </span><span class="cx"> if not self.private: </span><span class="cx"> self._synchronize(obj, child, None, True) </span><del>- if self.direction == PropertyLoader.ONETOMANY: - # for a cyclical task, this registration is handled by the objectstore </del><span class="cx"> uowcommit.register_object(child, isdelete=self.private) </span><span class="cx"> </span><span class="cx"> def execute(self, instance, row, identitykey, imap, isnew): </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemymappingunitofworkpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/mapping/unitofwork.py (1232 => 1233)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/mapping/unitofwork.py 2006-03-31 22:28:17 UTC (rev 1232) +++ sqlalchemy/trunk/lib/sqlalchemy/mapping/unitofwork.py 2006-03-31 23:43:20 UTC (rev 1233) </span><span class="lines">@@ -44,7 +44,8 @@ </span><span class="cx"> def list_value_changed(self, obj, key, item, listval, isdelete): </span><span class="cx"> sess = get_session(obj) </span><span class="cx"> if not isdelete and sess.deleted.contains(item): </span><del>- raise InvalidRequestError("re-inserting a deleted value into a list") </del><ins>+ #raise InvalidRequestError("re-inserting a deleted value into a list") + del sess.deleted[item] </ins><span class="cx"> sess.modified_lists.append(self) </span><span class="cx"> if self.deleteremoved and isdelete: </span><span class="cx"> sess.register_deleted(item) </span></span></pre></div> <a id="sqlalchemytrunktestobjectstorepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/objectstore.py (1232 => 1233)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/objectstore.py 2006-03-31 22:28:17 UTC (rev 1232) +++ sqlalchemy/trunk/test/objectstore.py 2006-03-31 23:43:20 UTC (rev 1233) </span><span class="lines">@@ -263,7 +263,80 @@ </span><span class="cx"> e.assigned = datetime.date.today() </span><span class="cx"> e.data = 'some more data' </span><span class="cx"> objectstore.commit() </span><ins>+ +class PrivateAttrTest(AssertMixin): + """tests various things to do with private=True mappers""" + def setUpAll(self): + global a_table, b_table + a_table = Table('a',testbase.db, + Column('a_id', Integer, Sequence('next_a_id'), primary_key=True), + Column('data', String(10)), + ).create() + + b_table = Table('b',testbase.db, + Column('b_id',Integer,Sequence('next_b_id'),primary_key=True), + Column('a_id',Integer,ForeignKey('a.a_id')), + Column('data',String(10))).create() + def tearDownAll(self): + b_table.drop() + a_table.drop() + def setUp(self): + objectstore.clear() + clear_mappers() + + def testsinglecommit(self): + """tests that a commit of a single object deletes private relationships""" + class A(object):pass + class B(object):pass + + assign_mapper(B,b_table) + assign_mapper(A,a_table,properties= {'bs' : relation + (B.mapper,private=True)}) + + # create some objects + a = A(data='a1') + a.bs = [] + + # add a 'B' instance + b1 = B(data='1111') + a.bs.append(b1) + + # add another one + b2 = B(data='2222') + a.bs.append(b2) + + # inserts both A and Bs + objectstore.commit(a) + + objectstore.delete(a) + objectstore.commit(a) </ins><span class="cx"> </span><ins>+ assert b_table.count().scalar() == 0 + + def testswitchparent(self): + """tests that you can switch the parent of an object in a backref scenario""" + class A(object):pass + class B(object):pass + + assign_mapper(B,b_table) + assign_mapper(A,a_table,properties= { + 'bs' : relation (B.mapper,private=True, backref='a')} + ) + a1 = A(data='testa1') + a2 = A(data='testa2') + b = B(data='testb') + b.a = a1 + objectstore.commit() + objectstore.clear() + sess = objectstore.get_session() + a1 = A.mapper.get(a1.a_id) + a2 = A.mapper.get(a2.a_id) + assert a1.bs[0].a is a1 + b = a1.bs[0] + b.a = a2 + assert b not in sess.deleted + objectstore.commit() + </ins><span class="cx"> class DefaultTest(AssertMixin): </span><span class="cx"> """tests that when saving objects whose table contains DefaultGenerators, either python-side, preexec or database-side, </span><span class="cx"> the newly saved instances receive all the default values either through a post-fetch or getting the pre-exec'ed </span></span></pre> </div> </div> </body> </html> |