Ejemplo n.º 1
0
    def test_atomic_rollback(self):
        with test_db.atomic():
            UniqueModel.create(name='charlie')
            try:
                with test_db.atomic():
                    UniqueModel.create(name='charlie')
            except IntegrityError:
                pass
            else:
                assert False

            with test_db.atomic():
                UniqueModel.create(name='zaizee')
                try:
                    with test_db.atomic():
                        UniqueModel.create(name='zaizee')
                except IntegrityError:
                    pass
                else:
                    assert False

                UniqueModel.create(name='mickey')
            UniqueModel.create(name='huey')

        names = [um.name for um in
                 UniqueModel.select().order_by(UniqueModel.name)]
        self.assertEqual(names, ['charlie', 'huey', 'mickey', 'zaizee'])
    def test_atomic_rollback(self):
        with test_db.atomic():
            UniqueModel.create(name='charlie')
            try:
                with test_db.atomic():
                    UniqueModel.create(name='charlie')
            except IntegrityError:
                pass
            else:
                assert False

            with test_db.atomic():
                UniqueModel.create(name='zaizee')
                try:
                    with test_db.atomic():
                        UniqueModel.create(name='zaizee')
                except IntegrityError:
                    pass
                else:
                    assert False

                UniqueModel.create(name='mickey')
            UniqueModel.create(name='huey')

        names = [um.name for um in
                 UniqueModel.select().order_by(UniqueModel.name)]
        self.assertEqual(names, ['charlie', 'huey', 'mickey', 'zaizee'])
Ejemplo n.º 3
0
    def test_atomic_second_connection(self):
        def test_separate_conn(expected):
            new_db = self.new_connection()
            cursor = new_db.execute_sql('select username from users;')
            usernames = sorted(row[0] for row in cursor.fetchall())
            self.assertEqual(usernames, expected)
            new_db.close()

        with test_db.atomic():
            User.create(username='******')
            test_separate_conn([])

            with test_db.atomic():
                User.create(username='******')

            with test_db.atomic() as tx3:
                User.create(username='******')
                tx3.rollback()

            test_separate_conn([])

            users = User.select(User.username).order_by(User.username)
            self.assertEqual(
                [user.username for user in users],
                ['u1', 'u2'])

        users = User.select(User.username).order_by(User.username)
        self.assertEqual(
            [user.username for user in users],
            ['u1', 'u2'])
    def test_atomic_second_connection(self):
        def test_separate_conn(expected):
            new_db = self.new_connection()
            cursor = new_db.execute_sql('select username from users;')
            usernames = sorted(row[0] for row in cursor.fetchall())
            self.assertEqual(usernames, expected)
            new_db.close()

        with test_db.atomic():
            User.create(username='******')
            test_separate_conn([])

            with test_db.atomic():
                User.create(username='******')

            with test_db.atomic() as tx3:
                User.create(username='******')
                tx3.rollback()

            test_separate_conn([])

            users = User.select(User.username).order_by(User.username)
            self.assertEqual(
                [user.username for user in users],
                ['u1', 'u2'])

        users = User.select(User.username).order_by(User.username)
        self.assertEqual(
            [user.username for user in users],
            ['u1', 'u2'])
Ejemplo n.º 5
0
    def test_atomic_rollback(self):
        with test_db.atomic():
            UniqueModel.create(name="charlie")
            try:
                with test_db.atomic():
                    UniqueModel.create(name="charlie")
            except IntegrityError:
                pass
            else:
                assert False

            with test_db.atomic():
                UniqueModel.create(name="zaizee")
                try:
                    with test_db.atomic():
                        UniqueModel.create(name="zaizee")
                except IntegrityError:
                    pass
                else:
                    assert False

                UniqueModel.create(name="mickey")
            UniqueModel.create(name="huey")

        names = [um.name for um in UniqueModel.select().order_by(UniqueModel.name)]
        self.assertEqual(names, ["charlie", "huey", "mickey", "zaizee"])
Ejemplo n.º 6
0
    def test_atomic_with_delete(self):
        for i in range(3):
            User.create(username='******' % i)

        with test_db.atomic():
            User.get(User.username == 'u1').delete_instance()

        usernames = [u.username for u in User.select()]
        self.assertEqual(sorted(usernames), ['u0', 'u2'])

        with test_db.atomic():
            with test_db.atomic():
                User.get(User.username == 'u2').delete_instance()

        usernames = [u.username for u in User.select()]
        self.assertEqual(usernames, ['u0'])
    def test_savepoint_explicit_commits(self):
        with test_db.atomic() as txn:
            User.create(username='******')
            txn.rollback()
            User.create(username='******')
            txn.commit()

            with test_db.atomic() as sp:
                User.create(username='******')
                sp.rollback()

                User.create(username='******')
                sp.commit()

        usernames = [u.username for u in User.select().order_by(User.username)]
        self.assertEqual(usernames, ['sp-commit', 'txn-commit'])
    def test_atomic_with_delete(self):
        for i in range(3):
            User.create(username='******' % i)

        with test_db.atomic():
            User.get(User.username == 'u1').delete_instance()

        usernames = [u.username for u in User.select()]
        self.assertEqual(sorted(usernames), ['u0', 'u2'])

        with test_db.atomic():
            with test_db.atomic():
                User.get(User.username == 'u2').delete_instance()

        usernames = [u.username for u in User.select()]
        self.assertEqual(usernames, ['u0'])
Ejemplo n.º 9
0
    def test_atomic_with_delete(self):
        for i in range(3):
            User.create(username="******" % i)

        with test_db.atomic():
            User.get(User.username == "u1").delete_instance()

        usernames = [u.username for u in User.select()]
        self.assertEqual(sorted(usernames), ["u0", "u2"])

        with test_db.atomic():
            with test_db.atomic():
                User.get(User.username == "u2").delete_instance()

        usernames = [u.username for u in User.select()]
        self.assertEqual(usernames, ["u0"])
Ejemplo n.º 10
0
    def test_atomic(self):
        with test_db.atomic():
            User.create(username='******')
            with test_db.atomic():
                User.create(username='******')
                with test_db.atomic() as txn3:
                    User.create(username='******')
                    txn3.rollback()

                with test_db.atomic():
                    User.create(username='******')

            with test_db.atomic() as txn5:
                User.create(username='******')
                txn5.rollback()

            User.create(username='******')

        query = User.select().order_by(User.username)
        self.assertEqual([u.username for u in query], ['u1', 'u2', 'u4', 'u6'])
Ejemplo n.º 11
0
    def test_atomic(self):
        with test_db.atomic():
            User.create(username="******")
            with test_db.atomic():
                User.create(username="******")
                with test_db.atomic() as txn3:
                    User.create(username="******")
                    txn3.rollback()

                with test_db.atomic():
                    User.create(username="******")

            with test_db.atomic() as txn5:
                User.create(username="******")
                txn5.rollback()

            User.create(username="******")

        query = User.select().order_by(User.username)
        self.assertEqual([u.username for u in query], ["u1", "u2", "u4", "u6"])
Ejemplo n.º 12
0
    def test_atomic(self):
        with test_db.atomic():
            User.create(username='******')
            with test_db.atomic():
                User.create(username='******')
                with test_db.atomic() as txn3:
                    User.create(username='******')
                    txn3.rollback()

                with test_db.atomic():
                    User.create(username='******')

            with test_db.atomic() as txn5:
                User.create(username='******')
                txn5.rollback()

            User.create(username='******')

        query = User.select().order_by(User.username)
        self.assertEqual(
            [u.username for u in query],
            ['u1', 'u2', 'u4', 'u6'])