diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-11-19 14:23:08 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-11-19 14:23:08 -0500 |
| commit | c7f9aa281857eeeaf7963c370bda43d2eb4746f5 (patch) | |
| tree | 8d99cb282312028f5004eae86a64f6004921b7dd /test/ext | |
| parent | 14498364f82eadaf3de914d5ac588cd5b9563547 (diff) | |
| download | sqlalchemy-c7f9aa281857eeeaf7963c370bda43d2eb4746f5.tar.gz | |
- rewrite the docs and add a test for the bake_queries=True
relationship flag; this flag *does* have an effect when the baked
lazy loader plugin has been invoked. clarify the intent of this
flag as an "opt out" but only has an effect when the baked system
is loaded anyway. fixes #3572
Diffstat (limited to 'test/ext')
| -rw-r--r-- | test/ext/test_baked.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/test/ext/test_baked.py b/test/ext/test_baked.py index 8bf697fbf..dcf333184 100644 --- a/test/ext/test_baked.py +++ b/test/ext/test_baked.py @@ -596,14 +596,14 @@ class ResultTest(BakedTest): class LazyLoaderTest(BakedTest): run_setup_mappers = 'each' - def _o2m_fixture(self, lazy="select"): + def _o2m_fixture(self, lazy="select", **kw): User = self.classes.User Address = self.classes.Address mapper(User, self.tables.users, properties={ 'addresses': relationship( Address, order_by=self.tables.addresses.c.id, - lazy=lazy) + lazy=lazy, **kw) }) mapper(Address, self.tables.addresses) return User, Address @@ -720,6 +720,50 @@ class LazyLoaderTest(BakedTest): # not invoked eq_(el.mock_calls, []) + def test_baked_lazy_loading_relationship_flag_true(self): + self._test_baked_lazy_loading_relationship_flag(True) + + def test_baked_lazy_loading_relationship_flag_false(self): + self._test_baked_lazy_loading_relationship_flag(False) + + def _test_baked_lazy_loading_relationship_flag(self, flag): + baked.bake_lazy_loaders() + try: + User, Address = self._o2m_fixture(bake_queries=flag) + + sess = Session() + u1 = sess.query(User).first() + + from sqlalchemy.orm import Query + + canary = mock.Mock() + + # I would think Mock can do this but apparently + # it cannot (wrap / autospec don't work together) + real_compile_context = Query._compile_context + + def _my_compile_context(*arg, **kw): + if arg[0].column_descriptions[0]['entity'] is Address: + canary() + return real_compile_context(*arg, **kw) + + with mock.patch.object( + Query, + "_compile_context", + _my_compile_context + ): + u1.addresses + + sess.expire(u1) + u1.addresses + finally: + baked.unbake_lazy_loaders() + + if flag: + eq_(canary.call_count, 1) + else: + eq_(canary.call_count, 2) + def test_baked_lazy_loading_option_o2m(self): User, Address = self._o2m_fixture() self._test_baked_lazy_loading(set_option=True) |
