@@ -208,7 +208,7 @@ def test():
208
208
self .assertEqual (count (x for x in self .X ), 3 )
209
209
else :
210
210
self .fail ()
211
-
211
+
212
212
def test_db_session_decorator_14 (self ):
213
213
# allowed_exceptions may be callable, should rollback if not nonzero
214
214
@db_session (allowed_exceptions = lambda e : isinstance (e , TypeError ))
@@ -322,65 +322,78 @@ class Student(db.Entity):
322
322
class TestDBSessionScope (unittest .TestCase ):
323
323
def setUp (self ):
324
324
rollback ()
325
+
325
326
def tearDown (self ):
326
327
rollback ()
328
+
327
329
def test1 (self ):
328
330
with db_session :
329
331
s1 = Student [1 ]
330
332
name = s1 .name
333
+
331
334
@raises_exception (DatabaseSessionIsOver , 'Cannot load attribute Student[1].picture: the database session is over' )
332
335
def test2 (self ):
333
336
with db_session :
334
337
s1 = Student [1 ]
335
338
picture = s1 .picture
339
+
336
340
@raises_exception (DatabaseSessionIsOver , 'Cannot load attribute Group[1].major: the database session is over' )
337
341
def test3 (self ):
338
342
with db_session :
339
343
s1 = Student [1 ]
340
344
group_id = s1 .group .id
341
345
major = s1 .group .major
346
+
342
347
@raises_exception (DatabaseSessionIsOver , 'Cannot assign new value to attribute Student[1].name: the database session is over' )
343
348
def test4 (self ):
344
349
with db_session :
345
350
s1 = Student [1 ]
346
351
s1 .name = 'New name'
352
+
347
353
def test5 (self ):
348
354
with db_session :
349
355
g1 = Group [1 ]
350
356
self .assertEqual (str (g1 .students ), 'StudentSet([...])' )
357
+
351
358
@raises_exception (DatabaseSessionIsOver , 'Cannot load collection Group[1].students: the database session is over' )
352
359
def test6 (self ):
353
360
with db_session :
354
361
g1 = Group [1 ]
355
362
l = len (g1 .students )
363
+
356
364
@raises_exception (DatabaseSessionIsOver , 'Cannot change collection Group[1].Group.students: the database session is over' )
357
365
def test7 (self ):
358
366
with db_session :
359
367
s1 = Student [1 ]
360
368
g1 = Group [1 ]
361
369
g1 .students .remove (s1 )
370
+
362
371
@raises_exception (DatabaseSessionIsOver , 'Cannot change collection Group[1].Group.students: the database session is over' )
363
372
def test8 (self ):
364
373
with db_session :
365
374
g2_students = Group [2 ].students
366
375
g1 = Group [1 ]
367
376
g1 .students = g2_students
377
+
368
378
@raises_exception (DatabaseSessionIsOver , 'Cannot change collection Group[1].Group.students: the database session is over' )
369
379
def test9 (self ):
370
380
with db_session :
371
381
s3 = Student [3 ]
372
382
g1 = Group [1 ]
373
383
g1 .students .add (s3 )
384
+
374
385
@raises_exception (DatabaseSessionIsOver , 'Cannot change collection Group[1].Group.students: the database session is over' )
375
386
def test10 (self ):
376
387
with db_session :
377
388
g1 = Group [1 ]
378
389
g1 .students .clear ()
390
+
379
391
@raises_exception (DatabaseSessionIsOver , 'Cannot delete object Student[1]: the database session is over' )
380
392
def test11 (self ):
381
393
with db_session :
382
394
s1 = Student [1 ]
383
395
s1 .delete ()
396
+
384
397
@raises_exception (DatabaseSessionIsOver , 'Cannot change object Student[1]: the database session is over' )
385
398
def test12 (self ):
386
399
with db_session :
0 commit comments