| | 451 | |
|---|
| | 452 | def testChildren_moveParentRecordPointer(self): |
|---|
| | 453 | """Moving the parent record pointer shouldn't erase child changes.""" |
|---|
| | 454 | bizMain = self.biz |
|---|
| | 455 | bizChild = dabo.biz.dBizobj(self.con) |
|---|
| | 456 | bizChild.UserSQL = "select * from %s" % self.temp_child_table_name |
|---|
| | 457 | bizChild.KeyField = "pk" |
|---|
| | 458 | bizChild.DataSource = self.temp_child_table_name |
|---|
| | 459 | bizChild.LinkField = "parent_fk" |
|---|
| | 460 | bizChild.FillLinkFromParent = True |
|---|
| | 461 | |
|---|
| | 462 | bizMain.addChild(bizChild) |
|---|
| | 463 | bizMain.requery() |
|---|
| | 464 | |
|---|
| | 465 | # preliminary sanity checks: |
|---|
| | 466 | self.assertEqual(bizChild.RowCount, 2) |
|---|
| | 467 | bizChild.RowNumber = 1 |
|---|
| | 468 | bizMain.next() |
|---|
| | 469 | self.assertEqual(bizChild.RowCount, 0) |
|---|
| | 470 | bizMain.prior() |
|---|
| | 471 | self.assertEqual(bizChild.RowCount, 2) |
|---|
| | 472 | self.assertEqual(bizMain.RowNumber, 0) |
|---|
| | 473 | self.assertEqual(bizChild.RowNumber, 1) |
|---|
| | 474 | bizMain.RowNumber = 2 |
|---|
| | 475 | self.assertEqual(bizChild.RowNumber, 0) |
|---|
| | 476 | |
|---|
| | 477 | # We are in row 2 of main, and row 0 of child |
|---|
| | 478 | |
|---|
| | 479 | # Change a field, and test isChanged() both before and after moving the |
|---|
| | 480 | # parent record pointer: |
|---|
| | 481 | bizChild.Record.cInvNum = "pkm0023" |
|---|
| | 482 | self.assertEqual(bizChild._CurrentCursor._mementos, {3: {'cInvNum': u'IN00024'}}) |
|---|
| | 483 | self.assertEqual(bizChild.isChanged(), True) |
|---|
| | 484 | self.assertEqual(bizMain.isChanged(), True) |
|---|
| | 485 | |
|---|
| | 486 | # Prove no problem with simple change, and moving parent record pointer: |
|---|
| | 487 | bizMain.RowNumber = 2 |
|---|
| | 488 | self.assertEqual(bizChild.Record.cInvNum, "pkm0023") |
|---|
| | 489 | self.assertEqual(bizChild._CurrentCursor._mementos, {3: {'cInvNum': u'IN00024'}}) |
|---|
| | 490 | self.assertEqual(bizChild.isChanged(), True) |
|---|
| | 491 | self.assertEqual(bizMain.isChanged(), True) |
|---|
| | 492 | |
|---|
| | 493 | # Prove no problem with simple change, adding new record, and changing the |
|---|
| | 494 | # new record: the simple change is still there. |
|---|
| | 495 | bizChild.new() |
|---|
| | 496 | bizChild.Record.cInvNum = "pkm0024" |
|---|
| | 497 | self.assertEqual(bizChild.RowCount, 2) |
|---|
| | 498 | bizMain.RowNumber = 2 |
|---|
| | 499 | self.assertEqual(bizChild.isAnyChanged(), True) |
|---|
| | 500 | self.assertEqual(bizChild.RowCount, 2) |
|---|
| | 501 | self.assertEqual(bizChild.isChanged(), True) |
|---|
| | 502 | bizChild.RowNumber = 0 |
|---|
| | 503 | self.assertEqual(bizChild.isChanged(), True) |
|---|
| | 504 | self.assertEqual(bizChild._CurrentCursor._mementos, {3: {'cInvNum': u'IN00024'}, -1: {'cInvNum': u''}}) |
|---|
| | 505 | |
|---|
| | 506 | # Now, here's the problem. If we add a new record to the child but don't |
|---|
| | 507 | # change any fields in that new record, then move the main record pointer, |
|---|
| | 508 | # all child changes in other records will be lost, not just the blank |
|---|
| | 509 | # new record which gets removed due to Dabo's design. |
|---|
| | 510 | bizChild.new() |
|---|
| | 511 | self.assertEqual(bizChild.RowCount, 3) |
|---|
| | 512 | self.assertEqual(bizChild.isAnyChanged(), True) |
|---|
| | 513 | self.assertEqual(bizChild._CurrentCursor._mementos, {3: {'cInvNum': u'IN00024'}, -1: {'cInvNum': u''}, -1: {'cInvNum': u''}}) |
|---|
| | 514 | bizMain.RowNumber = 2 |
|---|
| | 515 | # boom! a simple record change in the parent removed the change to the first |
|---|
| | 516 | # record, the new record with a change, as well as the expected last new record |
|---|
| | 517 | # that had no changes: |
|---|
| | 518 | self.assertEqual(bizChild.isAnyChanged(), True) |
|---|
| | 519 | |
|---|
| | 520 | |
|---|