~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to test/orm/test_load_on_fks.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
from sqlalchemy.orm import *
3
3
 
4
4
from sqlalchemy.ext.declarative import declarative_base
5
 
from test.lib.testing import eq_, AssertsExecutionResults, assert_raises
6
 
from test.lib import testing
7
 
from test.lib import fixtures
 
5
from sqlalchemy.testing import eq_, AssertsExecutionResults, assert_raises
 
6
from sqlalchemy import testing
 
7
from sqlalchemy.testing import fixtures
8
8
from sqlalchemy.orm.attributes import instance_state
9
9
from sqlalchemy.orm.exc import FlushError
10
 
from test.lib.schema import Table, Column
 
10
from sqlalchemy.testing.schema import Table, Column
11
11
 
12
12
engine = testing.db
13
13
 
112
112
        # should be turned on.
113
113
        assert c3 not in p1.children
114
114
 
 
115
    def test_enable_rel_loading_disallows_backref_event(self):
 
116
        sess.autoflush = False
 
117
        c3 = Child()
 
118
        sess.enable_relationship_loading(c3)
 
119
        c3.parent_id = p1.id
 
120
        c3.parent = p1
 
121
 
 
122
        # c3.parent is already acting like a "load" here,
 
123
        # so backref events don't work
 
124
        assert c3 not in p1.children
 
125
 
115
126
    def test_load_on_persistent_allows_backref_event(self):
116
127
        Child.parent.property.load_on_pending = True
117
128
        c3 = Child()
121
132
 
122
133
        assert c3 in p1.children
123
134
 
 
135
    def test_enable_rel_loading_on_persistent_disallows_backref_event(self):
 
136
        c3 = Child()
 
137
        sess.enable_relationship_loading(c3)
 
138
        c3.parent_id = p1.id
 
139
        c3.parent = p1
 
140
 
 
141
        # c3.parent is already acting like a "load" here,
 
142
        # so backref events don't work
 
143
        assert c3 not in p1.children
 
144
 
124
145
    def test_no_load_on_pending_allows_backref_event(self):
125
146
        # users who stick with the program and don't use
126
147
        # 'load_on_pending' get expected behavior
274
295
            for attach in (False, True):
275
296
                for autoflush in (False, True):
276
297
                    for manualflush in (False, True):
277
 
                        Child.parent.property.load_on_pending = loadonpending
278
 
                        sess.autoflush = autoflush
279
 
                        c2 = Child()
280
 
 
281
 
                        if attach:
282
 
                            sess._attach(instance_state(c2))
283
 
 
284
 
                        c2.parent_id = p2.id
285
 
 
286
 
                        if manualflush:
287
 
                           sess.flush()
288
 
 
289
 
                        if loadonpending and attach:
290
 
                            assert c2.parent is p2
291
 
                        else:
292
 
                            assert c2.parent is None
293
 
 
294
 
                        sess.rollback()
 
298
                        for enable_relationship_rel in (False, True):
 
299
                            Child.parent.property.load_on_pending = loadonpending
 
300
                            sess.autoflush = autoflush
 
301
                            c2 = Child()
 
302
 
 
303
                            if attach:
 
304
                                sess._attach(instance_state(c2))
 
305
 
 
306
                            if enable_relationship_rel:
 
307
                                sess.enable_relationship_loading(c2)
 
308
 
 
309
                            c2.parent_id = p2.id
 
310
 
 
311
                            if manualflush:
 
312
                               sess.flush()
 
313
 
 
314
                            if (loadonpending and attach) or enable_relationship_rel:
 
315
                                assert c2.parent is p2
 
316
                            else:
 
317
                                assert c2.parent is None
 
318
 
 
319
                            sess.rollback()