1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Moved contrib.flatpages tests out of contrib.

This commit is contained in:
Tim Graham 2015-02-09 19:20:39 -05:00
parent 197dd4b8f1
commit d3a725054f
17 changed files with 40 additions and 26 deletions

View File

@ -21,8 +21,6 @@ recursive-include django/contrib/admindocs/templates *
recursive-include django/contrib/auth/fixtures * recursive-include django/contrib/auth/fixtures *
recursive-include django/contrib/auth/templates * recursive-include django/contrib/auth/templates *
recursive-include django/contrib/auth/tests/templates * recursive-include django/contrib/auth/tests/templates *
recursive-include django/contrib/flatpages/fixtures *
recursive-include django/contrib/flatpages/tests/templates *
recursive-include django/contrib/gis/gdal/tests/data * recursive-include django/contrib/gis/gdal/tests/data *
recursive-include django/contrib/gis/static * recursive-include django/contrib/gis/static *
recursive-include django/contrib/gis/templates * recursive-include django/contrib/gis/templates *

View File

@ -1 +0,0 @@
<h1>Oh Noes!</h1>

View File

@ -1,10 +1,10 @@
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.tests.utils import skipIfCustomUser from django.test import Client, TestCase, modify_settings, override_settings
from django.test import Client, TestCase, override_settings
from .settings import FLATPAGES_TEMPLATES from .settings import FLATPAGES_TEMPLATES
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings( @override_settings(
LOGIN_URL='/accounts/login/', LOGIN_URL='/accounts/login/',
MIDDLEWARE_CLASSES=[ MIDDLEWARE_CLASSES=[
@ -15,7 +15,7 @@ from .settings import FLATPAGES_TEMPLATES
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
], ],
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
CSRF_FAILURE_VIEW='django.views.csrf.csrf_failure', CSRF_FAILURE_VIEW='django.views.csrf.csrf_failure',
TEMPLATES=FLATPAGES_TEMPLATES, TEMPLATES=FLATPAGES_TEMPLATES,
SITE_ID=1, SITE_ID=1,
@ -37,7 +37,6 @@ class FlatpageCSRFTests(TestCase):
response = self.client.get('/flatpage_root/no_such_flatpage/') response = self.client.get('/flatpage_root/no_such_flatpage/')
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@skipIfCustomUser
def test_view_authenticated_flatpage(self): def test_view_authenticated_flatpage(self):
"A flatpage served through a view can require authentication" "A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')

View File

@ -3,15 +3,20 @@ from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
from django.contrib.flatpages.forms import FlatpageForm from django.contrib.flatpages.forms import FlatpageForm
from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.models import FlatPage
from django.test import TestCase, override_settings from django.contrib.sites.models import Site
from django.test import TestCase, modify_settings, override_settings
from django.utils import translation from django.utils import translation
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.flatpages', ]})
@override_settings(SITE_ID=1) @override_settings(SITE_ID=1)
class FlatpageAdminFormTests(TestCase): class FlatpageAdminFormTests(TestCase):
fixtures = ['example_site'] fixtures = ['example_site']
def setUp(self): def setUp(self):
# Site fields cache needs to be cleared after flatpages is added to
# INSTALLED_APPS
Site._meta._expire_cache()
self.form_data = { self.form_data = {
'title': "A test page", 'title': "A test page",
'content': "This is a test", 'content': "This is a test",

View File

@ -1,12 +1,12 @@
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.models import FlatPage
from django.test import TestCase, override_settings from django.test import TestCase, modify_settings, override_settings
from .settings import FLATPAGES_TEMPLATES from .settings import FLATPAGES_TEMPLATES
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings( @override_settings(
LOGIN_URL='/accounts/login/', LOGIN_URL='/accounts/login/',
MIDDLEWARE_CLASSES=[ MIDDLEWARE_CLASSES=[
@ -17,7 +17,7 @@ from .settings import FLATPAGES_TEMPLATES
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
], ],
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
TEMPLATES=FLATPAGES_TEMPLATES, TEMPLATES=FLATPAGES_TEMPLATES,
SITE_ID=1, SITE_ID=1,
) )
@ -35,7 +35,6 @@ class FlatpageMiddlewareTests(TestCase):
response = self.client.get('/flatpage_root/no_such_flatpage/') response = self.client.get('/flatpage_root/no_such_flatpage/')
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@skipIfCustomUser
def test_view_authenticated_flatpage(self): def test_view_authenticated_flatpage(self):
"A flatpage served through a view can require authentication" "A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
@ -57,7 +56,6 @@ class FlatpageMiddlewareTests(TestCase):
response = self.client.get('/no_such_flatpage/') response = self.client.get('/no_such_flatpage/')
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@skipIfCustomUser
def test_fallback_authenticated_flatpage(self): def test_fallback_authenticated_flatpage(self):
"A flatpage served by the middleware can require authentication" "A flatpage served by the middleware can require authentication"
response = self.client.get('/sekrit/') response = self.client.get('/sekrit/')
@ -84,6 +82,7 @@ class FlatpageMiddlewareTests(TestCase):
self.assertContains(response, "<p>Isn't it special!</p>") self.assertContains(response, "<p>Isn't it special!</p>")
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings( @override_settings(
APPEND_SLASH=True, APPEND_SLASH=True,
LOGIN_URL='/accounts/login/', LOGIN_URL='/accounts/login/',
@ -95,7 +94,7 @@ class FlatpageMiddlewareTests(TestCase):
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
], ],
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
TEMPLATES=FLATPAGES_TEMPLATES, TEMPLATES=FLATPAGES_TEMPLATES,
SITE_ID=1, SITE_ID=1,
) )

View File

@ -7,10 +7,14 @@ from django.test.utils import modify_settings, override_settings
@override_settings( @override_settings(
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
SITE_ID=1, SITE_ID=1,
) )
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sitemaps']},) @modify_settings(
INSTALLED_APPS={
'append': ['django.contrib.sitemaps', 'django.contrib.flatpages'],
},
)
class FlatpagesSitemapTests(TestCase): class FlatpagesSitemapTests(TestCase):
@classmethod @classmethod

View File

@ -1,11 +1,11 @@
from django.contrib.auth.models import AnonymousUser, User from django.contrib.auth.models import AnonymousUser, User
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.template import Context, Template, TemplateSyntaxError from django.template import Context, Template, TemplateSyntaxError
from django.test import TestCase, override_settings from django.test import TestCase, modify_settings, override_settings
from .settings import FLATPAGES_TEMPLATES from .settings import FLATPAGES_TEMPLATES
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings( @override_settings(
MIDDLEWARE_CLASSES=[ MIDDLEWARE_CLASSES=[
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -15,7 +15,7 @@ from .settings import FLATPAGES_TEMPLATES
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
], ],
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
TEMPLATES=FLATPAGES_TEMPLATES, TEMPLATES=FLATPAGES_TEMPLATES,
SITE_ID=1, SITE_ID=1,
) )
@ -46,7 +46,6 @@ class FlatpageTemplateTagTests(TestCase):
})) }))
self.assertEqual(out, "A Flatpage,A Nested Flatpage,") self.assertEqual(out, "A Flatpage,A Nested Flatpage,")
@skipIfCustomUser
def test_get_flatpages_tag_for_user(self): def test_get_flatpages_tag_for_user(self):
"The flatpage template tag retrives all flatpages for an authenticated user" "The flatpage template tag retrives all flatpages for an authenticated user"
me = User.objects.create_user('testuser', 'test@example.com', 's3krit') me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
@ -85,7 +84,6 @@ class FlatpageTemplateTagTests(TestCase):
})) }))
self.assertEqual(out, "A Nested Flatpage,") self.assertEqual(out, "A Nested Flatpage,")
@skipIfCustomUser
def test_get_flatpages_with_prefix_for_user(self): def test_get_flatpages_with_prefix_for_user(self):
"The flatpage template tag retrieve prefixed flatpages for an authenticated user" "The flatpage template tag retrieve prefixed flatpages for an authenticated user"
me = User.objects.create_user('testuser', 'test@example.com', 's3krit') me = User.objects.create_user('testuser', 'test@example.com', 's3krit')

