diff --git a/MANIFEST.in b/MANIFEST.in index be49755e0f..03464ceff1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -21,8 +21,6 @@ recursive-include django/contrib/admindocs/templates * recursive-include django/contrib/auth/fixtures * recursive-include django/contrib/auth/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/static * recursive-include django/contrib/gis/templates * diff --git a/django/contrib/flatpages/tests/templates/404.html b/django/contrib/flatpages/tests/templates/404.html deleted file mode 100644 index cbfff0cf2f..0000000000 --- a/django/contrib/flatpages/tests/templates/404.html +++ /dev/null @@ -1 +0,0 @@ -
Isn't it special!
") +@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'}) @override_settings( APPEND_SLASH=True, LOGIN_URL='/accounts/login/', @@ -95,7 +94,7 @@ class FlatpageMiddlewareTests(TestCase): 'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', ], - ROOT_URLCONF='django.contrib.flatpages.tests.urls', + ROOT_URLCONF='flatpages_tests.urls', TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) diff --git a/django/contrib/flatpages/tests/test_models.py b/tests/flatpages_tests/test_models.py similarity index 100% rename from django/contrib/flatpages/tests/test_models.py rename to tests/flatpages_tests/test_models.py diff --git a/django/contrib/flatpages/tests/test_sitemaps.py b/tests/flatpages_tests/test_sitemaps.py similarity index 87% rename from django/contrib/flatpages/tests/test_sitemaps.py rename to tests/flatpages_tests/test_sitemaps.py index dcfbef4e29..5be4fe518a 100644 --- a/django/contrib/flatpages/tests/test_sitemaps.py +++ b/tests/flatpages_tests/test_sitemaps.py @@ -7,10 +7,14 @@ from django.test.utils import modify_settings, override_settings @override_settings( - ROOT_URLCONF='django.contrib.flatpages.tests.urls', + ROOT_URLCONF='flatpages_tests.urls', 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): @classmethod diff --git a/django/contrib/flatpages/tests/test_templatetags.py b/tests/flatpages_tests/test_templatetags.py similarity index 96% rename from django/contrib/flatpages/tests/test_templatetags.py rename to tests/flatpages_tests/test_templatetags.py index 209332b79c..de88890e11 100644 --- a/django/contrib/flatpages/tests/test_templatetags.py +++ b/tests/flatpages_tests/test_templatetags.py @@ -1,11 +1,11 @@ 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.test import TestCase, override_settings +from django.test import TestCase, modify_settings, override_settings from .settings import FLATPAGES_TEMPLATES +@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'}) @override_settings( MIDDLEWARE_CLASSES=[ 'django.middleware.common.CommonMiddleware', @@ -15,7 +15,7 @@ from .settings import FLATPAGES_TEMPLATES 'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', ], - ROOT_URLCONF='django.contrib.flatpages.tests.urls', + ROOT_URLCONF='flatpages_tests.urls', TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) @@ -46,7 +46,6 @@ class FlatpageTemplateTagTests(TestCase): })) self.assertEqual(out, "A Flatpage,A Nested Flatpage,") - @skipIfCustomUser def test_get_flatpages_tag_for_user(self): "The flatpage template tag retrives all flatpages for an authenticated user" me = User.objects.create_user('testuser', 'test@example.com', 's3krit') @@ -85,7 +84,6 @@ class FlatpageTemplateTagTests(TestCase): })) self.assertEqual(out, "A Nested Flatpage,") - @skipIfCustomUser def test_get_flatpages_with_prefix_for_user(self): "The flatpage template tag retrieve prefixed flatpages for an authenticated user" me = User.objects.create_user('testuser', 'test@example.com', 's3krit') diff --git a/django/contrib/flatpages/tests/test_views.py b/tests/flatpages_tests/test_views.py similarity index 94% rename from django/contrib/flatpages/tests/test_views.py rename to tests/flatpages_tests/test_views.py index 26c071c311..7582a7284a 100644 --- a/django/contrib/flatpages/tests/test_views.py +++ b/tests/flatpages_tests/test_views.py @@ -1,12 +1,12 @@ from django.conf import settings from django.contrib.auth.models import User -from django.contrib.auth.tests.utils import skipIfCustomUser 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 +@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'}) @override_settings( LOGIN_URL='/accounts/login/', MIDDLEWARE_CLASSES=[ @@ -17,7 +17,7 @@ from .settings import FLATPAGES_TEMPLATES 'django.contrib.messages.middleware.MessageMiddleware', # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' ], - ROOT_URLCONF='django.contrib.flatpages.tests.urls', + ROOT_URLCONF='flatpages_tests.urls', TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) @@ -35,7 +35,6 @@ class FlatpageViewTests(TestCase): response = self.client.get('/flatpage_root/no_such_flatpage/') self.assertEqual(response.status_code, 404) - @skipIfCustomUser def test_view_authenticated_flatpage(self): "A flatpage served through a view can require authentication" response = self.client.get('/flatpage_root/sekrit/') @@ -72,6 +71,7 @@ class FlatpageViewTests(TestCase): self.assertContains(response, "Isn't it special!
") +@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'}) @override_settings( APPEND_SLASH=True, LOGIN_URL='/accounts/login/', @@ -83,7 +83,7 @@ class FlatpageViewTests(TestCase): 'django.contrib.messages.middleware.MessageMiddleware', # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' ], - ROOT_URLCONF='django.contrib.flatpages.tests.urls', + ROOT_URLCONF='flatpages_tests.urls', TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) diff --git a/django/contrib/flatpages/tests/urls.py b/tests/flatpages_tests/urls.py similarity index 100% rename from django/contrib/flatpages/tests/urls.py rename to tests/flatpages_tests/urls.py diff --git a/tests/runtests.py b/tests/runtests.py index fe3049dfa4..1bb3c5699e 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -60,6 +60,14 @@ ALWAYS_MIDDLEWARE_CLASSES = [ '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(): modules = [] @@ -140,6 +148,7 @@ def setup(verbosity, test_labels): # us skip creating migrations for the test models. 'auth': 'django.contrib.auth.tests.migrations', 'contenttypes': 'django.contrib.contenttypes.tests.migrations', + 'flatpages_tests': 'django.contrib.flatpages.migrations', } if verbosity > 0: @@ -189,6 +198,9 @@ def setup(verbosity, test_labels): module_label == label or module_label.startswith(label + '.') 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 verbosity >= 2: print("Importing application %s" % module_name)