Ticket #20463: get_or_create_pgsql-test.diff

File get_or_create_pgsql-test.diff, 1.3 KB (added by Ulrich Petri, 12 years ago)
  • tests/get_or_create/tests.py

    diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py
    index e9cce9b..3f70626 100644
    a b from __future__ import absolute_import  
    33from datetime import date
    44import traceback
    55
    6 from django.db import IntegrityError
     6from django.db import IntegrityError, DataError, connection
    77from django.test import TestCase, TransactionTestCase
     8from django.utils.unittest.case import skipUnless
    89
    910from .models import Person, ManualPrimaryKeyTest, Profile
    1011
    class GetOrCreateTests(TestCase):  
    6465            formatted_traceback = traceback.format_exc()
    6566            self.assertIn('obj.save', formatted_traceback)
    6667
     68    @skipUnless(connection.vendor == 'postgresql', "This test only applies to PostgreSQL")
     69    def test_savepoint_rollback(self):
     70        # Provoke a DataError in .get_or_create()
     71        try:
     72            Person.objects.get_or_create(birthday=date(1970, 1, 1), defaults={
     73                'first_name': "\xff",
     74                'last_name': "\xff"
     75            })
     76        except DataError:
     77            pass
     78        # Create another object to make sure the database is not in a "broken" state
     79        Person.objects.create(first_name="Bob", last_name="Ross", birthday=date(1950, 1, 1))
     80
    6781
    6882class GetOrCreateTransactionTests(TransactionTestCase):
    6983
Back to Top