From 8931b5fbe047af6be60dc32551d5fc887ecab587 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Sat, 10 Aug 2013 16:08:28 -0400 Subject: [PATCH] Add two tests for #17 --- tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests.py b/tests.py index e9e1736..e4fd9cd 100644 --- a/tests.py +++ b/tests.py @@ -109,6 +109,17 @@ def test_TooMany_message_is_helpful_for_a_range(self): "Got 4 rows; expecting between 1 and 3 (inclusive)." +class TestOneRollsBack(WithData): + + def test_one_rollsback_on_error(self): + try: + self.db.one("UPDATE foo SET bar='bum' RETURNING *", strict=True) + except TooMany: + pass + actual = self.db.all("SELECT * FROM foo WHERE bar='bum'") + assert actual == [] + + class TestOne(WithData): def test_with_strict_True_one_raises_TooFew(self): @@ -209,6 +220,16 @@ def test_one_or_zero_raises_TooFew(self): , "CREATE TABLE foux (baar text)" ) + def test_one_or_zero_rollsback_on_error(self): + try: + self.db.one_or_zero("CREATE TABLE foux (baar text)") + except TooFew: + pass + self.assertRaises( ProgrammingError + , self.db.all + , "SELECT * FROM foux" + ) + def test_one_or_zero_returns_None(self): actual = self.db.one_or_zero("SELECT * FROM foo WHERE bar='blam'") assert actual is None