Exemple #1
0
    def test_integrity_error_rollsback_transaction(self):
        client = postgresql.create_from_config(self._get_config(),
                                               prefix='storage_',
                                               with_transaction=False)
        with self.assertRaises(exceptions.IntegrityError):
            with client.connect() as conn:
                # Make some change in a table.
                conn.execute("""
                INSERT INTO records
                VALUES ('rock-and-roll', 'music', 'genre', NOW(), '{}', FALSE);
                """)
                # Go into a failing integrity constraint.
                query = "INSERT INTO timestamps VALUES ('a', 'b', NOW());"
                conn.execute(query)
                conn.execute(query)
                conn.commit()
                conn.close()

        # Check that change in the above table was rolledback.
        with client.connect() as conn:
            result = conn.execute("""
            SELECT FROM records
             WHERE parent_id = 'music'
               AND collection_id = 'genre';
            """)
        self.assertEqual(result.rowcount, 0)
Exemple #2
0
    def test_integrity_error_rollsback_transaction(self):
        client = postgresql.create_from_config(
            self._get_config(), prefix="storage_", with_transaction=False
        )
        with self.assertRaises(exceptions.IntegrityError):
            with client.connect() as conn:
                # Make some change in a table.
                conn.execute(
                    """
                INSERT INTO records
                VALUES ('rock-and-roll', 'music', 'genre', NOW(), '{}', FALSE);
                """
                )
                # Go into a failing integrity constraint.
                query = "INSERT INTO timestamps VALUES ('a', 'b', NOW());"
                conn.execute(query)
                conn.execute(query)
                conn.commit()
                conn.close()

        # Check that change in the above table was rolledback.
        with client.connect() as conn:
            result = conn.execute(
                """
            SELECT FROM records
             WHERE parent_id = 'music'
               AND collection_id = 'genre';
            """
            )
        self.assertEqual(result.rowcount, 0)
Exemple #3
0
    def test_integrity_error_rollsback_transaction(self):
        client = postgresql.create_from_config(self._get_config(),
                                               prefix='storage_',
                                               with_transaction=False)
        with self.assertRaises(exceptions.IntegrityError):
            with client.connect() as conn:
                # Make some change in metadata.
                conn.execute("INSERT INTO metadata VALUES ('roll', 'rock');")
                # Go into a failing integrity constraint.
                query = "INSERT INTO timestamps VALUES ('a', 'b', NOW());"
                conn.execute(query)
                conn.execute(query)
                conn.commit()
                conn.close()

        # Check that change in metadata was rolledback.
        with client.connect() as conn:
            result = conn.execute("SELECT FROM metadata WHERE name = 'roll';")
        self.assertEqual(result.rowcount, 0)