mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #25746 -- Isolated inlined test models registration.
Thanks to Tim for the review.
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.managers import CurrentSiteManager
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core import checks
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.test.utils import isolate_apps
|
||||
|
||||
from .models import (
|
||||
AbstractArticle, CustomArticle, ExclusiveArticle, SyndicatedArticle,
|
||||
)
|
||||
from .models import CustomArticle, ExclusiveArticle, SyndicatedArticle
|
||||
|
||||
|
||||
class SitesFrameworkTestCase(TestCase):
|
||||
@@ -16,13 +14,6 @@ class SitesFrameworkTestCase(TestCase):
|
||||
Site.objects.get_or_create(id=settings.SITE_ID, domain="example.com", name="example.com")
|
||||
Site.objects.create(id=settings.SITE_ID + 1, domain="example2.com", name="example2.com")
|
||||
|
||||
self._old_models = apps.app_configs['sites_framework'].models.copy()
|
||||
|
||||
def tearDown(self):
|
||||
apps.app_configs['sites_framework'].models = self._old_models
|
||||
apps.all_models['sites_framework'] = self._old_models
|
||||
apps.clear_cache()
|
||||
|
||||
def test_site_fk(self):
|
||||
article = ExclusiveArticle.objects.create(title="Breaking News!", site_id=settings.SITE_ID)
|
||||
self.assertEqual(ExclusiveArticle.on_site.all().get(), article)
|
||||
@@ -42,12 +33,12 @@ class SitesFrameworkTestCase(TestCase):
|
||||
)
|
||||
self.assertEqual(CustomArticle.on_site.all().get(), article)
|
||||
|
||||
|
||||
@isolate_apps('sites_framework')
|
||||
class CurrentSiteManagerChecksTests(SimpleTestCase):
|
||||
|
||||
def test_invalid_name(self):
|
||||
|
||||
class InvalidArticle(AbstractArticle):
|
||||
site = models.ForeignKey(Site, models.CASCADE)
|
||||
|
||||
objects = models.Manager()
|
||||
class InvalidArticle(models.Model):
|
||||
on_site = CurrentSiteManager("places_this_article_should_appear")
|
||||
|
||||
errors = InvalidArticle.check()
|
||||
@@ -64,8 +55,9 @@ class SitesFrameworkTestCase(TestCase):
|
||||
|
||||
def test_invalid_field_type(self):
|
||||
|
||||
class ConfusedArticle(AbstractArticle):
|
||||
class ConfusedArticle(models.Model):
|
||||
site = models.IntegerField()
|
||||
on_site = CurrentSiteManager()
|
||||
|
||||
errors = ConfusedArticle.check()
|
||||
expected = [
|
||||
|
||||
Reference in New Issue
Block a user