View File

@ -1,12 +1,12 @@
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.models import FlatPage
from django.test import TestCase, override_settings from django.test import TestCase, modify_settings, override_settings
from .settings import FLATPAGES_TEMPLATES from .settings import FLATPAGES_TEMPLATES
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings( @override_settings(
LOGIN_URL='/accounts/login/', LOGIN_URL='/accounts/login/',
MIDDLEWARE_CLASSES=[ MIDDLEWARE_CLASSES=[
@ -17,7 +17,7 @@ from .settings import FLATPAGES_TEMPLATES
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
# no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
], ],
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
TEMPLATES=FLATPAGES_TEMPLATES, TEMPLATES=FLATPAGES_TEMPLATES,
SITE_ID=1, SITE_ID=1,
) )
@ -35,7 +35,6 @@ class FlatpageViewTests(TestCase):
response = self.client.get('/flatpage_root/no_such_flatpage/') response = self.client.get('/flatpage_root/no_such_flatpage/')
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@skipIfCustomUser
def test_view_authenticated_flatpage(self): def test_view_authenticated_flatpage(self):
"A flatpage served through a view can require authentication" "A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
@ -72,6 +71,7 @@ class FlatpageViewTests(TestCase):
self.assertContains(response, "<p>Isn't it special!</p>") self.assertContains(response, "<p>Isn't it special!</p>")
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings( @override_settings(
APPEND_SLASH=True, APPEND_SLASH=True,
LOGIN_URL='/accounts/login/', LOGIN_URL='/accounts/login/',
@ -83,7 +83,7 @@ class FlatpageViewTests(TestCase):
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
# no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
], ],
ROOT_URLCONF='django.contrib.flatpages.tests.urls', ROOT_URLCONF='flatpages_tests.urls',
TEMPLATES=FLATPAGES_TEMPLATES, TEMPLATES=FLATPAGES_TEMPLATES,
SITE_ID=1, SITE_ID=1,
) )

