Ticket #15654: test.diff

File test.diff, 1.7 KB (added by apollo13, 4 years ago)
  • new file tests/modeltests/delete/sub/__init__.py

    diff -r a427ac897106 tests/modeltests/delete/sub/__init__.py
    - +  
     1# __init__.py
  • new file tests/modeltests/delete/sub/models.py

    diff -r a427ac897106 tests/modeltests/delete/sub/models.py
    - +  
     1from django.db import models
     2from django.contrib.contenttypes.models import ContentType
     3
     4class TestModel(models.Model):
     5    fk = models.ForeignKey(ContentType)
  • tests/modeltests/delete/tests.py

    diff -r a427ac897106 tests/modeltests/delete/tests.py
    a b  
     1from django.conf import settings
    12from django.db import models, IntegrityError
    23from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature
    34
     
    251252
    252253        r.delete()
    253254        self.assertEqual(HiddenUserProfile.objects.count(), 0)
     255
     256
     257class ContentTypeDeleteTests(TestCase):
     258    def setUp(self):
     259        from sub.models import *
     260        self.old_installed_apps = settings.INSTALLED_APPS
     261        settings.INSTALLED_APPS = ['django.contrib.contenttypes']
     262        super(ContentTypeDeleteTests, self).setUp()
     263
     264    def test_deletion(self):
     265        from django.contrib.contenttypes import management, models
     266        # YIKES YIKES
     267        del models.ContentType._meta._related_objects_cache
     268        models.ContentType.objects.all().delete()
     269
     270    def tearDown(self):
     271        settings.INSTALLED_APPS = self.old_installed_apps
     272        super(ContentTypeDeleteTests, self).tearDown()
     273
     274
Back to Top