[Modeling-cvs] ProjectModeling/Modeling/tests test_EditingContext_Global_Inheritance.py,1.16,1.17
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-07-28 06:15:19
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv5634/tests
Modified Files:
test_EditingContext_Global_Inheritance.py
Log Message:
Removed the constraint on to-many relationships for which an inverse to-one
relationship had to be defined.
Details: recordChangesInEditingContext() refactored,
recordUpdateForObject() implemented,
Index: test_EditingContext_Global_Inheritance.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/test_EditingContext_Global_Inheritance.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** test_EditingContext_Global_Inheritance.py 24 Jul 2003 11:30:52 -0000 1.16
--- test_EditingContext_Global_Inheritance.py 28 Jul 2003 06:15:16 -0000 1.17
***************
*** 55,58 ****
--- 55,59 ----
from StoreEmployees.Executive import Executive
from StoreEmployees.Address import Address
+ from StoreEmployees.Holidays import Holidays
***************
*** 61,65 ****
def test_01_objectsWithFetchSpecification(self):
! "[EditingContext/Inheritance] objectsWithFetchSpecification"
ec=EditingContext()
fetchSpec=FetchSpecification(entityName='Employee', deepFlag=0)
--- 62,66 ----
def test_01_objectsWithFetchSpecification(self):
! "[EC/Inheritance] objectsWithFetchSpecification"
ec=EditingContext()
fetchSpec=FetchSpecification(entityName='Employee', deepFlag=0)
***************
*** 73,77 ****
def test_02_toOneFault(self):
! "[EditingContext/Inheritance] toOneFault"
ec=EditingContext()
qual=qualifierWithQualifierFormat('street like "2,*"')
--- 74,78 ----
def test_02_toOneFault(self):
! "[EC/Inheritance] toOneFault"
ec=EditingContext()
qual=qualifierWithQualifierFormat('street like "2,*"')
***************
*** 92,96 ****
def test_03_toOneFault_notifications(self):
! "[EditingContext/Inheritance] toOneFault/GlobalIDChangedNotification"
ec1=EditingContext()
ec2=EditingContext()
--- 93,97 ----
def test_03_toOneFault_notifications(self):
! "[EC/Inheritance] toOneFault/GlobalIDChangedNotification"
ec1=EditingContext()
ec2=EditingContext()
***************
*** 152,156 ****
def test_04_validation(self):
! "[EditingContext/Inheritance] test Validation"
ec=EditingContext()
qual=qualifierWithQualifierFormat('street like "2,*"')
--- 153,157 ----
def test_04_validation(self):
! "[EC/Inheritance] test Validation"
ec=EditingContext()
qual=qualifierWithQualifierFormat('street like "2,*"')
***************
*** 166,170 ****
def test_05_toOneFault_uniquing(self):
! "[EditingContext/Inheritance] Tests that toFaults are also unique within a ec"
ec=EditingContext()
# get address for John Cleese
--- 167,171 ----
def test_05_toOneFault_uniquing(self):
! "[EC/Inheritance] Tests that toFaults are also unique within a ec"
ec=EditingContext()
# get address for John Cleese
***************
*** 189,193 ****
def test_05b_toOneFault_uniquing(self):
! "[EditingContext/Inheritance] Tests unicity for toOne-related objects when they are already fetched"
## In this test we make sure that, after an object has been fetched,
## any other object pointing to it do not get a to-one fault, but the
--- 190,194 ----
def test_05b_toOneFault_uniquing(self):
! "[EC/Inheritance] Tests unicity for toOne-related objects when they are already fetched"
## In this test we make sure that, after an object has been fetched,
## any other object pointing to it do not get a to-one fault, but the
***************
*** 248,252 ****
def test_06_objectsCountWithFetchSpecification(self):
! "[EditingContext/Inheritance] objectsCountWithFetchSpecification"
ec=EditingContext()
fs=FetchSpecification(entityName='Employee')
--- 249,253 ----
def test_06_objectsCountWithFetchSpecification(self):
! "[EC/Inheritance] objectsCountWithFetchSpecification"
ec=EditingContext()
fs=FetchSpecification(entityName='Employee')
***************
*** 260,264 ****
def test_07_fetch_shouldnt_change_FetchSpecification(self):
! "[EditingContext/Inheritance] fetching shouldn't change FetchSpecification"
# Bug #753147
from StoreEmployees import Address
--- 261,265 ----
def test_07_fetch_shouldnt_change_FetchSpecification(self):
! "[EC/Inheritance] fetching shouldn't change FetchSpecification"
# Bug #753147
from StoreEmployees import Address
***************
*** 277,281 ****
def test_08a_fetchesRawRows(self):
! "[EditingContext/Inheritance] fetchesRawRows / basics"
ec=EditingContext()
--- 278,282 ----
def test_08a_fetchesRawRows(self):
! "[EC/Inheritance] fetchesRawRows / basics"
ec=EditingContext()
***************
*** 302,306 ****
def test_08b_fetchesRawRows(self):
! "[EditingContext/Inheritance] fetchesRawRows / inserted & deleted objects"
ec=EditingContext()
--- 303,307 ----
def test_08b_fetchesRawRows(self):
! "[EC/Inheritance] fetchesRawRows / inserted & deleted objects"
ec=EditingContext()
***************
*** 335,339 ****
def test_09_faultForRawRow(self):
! "[EditingContext/Inheritance] faultForRawRow"
ec=EditingContext()
employees=ec.fetch('Employee', isDeep=1, rawRows=1)
--- 336,340 ----
def test_09_faultForRawRow(self):
! "[EC/Inheritance] faultForRawRow"
ec=EditingContext()
employees=ec.fetch('Employee', isDeep=1, rawRows=1)
***************
*** 368,371 ****
--- 369,637 ----
## TBD: CHECK FOR TEMPORARY/INSERTED
+
+ def test_10_toMany_no_inverse__db_snapshot_is_correct(self):
+ "[EC/Inheritance] toMany w/o inverse: check db snapshot"
+ # We check here that a database snapshot for an object being pointed to
+ # by a toMany relationship with no inverse correctly contains its FK
+ ec=EditingContext()
+ holidays=Holidays()
+ from mx.DateTime import DateFrom
+ holidays.setStartDate(DateFrom('2003-07-01 08:00'))
+ holidays.setEndDate(DateFrom('2003-08-01 08:00'))
+ ec.insert(holidays)
+ ec.saveChanges()
+
+ database=ec.rootObjectStore().objectStoreForObject(holidays).database()
+ snap=database.snapshotForGlobalID(holidays.globalID())
+ self.failIf(not snap.has_key('fkEmployeeId'))
+
+ ## ToMany with no inverse:
+ # test10 / insertion:
+ # [a] insert (h.+emp.) + emp.addToHolidays + saveChges
+ # [b] insert h. + saveChges + emp.addToHolidays + saveChges
+ # [c] insert h.+ emp.addToHolidays + saveChges
+ # [d] insert h.+ saveChges + emp.addToHolidays + h.setStartDate + saveChges
+ # [e] insert h. + saveChges + insert emp. + emp.addToHolidays + saveChanges
+ #
+ # test11 / remove:
+ # [a] remove simple
+ # [b] add h1 + remove h2
+ # [c] remove (+ implicit delete w/ cascade rule) emp.
+
+ def _test_10_create_emp_n_holidays(self):
+ """
+ helper function for tests test_10...: return (employee, holidays), brand
+ new instances of Employee/Holidays.
+ """
+ emp=Employee.Employee()
+ emp.setLastName('Test'); emp.setFirstName('T.')
+ from mx.DateTime import DateFrom
+ holidays=Holidays()
+ holidays.setStartDate(DateFrom('2003-07-01 08:00'))
+ holidays.setEndDate(DateFrom('2003-08-01 08:00'))
+ return emp, holidays
+
+ def _test_10_check_insert_correctness_part1(self, ec, emp, holidays):
+ emp_gid=emp.globalID()
+ holidays_gid=holidays.globalID()
+ db=ec.rootObjectStore().objectStoreForObject(emp).database()
+
+ self.failUnless(holidays_gid)
+ self.failIf(not db.snapshotForGlobalID(holidays_gid))
+ self.failIf(not db.snapshotForGlobalID(holidays_gid).has_key('fkEmployeeId'))
+ self.assertEqual(db.snapshotForGlobalID(holidays_gid)['fkEmployeeId'],
+ emp_gid.keyValues()['id'])
+ self.failUnless(db.snapshotForSourceGlobalID(emp.globalID(), 'holidays'))
+ return emp_gid, db
+
+ def _test_10_check_insert_correctness_part2(self, emp_gid, database):
+ ""
+ # Now check that it was correctly saved. If 'holidays' was not correctly
+ # saved, it hasn't get the right value for its FK and we won't retrieve
+ # any holidays for the test employee
+
+ # make sure we won't get informations from the db cache
+ self.failIf(database.snapshotForSourceGlobalID(emp_gid, 'holidays'))
+
+ ec2=EditingContext()
+ emp2=ec2.fetch('Employee')[0]
+ self.failIf(len(emp2.getHolidays())==0)
+
+ def test_10a_toMany_with_no_inverse(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/a]"
+ # insert (h.+emp) + emp.addToHolidays + saveChanges
+ ec=EditingContext()
+ emp, holidays=self._test_10_create_emp_n_holidays()
+ ec.insert(emp)
+ ec.insert(holidays)
+ emp.addToHolidays(holidays)
+ ec.saveChanges()
+
+ emp_gid, db=self._test_10_check_insert_correctness_part1(ec, emp, holidays)
+ del ec # deleting the ec invalidates the database's cache
+ self._test_10_check_insert_correctness_part2(emp_gid, db)
+
+ def test_10b_toMany_with_no_inverse(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/b]"
+ # insert h. + saveChanges + emp.addToHolidays + saveChanges
+ ec=EditingContext()
+ emp, holidays=self._test_10_create_emp_n_holidays()
+ emp_gid=emp.globalID()
+ ec.insert(emp)
+ ec.saveChanges()
+
+ ec.insert(holidays)
+ ec.saveChanges()
+
+ emp.addToHolidays(holidays)
+ #emp.setLastName('fdsk')
+ ec.saveChanges()
+
+ emp_gid, db=self._test_10_check_insert_correctness_part1(ec, emp, holidays)
+ del ec # deleting the ec invalidates the database's cache
+ self._test_10_check_insert_correctness_part2(emp_gid, db)
+
+ def test_10c_toMany_with_no_inverse(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/c]"
+ # insert h. + emp.addToHolidays + saveChanges
+ ec=EditingContext()
+ emp, holidays=self._test_10_create_emp_n_holidays()
+ ec.insert(emp)
+ ec.saveChanges()
+
+ ec.insert(holidays)
+ emp.addToHolidays(holidays)
+ ec.saveChanges()
+
+ emp_gid, db=self._test_10_check_insert_correctness_part1(ec, emp, holidays)
+ del ec # deleting the ec invalidates the database's cache
+ self._test_10_check_insert_correctness_part2(emp_gid, db)
+
+ def test_10d_toMany_with_no_inverse(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/d]"
+ #insert h. + saveChanges + emp.addToHolidays + h.setStartDate + saveChanges
+ ec=EditingContext()
+ emp, holidays=self._test_10_create_emp_n_holidays()
+ ec.insert(emp)
+ ec.saveChanges()
+
+ ec.insert(holidays)
+ ec.saveChanges()
+
+ emp.addToHolidays(holidays)
+ from mx.DateTime import DateFrom
+ holidays.setStartDate(DateFrom('2003-07-02 08:00'))
+ ec.saveChanges()
+
+ emp_gid, db=self._test_10_check_insert_correctness_part1(ec, emp, holidays)
+ del ec # deleting the ec invalidates the database's cache
+ self._test_10_check_insert_correctness_part2(emp_gid, db)
+
+ def test_10e_toMany_with_no_inverse(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/e]"
+ # insert h. + save + insert emp. + emp.addToHolidays + saveChanges
+ ec=EditingContext()
+ emp, holidays=self._test_10_create_emp_n_holidays()
+ ec.insert(holidays)
+ ec.saveChanges()
+
+ ec.insert(emp)
+ emp.addToHolidays(holidays)
+ ec.saveChanges()
+
+ emp_gid, db=self._test_10_check_insert_correctness_part1(ec, emp, holidays)
+ del ec # deleting the ec invalidates the database's cache
+ self._test_10_check_insert_correctness_part2(emp_gid, db)
+
+ def _test_11a_init_emp_and_holidays(self, ec):
+ emp=Employee.Employee()
+ emp.setLastName('Test'); emp.setFirstName('T.')
+ from mx.DateTime import DateFrom
+ holidays=Holidays()
+ holidays.setStartDate(DateFrom('2003-07-01 08:00'))
+ holidays.setEndDate(DateFrom('2003-08-01 08:00'))
+ ec.insert(emp)
+ ec.insert(holidays)
+ emp.addToHolidays(holidays)
+ ec.saveChanges()
+ return emp, holidays
+
+ def test_11a_toMany_with_no_inverse__remove(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [remove/a]"
+ # remove simple
+ ec=EditingContext()
+ emp, holidays=self._test_11a_init_emp_and_holidays(ec)
+
+ emp.removeFromHolidays(holidays)
+ ec.saveChanges()
+
+ emp_gid=emp.globalID()
+ h_gid=holidays.globalID()
+ db=ec.rootObjectStore().objectStoreForObject(emp).database()
+ self.failUnless(db.snapshotForGlobalID(h_gid)['fkEmployeeId'] is None)
+ del ec
+
+ # make sure we won't get informations from the db cache
+ self.failIf(db.snapshotForSourceGlobalID(emp_gid, 'holidays'))
+ ec2=EditingContext()
+ emp2=ec2.fetch('Employee')[0]
+ self.failIf(len(emp2.getHolidays())!=0)
+
+ def test_11b_toMany_with_no_inverse__remove(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/b]"
+ # remove + add
+ ec=EditingContext()
+ emp, holidays=self._test_11a_init_emp_and_holidays(ec)
+
+ emp.removeFromHolidays(holidays)
+ h2=Holidays()
+ from mx.DateTime import DateFrom
+ sd2=DateFrom('2003-01-01 01:00')
+ ed2=DateFrom('2003-02-02 02:00')
+ h2.setStartDate(sd2)
+ h2.setEndDate(ed2)
+ ec.insert(h2)
+ emp.addToHolidays(h2)
+ ec.saveChanges()
+
+ emp_gid=emp.globalID()
+ h_gid=holidays.globalID()
+ db=ec.rootObjectStore().objectStoreForObject(emp).database()
+ self.failUnless(db.snapshotForGlobalID(h_gid)['fkEmployeeId'] is None)
+ del ec
+
+ # make sure we won't get informations from the db cache
+ self.failIf(db.snapshotForSourceGlobalID(emp_gid, 'holidays'))
+ ec2=EditingContext()
+ emp2=ec2.fetch('Employee')[0]
+ self.assertEqual(len(emp2.getHolidays()), 1)
+ h2b=emp2.getHolidays()[0]
+ self.assertEqual(sd2, h2b.getStartDate())
+ self.assertEqual(ed2, h2b.getEndDate())
+ #print db.snapshotForGlobalID(h_gid)
+
+ def test_11c_toMany_with_no_inverse__remove(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly updated [insert/c]"
+ # remove + add
+ ec=EditingContext()
+ emp, holidays=self._test_11a_init_emp_and_holidays(ec)
+
+ emp.removeFromHolidays(holidays)
+ ec.delete(emp)
+ ec.saveChanges()
+
+ db=ec.rootObjectStore().objectStoreForObject(holidays).database()
+ h_gid=holidays.globalID()
+ del ec
+
+ ec2=EditingContext()
+ h2=ec2.fetch('Holidays')[0]
+ #print db.snapshotForGlobalID(h_gid)
+ self.failIf(db.snapshotForGlobalID(h_gid)['fkEmployeeId']!=None)
+
+ def test_12_toMany_with_no_inverse__correct_fetch(self):
+ "[EC/Inheritance] toMany w/o inverse: obj. correctly fetched"
+ ec=EditingContext()
+ emp, holidays=self._test_11a_init_emp_and_holidays(ec)
+ db=ec.rootObjectStore().objectStoreForObject(holidays).database()
+ h_gid=holidays.globalID()
+ del ec
+ ec2=EditingContext()
+ h2=ec2.fetch('Holidays')[0]
+ self.failIf(db.snapshotForGlobalID(h_gid)['fkEmployeeId']==None)
+
+ def test_13_toMany_with_no_inverse__snapshot_row(self):
+ "[EC/Inheritance] toMany w/o inverse: obj.snapshot_raw()"
+ ec=EditingContext()
+ emp, holidays=self._test_10_create_emp_n_holidays()
+ ec.insert(emp)
+ ec.insert(holidays)
+ emp.addToHolidays(holidays)
+
+ # Not computed before saveChanges()
+ self.assertEqual(holidays.snapshot_raw()['fkEmployeeId'], None)
+ ec.saveChanges()
+ self.assertEqual(holidays.snapshot_raw()['fkEmployeeId'],
+ emp.globalID().keyValues()['id'])
def tearDown(self):
***************
*** 387,390 ****
--- 653,660 ----
sqlExpr.setStatement("delete from ADDRESS where id>3")
channel.evaluateExpression(sqlExpr)
+ sqlExpr.setStatement("delete from EMPLOYEE")
+ channel.evaluateExpression(sqlExpr)
+ sqlExpr.setStatement("delete from HOLIDAYS")
+ channel.evaluateExpression(sqlExpr)
***************
*** 536,539 ****
--- 806,814 ----
model=ModelSet.defaultModelSet().modelNamed('StoreEmployees')
Model.updateModelWithCFG(model, database_cfg)
+
+ # MySQL specifics: change TIMESTAMP to DATETIME
+ if database_cfg=='MySQL.cfg':
+ model.entityNamed('Holidays').attributeNamed('startDate').setExternalType('DATETIME')
+ model.entityNamed('Holidays').attributeNamed('endDate').setExternalType('DATETIME')
utils.enable_model_cache_and_compute()
|