MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_mapped_binds

Method test_mapped_binds

test/orm/test_bind.py:38–93  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

36 run_inserts = None
37
38 def test_mapped_binds(self):
39 Address, addresses, users, User = (
40 self.classes.Address,
41 self.tables.addresses,
42 self.tables.users,
43 self.classes.User,
44 )
45
46 # ensure tables are unbound
47 m2 = sa.MetaData()
48 users_unbound = users.to_metadata(m2)
49 addresses_unbound = addresses.to_metadata(m2)
50
51 self.mapper_registry.map_imperatively(Address, addresses_unbound)
52 self.mapper_registry.map_imperatively(
53 User,
54 users_unbound,
55 properties={
56 "addresses": relationship(
57 Address,
58 backref=backref("user", cascade="all"),
59 cascade="all",
60 )
61 },
62 )
63
64 sess = Session(binds={User: testing.db, Address: testing.db})
65
66 u1 = User(id=1, name="ed")
67 sess.add(u1)
68 eq_(
69 sess.query(User).filter(User.id == 1).all(),
70 [User(id=1, name="ed")],
71 )
72
73 # test expression binding
74
75 sess.execute(users_unbound.insert(), params=dict(id=2, name="jack"))
76 eq_(
77 sess.execute(
78 users_unbound.select().where(users_unbound.c.id == 2)
79 ).fetchall(),
80 [(2, "jack")],
81 )
82
83 eq_(
84 sess.execute(
85 users_unbound.select().where(User.id == 2)
86 ).fetchall(),
87 [(2, "jack")],
88 )
89
90 sess.execute(users_unbound.delete())
91 eq_(sess.execute(users_unbound.select()).fetchall(), [])
92
93 sess.close()
94
95 def test_table_binds(self):

Callers

nothing calls this directly

Calls 15

addMethod · 0.95
queryMethod · 0.95
executeMethod · 0.95
closeMethod · 0.95
relationshipFunction · 0.90
backrefFunction · 0.90
SessionClass · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
UserClass · 0.70
to_metadataMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected