test that a 'dict' can be used as a collection and can lazyload.
(self)
| 2416 | f.bars.clear() |
| 2417 | |
| 2418 | def test_dict(self): |
| 2419 | """test that a 'dict' can be used as a collection and can lazyload.""" |
| 2420 | |
| 2421 | someothertable, sometable = ( |
| 2422 | self.tables.someothertable, |
| 2423 | self.tables.sometable, |
| 2424 | ) |
| 2425 | |
| 2426 | class Foo: |
| 2427 | pass |
| 2428 | |
| 2429 | class Bar: |
| 2430 | pass |
| 2431 | |
| 2432 | class AppenderDict(dict): |
| 2433 | @collection.appender |
| 2434 | def set(self, item): |
| 2435 | self[id(item)] = item |
| 2436 | |
| 2437 | @collection.remover |
| 2438 | def remove(self, item): |
| 2439 | if id(item) in self: |
| 2440 | del self[id(item)] |
| 2441 | |
| 2442 | self.mapper_registry.map_imperatively( |
| 2443 | Foo, |
| 2444 | sometable, |
| 2445 | properties={ |
| 2446 | "bars": relationship(Bar, collection_class=AppenderDict) |
| 2447 | }, |
| 2448 | ) |
| 2449 | self.mapper_registry.map_imperatively(Bar, someothertable) |
| 2450 | f = Foo() |
| 2451 | f.bars.set(Bar()) |
| 2452 | f.bars.set(Bar()) |
| 2453 | sess = fixture_session() |
| 2454 | sess.add(f) |
| 2455 | sess.flush() |
| 2456 | sess.expunge_all() |
| 2457 | f = sess.get(Foo, f.col1) |
| 2458 | assert len(list(f.bars)) == 2 |
| 2459 | f.bars.clear() |
| 2460 | |
| 2461 | def test_dict_wrapper(self): |
| 2462 | """test that the supplied 'dict' wrapper can be used as a |
nothing calls this directly
no test coverage detected