View File

@ -60,6 +60,14 @@ ALWAYS_MIDDLEWARE_CLASSES = [
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
] ]
# Need to add the associated contrib app to INSTALLED_APPS in some cases to
# avoid "RuntimeError: Model class X doesn't declare an explicit app_label
# and either isn't in an application in INSTALLED_APPS or else was imported
# before its application was loaded."
CONTRIB_TESTS_TO_APPS = {
'flatpages_tests': 'django.contrib.flatpages',
}
def get_test_modules(): def get_test_modules():
modules = [] modules = []
@ -140,6 +148,7 @@ def setup(verbosity, test_labels):
# us skip creating migrations for the test models. # us skip creating migrations for the test models.
'auth': 'django.contrib.auth.tests.migrations', 'auth': 'django.contrib.auth.tests.migrations',
'contenttypes': 'django.contrib.contenttypes.tests.migrations', 'contenttypes': 'django.contrib.contenttypes.tests.migrations',
'flatpages_tests': 'django.contrib.flatpages.migrations',
} }
if verbosity > 0: if verbosity > 0:
@ -189,6 +198,9 @@ def setup(verbosity, test_labels):
module_label == label or module_label.startswith(label + '.') module_label == label or module_label.startswith(label + '.')
for label in test_labels_set) for label in test_labels_set)
if module_name in CONTRIB_TESTS_TO_APPS and module_found_in_labels:
settings.INSTALLED_APPS.append(CONTRIB_TESTS_TO_APPS[module_name])
if module_found_in_labels and module_label not in installed_app_names: if module_found_in_labels and module_label not in installed_app_names:
if verbosity >= 2: if verbosity >= 2:
print("Importing application %s" % module_name) print("Importing application %s" % module_name)