Thread: [Modeling-cvs] ProjectModeling/Modeling/tests test_EditingContext_Global_Inheritance.py,1.14,1.15 te
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-07-16 19:16:03
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv30582/tests
Modified Files:
test_EditingContext_Global_Inheritance.py
test_EditingContext_ParentChild.py
Log Message:
Added the ability to fetch raw rows (dictionaries instead of fully
intialized objects) --see FetchSpecification.setFetchesRawRows() and
EditingContext.fetch() 's parameter 'rawRows'. Also added the possibility
to turn these rows into real objects --see EditingContext.faultForRawRow()
Index: test_EditingContext_Global_Inheritance.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/test_EditingContext_Global_Inheritance.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_EditingContext_Global_Inheritance.py 15 Jul 2003 11:07:10 -0000 1.14
--- test_EditingContext_Global_Inheritance.py 16 Jul 2003 19:16:00 -0000 1.15
***************
*** 52,55 ****
--- 52,56 ----
from StoreEmployees import Employee
from StoreEmployees.SalesClerk import SalesClerk
+ from StoreEmployees.Executive import Executive
from StoreEmployees.Address import Address
***************
*** 274,277 ****
--- 275,371 ----
self.failIf(len(objs2)!=3)
+ def test_08a_fetchesRawRows(self):
+ "[EditingContext/Inheritance] fetchesRawRows / basics"
+ ec=EditingContext()
+
+ # No inheritance
+ addresses=ec.fetch('Address', rawRows=1)
+ self.failIf(len(addresses)!=3)
+ for a in addresses:
+ self.failIf(type(a) is not type({}))
+
+ # Inheritance
+ employees=ec.fetch('Employee', isDeep=1, rawRows=1)
+ self.failIf(len(employees)!=3)
+ for e in employees:
+ self.failIf(type(e) is not type({}))
+
+ # modified objects
+ john=ec.fetch('Executive', 'lastName == "Cleese"')[0]
+ john_gid=john.globalID()
+ john_name=john.getLastName()
+ alternate_john_name=john_name+' -- testing'
+ john.setLastName(alternate_john_name)
+ john=ec.fetch('Executive', isDeep=1, rawRows=1)[0]
+ self.assertEqual(john['lastName'], alternate_john_name)
+
+ def test_08b_fetchesRawRows(self):
+ "[EditingContext/Inheritance] fetchesRawRows / inserted & deleted objects"
+ ec=EditingContext()
+
+ # Inserted objects should appear, as expected
+ nsc=SalesClerk()
+ nsc.setLastName('New SC')
+ ne=Executive()
+ ne.setLastName('New Executive')
+ ec.insert(nsc)
+ ec.insert(ne)
+ employees=ec.fetch('Employee', isDeep=1, rawRows=1)
+ self.assertEqual(len(employees), 5)
+ rnsc=rne=None # returned nsc/ne
+ for e in employees:
+ self.assertEqual(type(e), type({}))
+
+ # deletedObjects should not appear
+ ec.delete(nsc)
+ jeanne=ec.fetch('SalesClerk', 'firstName=="Jeanne"')[0]
+ ec.deleteObject(jeanne)
+ employees=ec.fetch('Employee', isDeep=1, rawRows=1)
+ self.assertEqual(len(employees), 3)
+ rnsc=rne=rjeanne=None # returned nsc/ne
+ for e in employees:
+ self.assertEqual(type(e), type({}))
+ if e['lastName']==nsc.getLastName(): rnsc=e
+ if e['lastName']==ne.getLastName(): rne=e
+ if e['firstName']==jeanne.getFirstName(): rjeanne=e
+ self.assertEqual(rnsc, None)
+ self.assertEqual(rjeanne, None)
+ self.assertEqual(rne, ne.snapshot_raw())
+
+ def test_09_faultForRawRow(self):
+ "[EditingContext/Inheritance] faultForRawRow"
+ ec=EditingContext()
+ employees=ec.fetch('Employee', isDeep=1, rawRows=1)
+ r_executives=[]
+ r_sales_clerks=[]
+ for e in employees:
+ if e.has_key('officeLocation'):
+ r_executives.append(e)
+ else:
+ r_sales_clerks.append(e)
+ self.failIf(len(r_executives)!=1)
+ self.failIf(len(r_sales_clerks)!=2)
+
+ r_john_c=r_executives[0]
+ john_c1=ec.faultForRawRow(r_john_c, 'Employee')
+ john_c2=ec.faultForRawRow(r_john_c, 'Executive')
+ self.failUnless(john_c1.isFault())
+ self.failUnless(john_c1==john_c2)
+ john_c3=ec.fetch('Employee', 'firstName=="John" AND lastName=="Cleese"',
+ isDeep=1)[0]
+ self.failUnless(john_c2==john_c3)
+ john_c3.getFirstName()
+ self.failIf(john_c1.isFault())
+
+ # Anything in the correct inheritance tree return the right object
+ john_c4=ec.faultForRawRow(r_john_c, 'SalesClerk')
+ self.failUnless(john_c1==john_c4)
+
+ # Check that it correctly raise when 'pk' is not present
+ self.assertRaises(ValueError,
+ ec.faultForRawRow, {'incorrect':0}, 'Employee')
+
+ ## TBD: CHECK FOR TEMPORARY/INSERTED
+
def tearDown(self):
"""
Index: test_EditingContext_ParentChild.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/test_EditingContext_ParentChild.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** test_EditingContext_ParentChild.py 7 Jul 2003 14:57:14 -0000 1.9
--- test_EditingContext_ParentChild.py 16 Jul 2003 19:16:00 -0000 1.10
***************
*** 470,473 ****
--- 470,587 ----
'obj.W/FetchSpec() should not have returned John Cleese')
+ def test_12a_fetchesRawRows(self):
+ "[EC:parent/child] fetchesRawRows / basics"
+ ## Basically the same test than
+ ## test_EC_Global_Inheritance.test_08a_fetchesRawRows()
+ ## except for the part on modified objects (modified in parent EC here)
+ parent_ec=EditingContext()
+ child_ec=EditingContext(parent_ec)
+
+ # No inheritance
+ addresses=child_ec.fetch('Address', rawRows=1)
+ self.failIf(len(addresses)!=3)
+ for a in addresses:
+ self.failIf(type(a) is not type({}))
+
+ # Inheritance
+ employees=child_ec.fetch('Employee', isDeep=1, rawRows=1)
+ self.failIf(len(employees)!=3)
+ for e in employees:
+ self.failIf(type(e) is not type({}))
+
+ # modified objects in parent
+ pjohn=ec.fetch('Executive', 'lastName == "Cleese"')[0]
+ pjohn_gid=john.globalID()
+ john_name=pjohn.getLastName()
+ alternate_john_name=john_name+' -- testing'
+ pjohn.setLastName(alternate_john_name)
+ pjohn=ec.fetch('Executive', isDeep=1, rawRows=1)[0]
+ self.assertEqual(john['lastName'], alternate_john_name)
+
+ def test_12b_fetchesRawRows(self):
+ "[EC:parent/child] fetchesRawRows / inserted & deleted objects"
+ from StoreEmployees.SalesClerk import SalesClerk
+ from StoreEmployees.Executive import Executive
+
+ parent_ec=EditingContext()
+ child_ec=EditingContext(parent_ec)
+
+ # Inserted objects (either in parent or in child) should appear,
+ # as expected
+ nsc=SalesClerk()
+ nsc.setLastName('New SC')
+ ne=Executive()
+ ne.setLastName('New Executive')
+ parent_ec.insert(nsc)
+ child_ec.insert(ne)
+ employees=child_ec.fetch('Employee', isDeep=1, rawRows=1)
+ self.assertEqual(len(employees), 5)
+ rnsc=rne=None # returned nsc/ne
+ for e in employees:
+ self.assertEqual(type(e), type({}))
+
+ parent_ec.delete(nsc) # clean-up
+
+ # deletedObjects (either in parent or in child) should not appear
+ # Note: we left: 'ne' in the parent
+ jeanne=child_ec.fetch('SalesClerk', 'firstName=="Jeanne"')[0]
+ child_ec.deleteObject(jeanne)
+ john_jr=parent_ec.fetch('SalesClerk', 'firstName=="John Jr."')[0]
+ john=parent_ec.fetch('Executive', 'firstName=="John"')[0]
+ parent_ec.deleteObject(john_jr)
+
+ employees=child_ec.fetch('Employee', isDeep=1, rawRows=1)
+ self.assertEqual(len(employees), 2)
+ rnsc=rne=rjeanne=rjohn_jr=rjohn=None # returned nsc/ne
+ for e in employees:
+ self.assertEqual(type(e), type({}))
+ if e['lastName']==nsc.getLastName(): rnsc=e
+ if e['lastName']==ne.getLastName(): rne=e
+ if e['firstName']==jeanne.getFirstName(): rjeanne=e
+ if e['firstName']==john_jr.getFirstName(): rjohn_jr=e
+ if e['firstName']==john.getFirstName(): rjohn=e
+ self.assertEqual(rnsc, None)
+ self.assertEqual(rjeanne, None)
+ self.assertEqual(rjohn_jr, None)
+ self.assertEqual(rne, ne.snapshot_raw())
+ self.assertEqual(rjohn, john.snapshot_raw())
+
+
+ def test_13_faultForRawRow(self):
+ "[EC:parent/child] faultForRawRow"
+ parent_ec=EditingContext()
+ child_ec=EditingContext(parent_ec)
+
+ employees=child_ec.fetch('Employee', isDeep=1, rawRows=1)
+ r_executives=[]
+ r_sales_clerks=[]
+ for e in employees:
+ if e.has_key('officeLocation'):
+ r_executives.append(e)
+ else:
+ r_sales_clerks.append(e)
+ self.failIf(len(r_executives)!=1)
+ self.failIf(len(r_sales_clerks)!=2)
+
+ r_john_c=r_executives[0]
+ john_c1=child_ec.faultForRawRow(r_john_c, 'Employee')
+ john_c2=child_ec.faultForRawRow(r_john_c, 'Executive')
+ self.failUnless(john_c1.isFault())
+ self.failUnless(john_c1==john_c2)
+ john_c3=child_ec.fetch('Employee',
+ 'firstName=="John" AND lastName=="Cleese"',
+ isDeep=1)[0]
+ self.failUnless(john_c2==john_c3)
+ john_c3.getFirstName()
+ self.failIf(john_c1.isFault())
+
+ # Anything in the correct inheritance tree return the right object
+ john_c4=child_ec.faultForRawRow(r_john_c, 'SalesClerk')
+ self.failUnless(john_c1==john_c4)
+
+ # Last, check that it correctly raise when 'pk' is not present
+ self.assertRaises(ValueError,
+ child_ec.faultForRawRow, {'incorrect':0}, 'Employee')
+
def tearDown(self):
"""
|