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