(self)
| 1270 | assert a1.b_single is None |
| 1271 | |
| 1272 | def test_custom_getset(self): |
| 1273 | metadata = MetaData() |
| 1274 | p = Table( |
| 1275 | "p", |
| 1276 | metadata, |
| 1277 | Column("id", Integer, primary_key=True), |
| 1278 | Column("cid", Integer, ForeignKey("c.id")), |
| 1279 | ) |
| 1280 | c = Table( |
| 1281 | "c", |
| 1282 | metadata, |
| 1283 | Column("id", Integer, primary_key=True), |
| 1284 | Column("foo", String(128)), |
| 1285 | ) |
| 1286 | |
| 1287 | get = Mock() |
| 1288 | set_ = Mock() |
| 1289 | |
| 1290 | class Parent: |
| 1291 | foo = association_proxy( |
| 1292 | "child", "foo", getset_factory=lambda cc, parent: (get, set_) |
| 1293 | ) |
| 1294 | |
| 1295 | class Child: |
| 1296 | def __init__(self, foo): |
| 1297 | self.foo = foo |
| 1298 | |
| 1299 | self.mapper_registry.map_imperatively( |
| 1300 | Parent, p, properties={"child": relationship(Child)} |
| 1301 | ) |
| 1302 | self.mapper_registry.map_imperatively(Child, c) |
| 1303 | |
| 1304 | p1 = Parent() |
| 1305 | |
| 1306 | eq_(p1.foo, get(None)) |
| 1307 | p1.child = child = Child(foo="x") |
| 1308 | eq_(p1.foo, get(child)) |
| 1309 | p1.foo = "y" |
| 1310 | eq_(set_.mock_calls, [call(child, "y")]) |
| 1311 | |
| 1312 | |
| 1313 | class LazyLoadTest(fixtures.MappedTest): |
nothing calls this directly
no test coverage detected