test that the supplied 'dict' wrapper can be used as a collection and can lazyload.
(self)
| 2459 | f.bars.clear() |
| 2460 | |
| 2461 | def test_dict_wrapper(self): |
| 2462 | """test that the supplied 'dict' wrapper can be used as a |
| 2463 | collection and can lazyload.""" |
| 2464 | |
| 2465 | someothertable, sometable = ( |
| 2466 | self.tables.someothertable, |
| 2467 | self.tables.sometable, |
| 2468 | ) |
| 2469 | |
| 2470 | class Foo: |
| 2471 | pass |
| 2472 | |
| 2473 | class Bar: |
| 2474 | def __init__(self, data): |
| 2475 | self.data = data |
| 2476 | |
| 2477 | self.mapper_registry.map_imperatively( |
| 2478 | Foo, |
| 2479 | sometable, |
| 2480 | properties={ |
| 2481 | "bars": relationship( |
| 2482 | Bar, |
| 2483 | collection_class=collections.column_keyed_dict( |
| 2484 | someothertable.c.data |
| 2485 | ), |
| 2486 | ) |
| 2487 | }, |
| 2488 | ) |
| 2489 | self.mapper_registry.map_imperatively(Bar, someothertable) |
| 2490 | |
| 2491 | f = Foo() |
| 2492 | col = collections.collection_adapter(f.bars) |
| 2493 | col.append_with_event(Bar("a")) |
| 2494 | col.append_with_event(Bar("b")) |
| 2495 | sess = fixture_session() |
| 2496 | sess.add(f) |
| 2497 | sess.flush() |
| 2498 | sess.expunge_all() |
| 2499 | f = sess.get(Foo, f.col1) |
| 2500 | assert len(list(f.bars)) == 2 |
| 2501 | |
| 2502 | strongref = list(f.bars.values()) |
| 2503 | existing = {id(b) for b in strongref} |
| 2504 | |
| 2505 | col = collections.collection_adapter(f.bars) |
| 2506 | col.append_with_event(Bar("b")) |
| 2507 | f.bars["a"] = Bar("a") |
| 2508 | sess.flush() |
| 2509 | sess.expunge_all() |
| 2510 | f = sess.get(Foo, f.col1) |
| 2511 | assert len(list(f.bars)) == 2 |
| 2512 | |
| 2513 | replaced = {id(b) for b in list(f.bars.values())} |
| 2514 | ne_(existing, replaced) |
| 2515 | |
| 2516 | @testing.combinations("direct", "as_callable", argnames="factory_type") |
| 2517 | def test_list(self, factory_type): |
nothing calls this directly
no test coverage detected