[Modeling-cvs] ProjectModeling/Modeling/tests test_EditingContext_ParentChild.py,1.4,1.5
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-03-12 15:45:59
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/tests In directory sc8-pr-cvs1:/tmp/cvs-serv24823/tests Modified Files: test_EditingContext_ParentChild.py Log Message: Fixed EditingContext.objectsWithFetchSpecification(): when a nested EC asks for objects, the result set now correctly includes objects that are inserted in its parent (or grand-parent, etc.) and objects that are marked as deleted in the parent are excluded. See also: tests.test_EditingContext_ParentChild, test_10_child_gets_newly_inserted_objects() and test_11_child_doesnt_get_deleted_objects() Index: test_EditingContext_ParentChild.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/test_EditingContext_ParentChild.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_EditingContext_ParentChild.py 7 Mar 2003 16:34:44 -0000 1.4 --- test_EditingContext_ParentChild.py 12 Mar 2003 15:45:55 -0000 1.5 *************** *** 68,72 **** def test_02_objectsWithFetchSpecification(self): ! "[EC:parent/child] objectsWithFetchSpecification" parent_ec=EditingContext() ec=EditingContext(parent_ec) --- 68,76 ---- def test_02_objectsWithFetchSpecification(self): ! "[EC:parent/child] objectsWithFetchSpecification simple verifications" ! ## We check here that the basic functionality of fetching objects ! ## from a nested EC does behave as expected. Further testing is done ! ## in tests 10 and 11. ! parent_ec=EditingContext() ec=EditingContext(parent_ec) *************** *** 402,406 **** --- 406,475 ---- self.failUnless(mark.getExecutive()==cleese) + def test_10_child_gets_newly_inserted_objects(self): + "[EC:parent/child] Child-ec fetches newly inserted objects in parent" + # This starts like test_03_fetchedAndModifiedObjectsInParent + # We here want to check that when fetching objects in a child EC + # we get insertedObjects in the parent EC, as expected + parent_ec=EditingContext() + parent_ec.setPropagatesInsertionForRelatedObjects(1) + child_ec=EditingContext(parent_ec) + + qualifier=qualifierWithQualifierFormat('lastName=="Cleese"') + fetchSpec=FetchSpecification(entityName='Writer', qualifier=qualifier) + objects=parent_ec.objectsWithFetchSpecification(fetchSpec) + self.failUnless(len(objects)==1, 'Could not get Writer "Cleese"') + parent_cleese=objects[0] + + # Add a new Book + parent_test_book=Book() ; parent_test_book.setTitle('test') + parent_ec.insertObject(parent_test_book) + #parent_cleese.addToBooks(parent_test_book) + #parent_test_book.setAuthor(parent_cleese) + + # Now, ask the child for books: the new one, 'test', should be included + fetchSpec=FetchSpecification(entityName='Book') + objects=child_ec.objectsWithFetchSpecification(fetchSpec) + + #print len(objects), [o.getTitle() for o in objects] + self.failUnless(len(objects)==5, + 'Failed to get the object inserted in the parent_ec()') + child_test_book=[b for b in objects if b.getTitle()=='test'][0] + + + # Check that the object was correctly registered within the child ec + self.failUnless(child_ec.globalIDForObject(child_test_book), + "child_test_book is not known to the child ec") + + # Check that the objects are different but have the same GlobalID + self.assertNotEqual(child_test_book, parent_test_book) + self.assertEqual(child_ec.globalIDForObject(child_test_book), + parent_ec.globalIDForObject(parent_test_book)) + def test_11_child_doesnt_get_deleted_objects(self): + "[EC:parent/child] Child-ec does not fetch objects deleted in parent" + # We want to check that when fetching objects in a child EC + # we do not get objects marked as deleted in the parent EC, as expected + parent_ec=EditingContext() + parent_ec.setPropagatesInsertionForRelatedObjects(1) + child_ec=EditingContext(parent_ec) + + qualifier=qualifierWithQualifierFormat('lastName=="Cleese"') + fetchSpec=FetchSpecification(entityName='Writer', qualifier=qualifier) + objects=parent_ec.objectsWithFetchSpecification(fetchSpec) + self.failUnless(len(objects)==1, 'Could not get Writer "Cleese"') + parent_cleese=objects[0] + + parent_ec.deleteObject(parent_cleese) + + # Now, ask the child for writers: we shouldn't get John Cleese + fetchSpec=FetchSpecification(entityName='Writer') + objects=child_ec.objectsWithFetchSpecification(fetchSpec) + + self.failUnless(len(objects)==2, + 'Got %s writers, expected: 2'%len(objects)) + verif=[w for w in objects if w.getLastName()=='Cleese'] + self.failIf(verif, + 'obj.W/FetchSpec() should not have returned John Cleese') + def tearDown(self): """ |