[Modeling-cvs] ProjectModeling/Modeling/tests test_PyModel.py,1.1.2.1,1.1.2.2
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-05-18 11:54:38
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/tests In directory sc8-pr-cvs1:/tmp/cvs-serv11619 Modified Files: Tag: brch-0_9pre7-1-PyModel test_PyModel.py Log Message: Reorganized the tests --factorization of tests in check_model() and check_inverse_rels() Index: test_PyModel.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/Attic/test_PyModel.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_PyModel.py 15 May 2003 17:44:58 -0000 1.1.2.1 --- test_PyModel.py 18 May 2003 11:54:34 -0000 1.1.2.2 *************** *** 52,56 **** --- 52,115 ---- self.failUnless(r.destinationEntity(),'%s.%s.destinationEntity() is None'%(e.name(),r.name())) + + def check_model(self, model): + """ + This method tests that: + + - checkEntitiesProperties() succeeds, + + - SalesClerk has 2 relationships, + + - for Employee and SalesClerk, relationships 'toStore' and 'toMarks' + have the correct multiplicity, that their source and destination + attributes are correct, and that their destination entities are correct + + """ + emp=model.component.entityNamed('Employee') + sc=model.component.entityNamed('SalesClerk') + store=model.component.entityNamed('Store') + mark=model.component.entityNamed('Mark') + + self.checkEntitiesProperties((emp,sc,store,mark)) + + self.assertEqual(len(sc.relationships()), 2) + + def check(self, toStore, toMarks, store, mark): + self.failUnless(toStore.isToOne()) + self.failUnless(toMarks.isToMany()) + self.assertEqual(toStore.destinationEntity(), store) + self.assertEqual(toMarks.destinationEntity(), mark) + + # Check toStore and toMarks for Employee + toStore=emp.propertyNamed('toStore') + toMarks=emp.propertyNamed('toMarks') + check(self, toStore, toMarks, store, mark) + self.failIf(emp.propertyNamed('fkStore') not in toStore.sourceAttributes()) + self.failIf(store.propertyNamed('id') not in toStore.destinationAttributes()) + self.failIf(emp.propertyNamed('id') not in toMarks.sourceAttributes()) + self.failIf(mark.propertyNamed('fkEmployee') not in toMarks.destinationAttributes()) + + # Check toStore and toMarks for SalesClerk + toStore=sc.propertyNamed('toStore') + toMarks=sc.propertyNamed('toMarks') + check(self, toStore, toMarks, store, mark) + self.failIf(sc.propertyNamed('fkStore') not in toStore.sourceAttributes()) + self.failIf(store.propertyNamed('id') not in toStore.destinationAttributes()) + self.failIf(sc.propertyNamed('id') not in toMarks.sourceAttributes()) + self.failIf(mark.propertyNamed('fkEmployee') not in toMarks.destinationAttributes()) + + def check_inverse_rels(self, model): + """ + This method checks that Employee.toStore (resp. Employee.toMarks) is the + inverse relationship for Store.toEmployees (resp. Mark.toEmployee) + """ + emp=model.component.entityNamed('Employee') + sc=model.component.entityNamed('SalesClerk') + store=model.component.entityNamed('Store') + mark=model.component.entityNamed('Mark') + self.failUnless(mark.relationshipNamed('toEmployee').inverseRelationship()==emp.propertyNamed('toMarks')) + self.failUnless(store.relationshipNamed('toEmployees').inverseRelationship()==emp.propertyNamed('toStore')) + ## BEGIN tests def setUp(self): self.model = Model('StoreEmployees',adaptorName='Postgresql') *************** *** 156,181 **** ] model.build() ! emp=model.component.entityNamed('Employee') ! sc=model.component.entityNamed('SalesClerk') ! store=model.component.entityNamed('Store') ! mark=model.component.entityNamed('Mark') ! ! self.checkEntitiesProperties((emp,sc,store,mark)) ! ! self.assertEqual(len(sc.relationships()), 2) ! ! def check(self, toStore, toMarks, store, mark): ! self.failUnless(toStore.isToOne()) ! self.failUnless(toMarks.isToMany()) ! self.assertEqual(toStore.destinationEntity(), store) ! self.assertEqual(toMarks.destinationEntity(), mark) ! ! toStore=emp.propertyNamed('toStore') ! toMarks=emp.propertyNamed('toMarks') ! check(self, toStore, toMarks, store, mark) ! ! toStore=sc.propertyNamed('toStore') ! toMarks=sc.propertyNamed('toMarks') ! check(self, toStore, toMarks, store, mark) def test_05_unqualified_relationships_no_inverse(self): --- 215,219 ---- ] model.build() ! self.check_model(model) def test_05_unqualified_relationships_no_inverse(self): *************** *** 193,196 **** --- 231,236 ---- ] model.build() + self.check_model(model) + emp=model.component.entityNamed('Employee') sc=model.component.entityNamed('SalesClerk') *************** *** 198,202 **** mark=model.component.entityNamed('Mark') - self.checkEntitiesProperties((emp,sc,store,mark)) self.assertEqual(len(sc.relationships()), 2) --- 238,241 ---- *************** *** 211,238 **** self.failUnless(sc.attributeNamed('fkStore')) self.failUnless(mark.attributeNamed('fkEmployee')) - - def check(self, toStore, toMarks, store, mark): - self.failUnless(toStore.isToOne()) - self.failUnless(toMarks.isToMany()) - self.assertEqual(toStore.destinationEntity(), store) - self.assertEqual(toMarks.destinationEntity(), mark) - - # check the parent - toStore=emp.propertyNamed('toStore') - toMarks=emp.propertyNamed('toMarks') - check(self, toStore, toMarks, store, mark) - self.failIf(emp.propertyNamed('fkStore') not in toStore.sourceAttributes()) - self.failIf(store.propertyNamed('id') not in toStore.destinationAttributes()) - self.failIf(emp.propertyNamed('id') not in toMarks.sourceAttributes()) - self.failIf(mark.propertyNamed('fkEmployee') not in toMarks.destinationAttributes()) - - # Also check the sub-entity - toStore=sc.propertyNamed('toStore') - toMarks=sc.propertyNamed('toMarks') - check(self, toStore, toMarks, store, mark) - self.failIf(sc.propertyNamed('fkStore') not in toStore.sourceAttributes()) - self.failIf(store.propertyNamed('id') not in toStore.destinationAttributes()) - self.failIf(sc.propertyNamed('id') not in toMarks.sourceAttributes()) - self.failIf(mark.propertyNamed('fkEmployee') not in toMarks.destinationAttributes()) # test_06 qualified & unqualified --- 250,253 ---- *************** *** 256,292 **** # # NB: quid si inverse='ghjgh'? --> TBD test! # ] - - def check_model(self, model): - model.build() - emp=model.component.entityNamed('Employee') - sc=model.component.entityNamed('SalesClerk') - store=model.component.entityNamed('Store') - mark=model.component.entityNamed('Mark') - - self.checkEntitiesProperties((emp,sc,store,mark)) - - self.assertEqual(len(sc.relationships()), 2) - - def check(self, toStore, toMarks, store, mark): - self.failUnless(toStore.isToOne()) - self.failUnless(toMarks.isToMany()) - self.assertEqual(toStore.destinationEntity(), store) - self.assertEqual(toMarks.destinationEntity(), mark) - - toStore=emp.propertyNamed('toStore') - toMarks=emp.propertyNamed('toMarks') - check(self, toStore, toMarks, store, mark) - - toStore=sc.propertyNamed('toStore') - toMarks=sc.propertyNamed('toMarks') - check(self, toStore, toMarks, store, mark) - #### JUSQU'ICI on est pareil que test_04 - self.failUnless(mark.relationshipNamed('toEmployee').inverseRelationship()==emp.propertyNamed('toMarks')) - self.failUnless(store.relationshipNamed('toEmployees').inverseRelationship()==emp.propertyNamed('toStore')) def test_07_relationships_with_inverse(self): "[PyModel] qualified_relationships_with_inverse" ! model = self.model ! model.entities = [ Entity('Employee', properties=[ AForeignKey('fkStore'), --- 271,278 ---- # # NB: quid si inverse='ghjgh'? --> TBD test! # ] def test_07_relationships_with_inverse(self): "[PyModel] qualified_relationships_with_inverse" ! self.model.entities = [ Entity('Employee', properties=[ AForeignKey('fkStore'), *************** *** 307,312 **** # NB: quid si inverse='ghjgh'? --> TBD test! ] self.check_model(self.model) ! # self.setUp() --- 293,299 ---- # NB: quid si inverse='ghjgh'? --> TBD test! ] + self.model.build() self.check_model(self.model) ! self.check_inverse_rels(self.model) # self.setUp() *************** *** 324,330 **** --- 311,321 ---- ), ] + self.model.build() self.check_model(self.model) + self.check_inverse_rels(self.model) # Automatic creation of source + destination key + # NOTE: this fails by now, because the feature is considered not desirable + # for now. self.setUp() self.model.entities = [ *************** *** 341,349 **** ), ] #self.check_model(self.model) ! def test_08_qualified_relationships_with_inverse(self): "[PyModel] unqualified_relationships_with_inverse" model = self.model model.entities = [ --- 332,342 ---- ), ] + #self.model.build() #self.check_model(self.model) ! #self.check_inverse_rels(self.model) def test_08_qualified_relationships_with_inverse(self): "[PyModel] unqualified_relationships_with_inverse" + # Simple declaration model = self.model model.entities = [ *************** *** 357,365 **** Association('Mark', 'Employee'), ] self.check_model(self.model) def test_suite(): suite = unittest.TestSuite() ! suite.addTest(unittest.makeSuite(TestPyModel, "test_08")) return suite --- 350,361 ---- Association('Mark', 'Employee'), ] + model.build() self.check_model(self.model) + self.check_inverse_rels(self.model) + # def test_suite(): suite = unittest.TestSuite() ! suite.addTest(unittest.makeSuite(TestPyModel, "test_")) return suite |