Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding tests for the context manager

  • Loading branch information...
commit 76523bbf6c63d5fe10398279ceac3ee8f9fdc123 1 parent 5ce3350
@coleifer authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 tests.py
View
26 tests.py
@@ -3373,6 +3373,32 @@ def will_succeed():
self.assertEqual(Blog.select().count(), 1)
self.assertEqual(Entry.select().count(), 1)
+ def test_context_mgr(self):
+ def will_fail():
+ b = Blog.create(title='b1')
+ e = Entry.create() # no blog, will raise an error
+ return b, e
+
+ def do_will_fail():
+ with transaction(test_db):
+ will_fail()
+
+ self.assertRaises(Exception, do_will_fail)
+ self.assertEqual(Blog.select().count(), 0)
+
+ def will_succeed():
+ b = Blog.create(title='b1')
+ e = Entry.create(title='e1', content='e1', blog=b)
+ return b, e
+
+ def do_will_succeed():

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

@coleifer Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ with transaction(test_db):
+ will_succeed()
+
+ b, e = will_succeed()
+ self.assertEqual(Blog.select().count(), 1)
+ self.assertEqual(Entry.select().count(), 1)
+
if test_db.adapter.for_update_support:
class ForUpdateTestCase(BaseModelTestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.