MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_child_move

Method test_child_move

test/orm/test_unitofwork.py:1641–1685  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 = (

Callers

nothing calls this directly

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
UserClass · 0.70
AddressClass · 0.70
appendMethod · 0.45
add_allMethod · 0.45
flushMethod · 0.45
deleteMethod · 0.45
expunge_allMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected