[Modeling-cvs] ProjectModeling/Modeling/tests test_EditingContext_Global.py,1.35,1.36
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-08-02 11:15:00
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/tests In directory sc8-pr-cvs1:/tmp/cvs-serv32454/tests Modified Files: test_EditingContext_Global.py Log Message: Fixed bug #774989: improper result returned by CustomObject.snapshot() wrt tomany relationships --see CustomObject.snapshot() documentation for details. Index: test_EditingContext_Global.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/test_EditingContext_Global.py,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** test_EditingContext_Global.py 2 Aug 2003 09:40:49 -0000 1.35 --- test_EditingContext_Global.py 2 Aug 2003 11:14:57 -0000 1.36 *************** *** 22,25 **** --- 22,26 ---- # #----------------------------------------------------------------------------- + from __future__ import nested_scopes """ *************** *** 920,924 **** ec.saveChanges() gid=ec.globalIDForObject(w) ! self.assertEqual(b.getFK_Writer_Id(), gid.keyValues()['id']) def test_18_percent_in_qualifiers_should_be_correctly_escaped(self): --- 921,928 ---- ec.saveChanges() gid=ec.globalIDForObject(w) ! # a FK defined as a class property is NOT updated by the framework ! # see the User's Guide, section B.1 ! # so we get None instead of gid.keyValues()['id'] ! self.assertEqual(b.getFK_Writer_Id(), None) def test_18_percent_in_qualifiers_should_be_correctly_escaped(self): *************** *** 962,970 **** def test_20_snapshot(self): ! "[EditingContext] snapshot: TBD" ! pass ! def test_21_snapshot_raw(self): ! "[EditingContext] snapshot_raw" ec=EditingContext() --- 966,1045 ---- def test_20_snapshot(self): ! "[EditingContext] CustomObject.snapshot()" ! ec=EditingContext() ! ! ## single object, no object related ! w=Writer() ! w.setLastName('Test'); w.setFirstName('20') ! ec.insertObject(w) ! ! ws=w.snapshot() ! def check_single_object(): ! self.assertEqual(ws['lastName'], 'Test') ! self.assertEqual(ws['firstName'], '20') ! self.assertEqual(ws['birthday'], None) ! self.assertEqual(ws['pygmalion'], None) ! self.assertEqual(ws['books'], []) ! check_single_object() ! ec.saveChanges() ! check_single_object() ! ! ## all objects saved, no faults here ! b1=Book(); b1.setTitle('b1') ! b2=Book(); b2.setTitle('b2') ! ec.insert(b1) ! ec.insert(b2) ! w.addToBooks(b1) ; b1.setAuthor(w) ! w.addToBooks(b2) ; b2.setAuthor(w) ! p=Writer(); p.setLastName('test_20 pygmalion') ! ec.insert(p) ! w.setPygmalion(p) ! ws=w.snapshot() ! self.assertEqual(ws['lastName'], 'Test') ! self.assertEqual(ws['firstName'], '20') ! self.assertEqual(ws['pygmalion'], p.globalID()) ! self.assertEqual(len(ws['books']), 2) ! self.failUnless(b1.globalID() in ws['books']) ! self.failUnless(b2.globalID() in ws['books']) ! ec.saveChanges() ! p_globalID=p.globalID() ! del ec ! ! ## Now both relationships 'pygmalion' and 'books' are faults ! ec=EditingContext() ! w=ec.fetch('Writer', 'lastName=="Test" and firstName=="20"')[0] ! ws=w.snapshot() ! self.assertEqual(ws['lastName'], 'Test') ! self.assertEqual(ws['firstName'], '20') ! ! # for a faulted to-one rel, we get the corresponding globalID ! self.assertEqual(ws['pygmalion'], p_globalID) ! self.failUnless(w.getPygmalion().isFault()) ! ! # for a faulted to-many rel, we get a CustomObject.Snapshot_ToManyFault ! self.failUnless(w.getBooks().isFault()) ! from Modeling.FaultHandler import AccessArrayFaultHandler ! from Modeling.CustomObject import Snapshot_ToManyFault ! self.assertEqual(ws['books'].__class__, Snapshot_ToManyFault) ! ! # last, we check that the to-many fault is accessible, if we want to: ! self.assertEqual(ws['books'].sourceGlobalID, w.globalID()) ! self.assertEqual(ws['books'].key, 'books') ! tomany_fault=ws['books'].getToManyFault(ec) ! from Modeling.FaultHandler import AccessArrayFaultHandler ! self.failUnless(isinstance(tomany_fault, AccessArrayFaultHandler)) ! self.failUnless(tomany_fault.isFault()) ! ! # check that we got the same set of objects ! adaptorChannel=concreteAdaptorChannelForEntity('Writer', ec) ! fetchCount=adaptorChannel._count_for_execute ! self.assertEqual(len(tomany_fault), 2) ! self.assertEqual(adaptorChannel._count_for_execute, ! fetchCount+1) # fault was cleared ! for book in w.getBooks(): ! self.failIf(book not in tomany_fault) ! def test_21_snapshot_raw(self): ! "[EditingContext] CustomObject.snapshot_raw()" ec=EditingContext() *************** *** 972,977 **** --- 1047,1055 ---- raw_fdard=ec.fetch('Writer', 'age == 82', rawRows=1)[0] fdard=ec.fetch('Writer', 'age == 82')[0] + rabelais=ec.fetch('Writer', 'lastName == "Rabelais"')[0] fdard_snapshot_raw=fdard.snapshot_raw() self.assertEqual(raw_fdard, fdard_snapshot_raw) + self.assertEqual(fdard_snapshot_raw['FK_Writer_id'], + rabelais.globalID().keyValues()['id']) # new object, related to saved objects *************** *** 982,986 **** self.assertEqual(w_sr.keys(), fdard_snapshot_raw.keys()) self.assertEqual(w_sr['FK_Writer_id'], fdard.globalID().keyValues()['id']) ! self.assertEqual(w_sr['id'], w.globalID()) w.setPygmalion(None) ec.delete(w) --- 1060,1065 ---- self.assertEqual(w_sr.keys(), fdard_snapshot_raw.keys()) self.assertEqual(w_sr['FK_Writer_id'], fdard.globalID().keyValues()['id']) ! self.assertEqual(w_sr['id'], w.globalID()) # we get a TemporaryGlobalID ! self.failUnless(w_sr['id'].isTemporary()) w.setPygmalion(None) ec.delete(w) |