Normalized Model._meta.installed.
Used the information from the app cache instead of creating a duplicate based on INSTALLED_APPS. Model._meta.installed is no longer writable. It was a rather sketchy way to alter private internals anyway.
This commit is contained in:
parent
0242c56fd8
commit
7eea9bf303
|
@ -52,12 +52,13 @@ class FooWithBrokenAbsoluteUrl(FooWithoutUrl):
|
||||||
|
|
||||||
|
|
||||||
class ContentTypesTests(TestCase):
|
class ContentTypesTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_Site_meta_installed = Site._meta.installed
|
self._old_installed = Site._meta.app_config.installed
|
||||||
ContentType.objects.clear_cache()
|
ContentType.objects.clear_cache()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Site._meta.installed = self.old_Site_meta_installed
|
Site._meta.app_config.installed = self._old_installed
|
||||||
ContentType.objects.clear_cache()
|
ContentType.objects.clear_cache()
|
||||||
|
|
||||||
def test_lookup_cache(self):
|
def test_lookup_cache(self):
|
||||||
|
@ -222,12 +223,12 @@ class ContentTypesTests(TestCase):
|
||||||
user_ct = ContentType.objects.get_for_model(FooWithUrl)
|
user_ct = ContentType.objects.get_for_model(FooWithUrl)
|
||||||
obj = FooWithUrl.objects.create(name="john")
|
obj = FooWithUrl.objects.create(name="john")
|
||||||
|
|
||||||
if Site._meta.installed:
|
Site._meta.app_config.installed = True
|
||||||
response = shortcut(request, user_ct.id, obj.id)
|
response = shortcut(request, user_ct.id, obj.id)
|
||||||
self.assertEqual("http://%s/users/john/" % get_current_site(request).domain,
|
self.assertEqual("http://%s/users/john/" % get_current_site(request).domain,
|
||||||
response._headers.get("location")[1])
|
response._headers.get("location")[1])
|
||||||
|
|
||||||
Site._meta.installed = False
|
Site._meta.app_config.installed = False
|
||||||
response = shortcut(request, user_ct.id, obj.id)
|
response = shortcut(request, user_ct.id, obj.id)
|
||||||
self.assertEqual("http://Example.com/users/john/",
|
self.assertEqual("http://Example.com/users/john/",
|
||||||
response._headers.get("location")[1])
|
response._headers.get("location")[1])
|
||||||
|
|
|
@ -20,11 +20,11 @@ class GeoFeedTest(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
|
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
|
||||||
self.old_Site_meta_installed = Site._meta.installed
|
self._old_installed = Site._meta.app_config.installed
|
||||||
Site._meta.installed = True
|
Site._meta.app_config.installed = True
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Site._meta.installed = self.old_Site_meta_installed
|
Site._meta.app_config.installed = self._old_installed
|
||||||
|
|
||||||
def assertChildNodes(self, elem, expected):
|
def assertChildNodes(self, elem, expected):
|
||||||
"Taken from syndication/tests.py."
|
"Taken from syndication/tests.py."
|
||||||
|
|
|
@ -26,11 +26,11 @@ class GeoSitemapTest(IgnoreDeprecationWarningsMixin, TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(GeoSitemapTest, self).setUp()
|
super(GeoSitemapTest, self).setUp()
|
||||||
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
|
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
|
||||||
self.old_Site_meta_installed = Site._meta.installed
|
self._old_installed = Site._meta.app_config.installed
|
||||||
Site._meta.installed = True
|
Site._meta.app_config.installed = True
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Site._meta.installed = self.old_Site_meta_installed
|
Site._meta.app_config.installed = self._old_installed
|
||||||
super(GeoSitemapTest, self).tearDown()
|
super(GeoSitemapTest, self).tearDown()
|
||||||
|
|
||||||
def assertChildNodes(self, elem, expected):
|
def assertChildNodes(self, elem, expected):
|
||||||
|
|
|
@ -25,10 +25,10 @@ class SitemapTestsBase(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.base_url = '%s://%s' % (self.protocol, self.domain)
|
self.base_url = '%s://%s' % (self.protocol, self.domain)
|
||||||
self.old_Site_meta_installed = Site._meta.installed
|
self._old_installed = Site._meta.app_config.installed
|
||||||
cache.clear()
|
cache.clear()
|
||||||
# Create an object for sitemap content.
|
# Create an object for sitemap content.
|
||||||
TestModel.objects.create(name='Test Object')
|
TestModel.objects.create(name='Test Object')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Site._meta.installed = self.old_Site_meta_installed
|
Site._meta.app_config.installed = self._old_installed
|
||||||
|
|
|
@ -107,8 +107,9 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
|
|
||||||
def test_requestsite_sitemap(self):
|
def test_requestsite_sitemap(self):
|
||||||
# Make sure hitting the flatpages sitemap without the sites framework
|
# Make sure hitting the flatpages sitemap without the sites framework
|
||||||
# installed doesn't raise an exception
|
# installed doesn't raise an exception.
|
||||||
Site._meta.installed = False
|
# Reset by SitemapTestsBase.tearDown().
|
||||||
|
Site._meta.app_config.installed = False
|
||||||
response = self.client.get('/simple/sitemap.xml')
|
response = self.client.get('/simple/sitemap.xml')
|
||||||
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
@ -133,7 +134,8 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
Sitemap.get_urls if Site objects exists, but the sites framework is not
|
Sitemap.get_urls if Site objects exists, but the sites framework is not
|
||||||
actually installed.
|
actually installed.
|
||||||
"""
|
"""
|
||||||
Site._meta.installed = False
|
# Reset by SitemapTestsBase.tearDown().
|
||||||
|
Site._meta.app_config.installed = False
|
||||||
self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
|
self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
|
||||||
|
|
||||||
def test_sitemap_item(self):
|
def test_sitemap_item(self):
|
||||||
|
|
|
@ -12,11 +12,11 @@ class SitesFrameworkTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
|
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
|
||||||
self.old_Site_meta_installed = Site._meta.installed
|
self._old_installed = Site._meta.app_config.installed
|
||||||
Site._meta.installed = True
|
Site._meta.app_config.installed = True
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Site._meta.installed = self.old_Site_meta_installed
|
Site._meta.app_config.installed = self._old_installed
|
||||||
|
|
||||||
def test_save_another(self):
|
def test_save_another(self):
|
||||||
# Regression for #17415
|
# Regression for #17415
|
||||||
|
@ -67,7 +67,7 @@ class SitesFrameworkTests(TestCase):
|
||||||
self.assertRaises(ObjectDoesNotExist, get_current_site, request)
|
self.assertRaises(ObjectDoesNotExist, get_current_site, request)
|
||||||
|
|
||||||
# A RequestSite is returned if the sites framework is not installed
|
# A RequestSite is returned if the sites framework is not installed
|
||||||
Site._meta.installed = False
|
Site._meta.app_config.installed = False
|
||||||
site = get_current_site(request)
|
site = get_current_site(request)
|
||||||
self.assertTrue(isinstance(site, RequestSite))
|
self.assertTrue(isinstance(site, RequestSite))
|
||||||
self.assertEqual(site.name, "example.com")
|
self.assertEqual(site.name, "example.com")
|
||||||
|
|
|
@ -91,13 +91,21 @@ class Options(object):
|
||||||
# A custom AppCache to use, if you're making a separate model set.
|
# A custom AppCache to use, if you're making a separate model set.
|
||||||
self.app_cache = app_cache
|
self.app_cache = app_cache
|
||||||
|
|
||||||
|
@property
|
||||||
|
def app_config(self):
|
||||||
|
# Don't go through get_app_config to avoid triggering populate().
|
||||||
|
return self.app_cache.app_configs[self.app_label]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def installed(self):
|
||||||
|
return self.app_config.installed
|
||||||
|
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.backends.utils import truncate_name
|
from django.db.backends.utils import truncate_name
|
||||||
|
|
||||||
cls._meta = self
|
cls._meta = self
|
||||||
self.model = cls
|
self.model = cls
|
||||||
self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS
|
|
||||||
# First, construct the default values for these options.
|
# First, construct the default values for these options.
|
||||||
self.object_name = cls.__name__
|
self.object_name = cls.__name__
|
||||||
self.model_name = self.object_name.lower()
|
self.model_name = self.object_name.lower()
|
||||||
|
|
Loading…
Reference in New Issue