Ticket #18081: 18081-test.diff

File 18081-test.diff, 1.6 KB (added by Tim Graham, 9 years ago)
  • tests/proxy_models/tests.py

    diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
    index 9824432..2210503 100644
    a b from django.contrib.auth.models import User as AuthUser  
    88from django.contrib.contenttypes.models import ContentType
    99from django.core import checks, exceptions, management
    1010from django.core.urlresolvers import reverse
    11 from django.db import DEFAULT_DB_ALIAS, models
     11from django.db import DEFAULT_DB_ALIAS, IntegrityError, models, transaction
    1212from django.db.models import signals
    13 from django.test import TestCase, override_settings
     13from django.test import TestCase, TransactionTestCase, override_settings
    1414
    1515from .admin import admin as force_admin_model_registration  # NOQA
    1616from .models import (
    class ProxyModelAdminTests(TestCase):  
    447447        delete_str = response.context['deleted_objects'][0]
    448448        self.assertEqual(delete_str, proxy_str)
    449449        self.client.logout()
     450
     451
     452class TransactionalProxyModelTests(TransactionTestCase):
     453    available_apps = ['proxy_models']
     454
     455    def test_proxy_fk(self):
     456        """
     457        Test that the DB contains proper foreign keys for proxy model references.
     458        """
     459        @transaction.atomic
     460        def create_failing_pk():
     461            t = TrackerUser.objects.create(status='bar')
     462            proxy_tracker = ProxyTrackerUser.objects.get(pk=t.pk)
     463            Improvement.objects.create(
     464                summary='foof', version='foof',
     465                reporter_id=1, associated_bug_id=1,
     466                assignee=proxy_tracker,
     467           )
     468        self.assertRaises(IntegrityError, create_failing_pk)
Back to Top