Moving a child from one parent to another, with a delete. Tests that deleting the first parent properly updates the child with the new parent. This tests the 'trackparent' option in the attributes module.
(self)
| 1639 | ) |
| 1640 | |
| 1641 | def test_child_move(self): |
| 1642 | """Moving a child from one parent to another, with a delete. |
| 1643 | |
| 1644 | Tests that deleting the first parent properly updates the child with |
| 1645 | the new parent. This tests the 'trackparent' option in the attributes |
| 1646 | module. |
| 1647 | |
| 1648 | """ |
| 1649 | |
| 1650 | Address, addresses, users, User = ( |
| 1651 | self.classes.Address, |
| 1652 | self.tables.addresses, |
| 1653 | self.tables.users, |
| 1654 | self.classes.User, |
| 1655 | ) |
| 1656 | |
| 1657 | self.mapper_registry.map_imperatively( |
| 1658 | User, |
| 1659 | users, |
| 1660 | properties=dict( |
| 1661 | addresses=relationship( |
| 1662 | self.mapper_registry.map_imperatively(Address, addresses), |
| 1663 | lazy="select", |
| 1664 | ) |
| 1665 | ), |
| 1666 | ) |
| 1667 | |
| 1668 | u1 = User(name="user1") |
| 1669 | u2 = User(name="user2") |
| 1670 | a = Address(email_address="address1") |
| 1671 | u1.addresses.append(a) |
| 1672 | |
| 1673 | session = fixture_session() |
| 1674 | session.add_all((u1, u2)) |
| 1675 | session.flush() |
| 1676 | |
| 1677 | del u1.addresses[0] |
| 1678 | u2.addresses.append(a) |
| 1679 | session.delete(u1) |
| 1680 | |
| 1681 | session.flush() |
| 1682 | session.expunge_all() |
| 1683 | |
| 1684 | u2 = session.get(User, u2.id) |
| 1685 | eq_(len(u2.addresses), 1) |
| 1686 | |
| 1687 | def test_child_move_2(self): |
| 1688 | Address, addresses, users, User = ( |
nothing calls this directly
no test coverage detected