Ejemplo n.º 1
0
    def test_transaction_connection_handling(self):
        patch = 'peewee.Database'
        db = SqliteDatabase(':memory:')
        with mock.patch(patch, wraps=db) as patched_db:
            with transaction(patched_db):
                patched_db.begin.assert_called_once_with()
                self.assertEqual(patched_db.commit.call_count, 0)
                self.assertEqual(patched_db.rollback.call_count, 0)

            patched_db.begin.assert_called_once_with()
            patched_db.commit.assert_called_once_with()
            self.assertEqual(patched_db.rollback.call_count, 0)

        with mock.patch(patch, wraps=db) as patched_db:
            def _test_patched():
                patched_db.commit.side_effect = ValueError
                with transaction(patched_db):
                    pass

            self.assertRaises(ValueError, _test_patched)
            patched_db.begin.assert_called_once_with()
            patched_db.commit.assert_called_once_with()
            patched_db.rollback.assert_called_once_with()
    def test_transaction_connection_handling(self):
        patch = 'peewee.Database'
        db = SqliteDatabase(':memory:')
        with mock.patch(patch, wraps=db) as patched_db:
            with transaction(patched_db):
                patched_db.begin.assert_called_once_with()
                self.assertEqual(patched_db.commit.call_count, 0)
                self.assertEqual(patched_db.rollback.call_count, 0)

            patched_db.begin.assert_called_once_with()
            patched_db.commit.assert_called_once_with()
            self.assertEqual(patched_db.rollback.call_count, 0)

        with mock.patch(patch, wraps=db) as patched_db:
            def _test_patched():
                patched_db.commit.side_effect = ValueError
                with transaction(patched_db):
                    pass

            self.assertRaises(ValueError, _test_patched)
            patched_db.begin.assert_called_once_with()
            patched_db.commit.assert_called_once_with()
            patched_db.rollback.assert_called_once_with()
Ejemplo n.º 3
0
 def _test_patched():
     patched_db.commit.side_effect = ValueError
     with transaction(patched_db):
         pass
Ejemplo n.º 4
0
 def do_will_succeed():
     with transaction(test_db):
         u = User.create(username='******')
         Blog.create(title='b1', user=u)
Ejemplo n.º 5
0
 def transaction(self, lock_type='deferred'):
     return transaction(self, lock_type)
 def _test_patched():
     patched_db.commit.side_effect = ValueError
     with transaction(patched_db):
         pass
 def do_will_succeed():
     with transaction(test_db):
         u = User.create(username='******')
         Blog.create(title='b1', user=u)
Ejemplo n.º 8
0
 def do_will_succeed():
     with transaction(test_db):
         u = User.create(username="******")
         Blog.create(title="b1", user=u)
Ejemplo n.º 9
0
 def transaction(self, lock_type='deferred'):
     return transaction(self, lock_type)