|
18 | 18 | from test.orm import _fixtures |
19 | 19 |
|
20 | 20 |
|
21 | | -class DefaultStrategyOptionsTest(_fixtures.FixtureTest): |
| 21 | +class DefaultStrategyOptionsTestFixtures(_fixtures.FixtureTest): |
22 | 22 | def _assert_fully_loaded(self, users): |
23 | 23 | # verify everything loaded, with no additional sql needed |
24 | 24 | def go(): |
@@ -193,6 +193,9 @@ def _upgrade_fixture(self): |
193 | 193 |
|
194 | 194 | return fixture_session() |
195 | 195 |
|
| 196 | + |
| 197 | +class DefaultStrategyOptionsTest(DefaultStrategyOptionsTestFixtures): |
| 198 | + |
196 | 199 | def test_downgrade_baseline(self): |
197 | 200 | """Mapper strategy defaults load as expected |
198 | 201 | (compare to rest of DefaultStrategyOptionsTest downgrade tests).""" |
@@ -368,67 +371,6 @@ def go(): |
368 | 371 | # lastly, make sure they actually loaded properly |
369 | 372 | eq_(users, self.static.user_all_result) |
370 | 373 |
|
371 | | - def test_noload_with_joinedload(self): |
372 | | - """Mapper load strategy defaults can be downgraded with |
373 | | - noload('*') option, while explicit joinedload() option |
374 | | - is still honored""" |
375 | | - sess = self._downgrade_fixture() |
376 | | - users = [] |
377 | | - |
378 | | - # test noload('*') shuts off 'orders' subquery, only 1 sql |
379 | | - def go(): |
380 | | - users[:] = ( |
381 | | - sess.query(self.classes.User) |
382 | | - .options(sa.orm.noload("*")) |
383 | | - .options(joinedload(self.classes.User.addresses)) |
384 | | - .order_by(self.classes.User.id) |
385 | | - .all() |
386 | | - ) |
387 | | - |
388 | | - self.assert_sql_count(testing.db, go, 1) |
389 | | - |
390 | | - # verify all the addresses were joined loaded (no more sql) |
391 | | - self._assert_addresses_loaded(users) |
392 | | - |
393 | | - # User.orders should have loaded "noload" (meaning []) |
394 | | - def go(): |
395 | | - for u in users: |
396 | | - assert u.orders == [] |
397 | | - |
398 | | - self.assert_sql_count(testing.db, go, 0) |
399 | | - |
400 | | - def test_noload_with_subqueryload(self): |
401 | | - """Mapper load strategy defaults can be downgraded with |
402 | | - noload('*') option, while explicit subqueryload() option |
403 | | - is still honored""" |
404 | | - sess = self._downgrade_fixture() |
405 | | - users = [] |
406 | | - |
407 | | - # test noload('*') option combined with subqueryload() |
408 | | - # shuts off 'addresses' load AND orders.items load: 2 sql expected |
409 | | - def go(): |
410 | | - users[:] = ( |
411 | | - sess.query(self.classes.User) |
412 | | - .options(sa.orm.noload("*")) |
413 | | - .options(subqueryload(self.classes.User.orders)) |
414 | | - .order_by(self.classes.User.id) |
415 | | - .all() |
416 | | - ) |
417 | | - |
418 | | - self.assert_sql_count(testing.db, go, 2) |
419 | | - |
420 | | - def go(): |
421 | | - # Verify orders have already been loaded: 0 sql |
422 | | - for u, static in zip(users, self.static.user_all_result): |
423 | | - assert len(u.orders) == len(static.orders) |
424 | | - # Verify noload('*') prevented orders.items load |
425 | | - # and set 'items' to [] |
426 | | - for u in users: |
427 | | - for o in u.orders: |
428 | | - assert o.items == [] |
429 | | - |
430 | | - self.assert_sql_count(testing.db, go, 0) |
431 | | - |
432 | 374 | def test_joined(self): |
433 | 375 | """Mapper load strategy defaults can be upgraded with |
434 | 376 | joinedload('*') option.""" |
@@ -654,99 +596,6 @@ def go(): |
654 | 596 | self._assert_fully_loaded(users) |
655 | 597 |
|
656 | 598 |
|
657 | | -class NoLoadTest(_fixtures.FixtureTest): |
658 | | - run_inserts = "once" |
659 | | - run_deletes = None |
660 | | - |
661 | | - def test_o2m_noload(self): |
662 | | - Address, addresses, users, User = ( |
663 | | - self.classes.Address, |
664 | | - self.tables.addresses, |
665 | | - self.tables.users, |
666 | | - self.classes.User, |
667 | | - ) |
668 | | - |
669 | | - m = self.mapper_registry.map_imperatively( |
670 | | - User, |
671 | | - users, |
672 | | - properties=dict( |
673 | | - addresses=relationship( |
674 | | - self.mapper_registry.map_imperatively(Address, addresses), |
675 | | - lazy="noload", |
676 | | - ) |
677 | | - ), |
678 | | - ) |
679 | | - q = fixture_session().query(m) |
680 | | - result = [None] |
681 | | - |
682 | | - def go(): |
683 | | - x = q.filter(User.id == 7).all() |
684 | | - x[0].addresses |
685 | | - result[0] = x |
686 | | - |
687 | | - self.assert_sql_count(testing.db, go, 1) |
688 | | - |
689 | | - self.assert_result( |
690 | | - result[0], User, {"id": 7, "addresses": (Address, [])} |
691 | | - ) |
692 | | - |
693 | | - def test_upgrade_o2m_noload_lazyload_option(self): |
694 | | - Address, addresses, users, User = ( |
695 | | - self.classes.Address, |
696 | | - self.tables.addresses, |
697 | | - self.tables.users, |
698 | | - self.classes.User, |
699 | | - ) |
700 | | - |
701 | | - m = self.mapper_registry.map_imperatively( |
702 | | - User, |
703 | | - users, |
704 | | - properties=dict( |
705 | | - addresses=relationship( |
706 | | - self.mapper_registry.map_imperatively(Address, addresses), |
707 | | - lazy="noload", |
708 | | - ) |
709 | | - ), |
710 | | - ) |
711 | | - q = fixture_session().query(m).options(sa.orm.lazyload(User.addresses)) |
712 | | - result = [None] |
713 | | - |
714 | | - def go(): |
715 | | - x = q.filter(User.id == 7).all() |
716 | | - x[0].addresses |
717 | | - result[0] = x |
718 | | - |
719 | | - self.sql_count_(2, go) |
720 | | - |
721 | | - self.assert_result( |
722 | | - result[0], User, {"id": 7, "addresses": (Address, [{"id": 1}])} |
723 | | - ) |
724 | | - |
725 | | - def test_m2o_noload_option(self): |
726 | | - Address, addresses, users, User = ( |
727 | | - self.classes.Address, |
728 | | - self.tables.addresses, |
729 | | - self.tables.users, |
730 | | - self.classes.User, |
731 | | - ) |
732 | | - self.mapper_registry.map_imperatively( |
733 | | - Address, addresses, properties={"user": relationship(User)} |
734 | | - ) |
735 | | - self.mapper_registry.map_imperatively(User, users) |
736 | | - s = fixture_session() |
737 | | - a1 = ( |
738 | | - s.query(Address) |
739 | | - .filter_by(id=1) |
740 | | - .options(sa.orm.noload(Address.user)) |
741 | | - .first() |
742 | | - ) |
743 | | - |
744 | | - def go(): |
745 | | - eq_(a1.user, None) |
746 | | - |
747 | | - self.sql_count_(0, go) |
748 | | - |
749 | | - |
750 | 599 | class Issue11292Test(fixtures.DeclarativeMappedTest): |
751 | 600 | @classmethod |
752 | 601 | def setup_classes(cls): |
|
0 commit comments