Skip to content
This repository
Browse code

Adding tests for the context manager

  • Loading branch information...
commit 76523bbf6c63d5fe10398279ceac3ee8f9fdc123 1 parent 5ce3350
Charles Leifer authored May 10, 2012

Showing 1 changed file with 26 additions and 0 deletions. Show diff stats Hide diff stats

  1. 26  tests.py
26  tests.py
@@ -3373,6 +3373,32 @@ def will_succeed():
3373 3373
         self.assertEqual(Blog.select().count(), 1)
3374 3374
         self.assertEqual(Entry.select().count(), 1)
3375 3375
 
  3376
+    def test_context_mgr(self):
  3377
+        def will_fail():
  3378
+            b = Blog.create(title='b1')
  3379
+            e = Entry.create() # no blog, will raise an error
  3380
+            return b, e
  3381
+
  3382
+        def do_will_fail():
  3383
+            with transaction(test_db):
  3384
+                will_fail()
  3385
+
  3386
+        self.assertRaises(Exception, do_will_fail)
  3387
+        self.assertEqual(Blog.select().count(), 0)
  3388
+
  3389
+        def will_succeed():
  3390
+            b = Blog.create(title='b1')
  3391
+            e = Entry.create(title='e1', content='e1', blog=b)
  3392
+            return b, e
  3393
+
  3394
+        def do_will_succeed():
  3395
+            with transaction(test_db):
  3396
+                will_succeed()
  3397
+
  3398
+        b, e = will_succeed()
  3399
+        self.assertEqual(Blog.select().count(), 1)
  3400
+        self.assertEqual(Entry.select().count(), 1)
  3401
+
3376 3402
 
3377 3403
 if test_db.adapter.for_update_support:
3378 3404
     class ForUpdateTestCase(BaseModelTestCase):

0 notes on commit 76523bb

Tom Moertel

I suspect that you meant to use do_will_succeed somewhere in the test case :-)

Charles Leifer
Please sign in to comment.
Something went wrong with that request. Please try again.