MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_attribute_cascade

Method test_attribute_cascade

test/orm/test_merge.py:618–761  ·  view source on GitHub ↗

Merge of a persistent entity with two child persistent entities.

(self)

Source from the content-addressed store, hash-verified

616 assert list(u1.addresses.keys()) == ["foo@bar.com"]
617
618 def test_attribute_cascade(self):
619 """Merge of a persistent entity with two child
620 persistent entities."""
621
622 users, Address, addresses, User = (
623 self.tables.users,
624 self.classes.Address,
625 self.tables.addresses,
626 self.classes.User,
627 )
628
629 self.mapper_registry.map_imperatively(
630 User,
631 users,
632 properties={
633 "addresses": relationship(
634 self.mapper_registry.map_imperatively(Address, addresses),
635 backref="user",
636 )
637 },
638 )
639 load = self.load_tracker(User)
640 self.load_tracker(Address, load)
641
642 with fixture_session(expire_on_commit=False) as sess, sess.begin():
643 # set up data and save
644 u = User(
645 id=7,
646 name="fred",
647 addresses=[
648 Address(email_address="foo@bar.com"),
649 Address(email_address="hoho@la.com"),
650 ],
651 )
652 sess.add(u)
653
654 # assert data was saved
655 sess2 = fixture_session()
656 u2 = sess2.get(User, 7)
657 eq_(
658 u2,
659 User(
660 id=7,
661 name="fred",
662 addresses=[
663 Address(email_address="foo@bar.com"),
664 Address(email_address="hoho@la.com"),
665 ],
666 ),
667 )
668
669 # make local changes to data
670 u.name = "fred2"
671 u.addresses[1].email_address = "hoho@lalala.com"
672
673 eq_(load.called, 3)
674
675 # new session, merge modified data into session

Callers

nothing calls this directly

Calls 13

load_trackerMethod · 0.95
relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
assert_sql_countMethod · 0.80
UserClass · 0.70
AddressClass · 0.70
beginMethod · 0.45
addMethod · 0.45
getMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected