[Sqlalchemy-commits] [1097] sqlalchemy/trunk/test: added unittest for orm-persisted insert without a
Brought to you by:
zzzeek
<!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>[1097] sqlalchemy/trunk/test: added unittest for orm-persisted insert without a postfetch, tweak to engine to only signal postfetch if the passivedefault columns received None/NULL for their parameter (since they dont exec otherwise)</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1097</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-03-05 15:10:20 -0600 (Sun, 05 Mar 2006)</dd> </dl> <h3>Log Message</h3> <pre>added unittest for orm-persisted insert without a postfetch, tweak to engine to only signal postfetch if the passivedefault columns received None/NULL for their parameter (since they dont exec otherwise)</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunklibsqlalchemyenginepy">sqlalchemy/trunk/lib/sqlalchemy/engine.py</a></li> <li><a href="#sqlalchemytrunktestobjectstorepy">sqlalchemy/trunk/test/objectstore.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunklibsqlalchemyenginepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/engine.py (1096 => 1097)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/engine.py 2006-03-05 21:01:21 UTC (rev 1096) +++ sqlalchemy/trunk/lib/sqlalchemy/engine.py 2006-03-05 21:10:20 UTC (rev 1097) </span><span class="lines">@@ -468,9 +468,9 @@ </span><span class="cx"> last_inserted_ids = [] </span><span class="cx"> need_lastrowid=False </span><span class="cx"> for c in compiled.statement.table.c: </span><del>- if isinstance(c.default, schema.PassiveDefault): - self.context.lastrow_has_defaults = True </del><span class="cx"> if not param.has_key(c.name) or param[c.name] is None: </span><ins>+ if isinstance(c.default, schema.PassiveDefault): + self.context.lastrow_has_defaults = True </ins><span class="cx"> newid = drunner.get_column_default(c) </span><span class="cx"> if newid is not None: </span><span class="cx"> param[c.name] = newid </span></span></pre></div> <a id="sqlalchemytrunktestobjectstorepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/objectstore.py (1096 => 1097)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/objectstore.py 2006-03-05 21:01:21 UTC (rev 1096) +++ sqlalchemy/trunk/test/objectstore.py 2006-03-05 21:10:20 UTC (rev 1097) </span><span class="lines">@@ -213,6 +213,9 @@ </span><span class="cx"> objectstore.commit() </span><span class="cx"> </span><span class="cx"> class DefaultTest(AssertMixin): </span><ins>+ """tests that when saving objects whose table contains DefaultGenerators, either python-side, preexec or database-side, + the newly saved instances receive all the default values either through a post-fetch or getting the pre-exec'ed + defaults back from the engine.""" </ins><span class="cx"> def setUpAll(self): </span><span class="cx"> #db.echo = 'debug' </span><span class="cx"> use_string_defaults = db.engine.__module__.endswith('postgres') or db.engine.__module__.endswith('oracle') or db.engine.__module__.endswith('sqlite') </span><span class="lines">@@ -236,8 +239,7 @@ </span><span class="cx"> self.table.drop() </span><span class="cx"> def setUp(self): </span><span class="cx"> self.table = Table('default_test', db) </span><del>- def testbasic(self): - </del><ins>+ def testinsert(self): </ins><span class="cx"> class Hoho(object):pass </span><span class="cx"> assign_mapper(Hoho, self.table) </span><span class="cx"> h1 = Hoho(hoho=self.althohoval) </span><span class="lines">@@ -264,6 +266,16 @@ </span><span class="cx"> self.assert_(h2.foober == h3.foober == h4.foober == 'im foober') </span><span class="cx"> self.assert_(h5.foober=='im the new foober') </span><span class="cx"> </span><ins>+ def testinsertnopostfetch(self): + # populates the PassiveDefaults explicitly so there is no "post-update" + class Hoho(object):pass + assign_mapper(Hoho, self.table) + h1 = Hoho(hoho="15", counter="15") + objectstore.commit() + self.assert_(h1.hoho=="15") + self.assert_(h1.counter=="15") + self.assert_(h1.foober=="im foober") + </ins><span class="cx"> def testupdate(self): </span><span class="cx"> class Hoho(object):pass </span><span class="cx"> assign_mapper(Hoho, self.table) </span></span></pre> </div> </div> </body> </html> |