From 36bf6ec9eb8a3ef4e24d3a6374780603f5bbdf97 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 9 Feb 2015 19:20:39 -0500 Subject: [PATCH] [1.8.x] Moved contrib.flatpages tests out of contrib. Backport of d3a725054fa260e84c788b240fd03cbd0ccc1151 from master --- MANIFEST.in | 2 -- django/contrib/flatpages/tests/templates/404.html | 1 - .../tests => tests/flatpages_tests}/__init__.py | 0 .../flatpages_tests}/fixtures/example_site.json | 0 .../flatpages_tests}/fixtures/sample_flatpages.json | 0 .../tests => tests/flatpages_tests}/settings.py | 0 .../templates/flatpages/default.html | 0 .../templates/registration/login.html | 0 .../tests => tests/flatpages_tests}/test_csrf.py | 7 +++---- .../tests => tests/flatpages_tests}/test_forms.py | 7 ++++++- .../flatpages_tests}/test_middleware.py | 11 +++++------ .../tests => tests/flatpages_tests}/test_models.py | 0 .../tests => tests/flatpages_tests}/test_sitemaps.py | 8 ++++++-- .../flatpages_tests}/test_templatetags.py | 8 +++----- .../tests => tests/flatpages_tests}/test_views.py | 10 +++++----- .../tests => tests/flatpages_tests}/urls.py | 0 tests/runtests.py | 12 ++++++++++++ 17 files changed, 40 insertions(+), 26 deletions(-) delete mode 100644 django/contrib/flatpages/tests/templates/404.html rename {django/contrib/flatpages/tests => tests/flatpages_tests}/__init__.py (100%) rename {django/contrib/flatpages => tests/flatpages_tests}/fixtures/example_site.json (100%) rename {django/contrib/flatpages => tests/flatpages_tests}/fixtures/sample_flatpages.json (100%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/settings.py (100%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/templates/flatpages/default.html (100%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/templates/registration/login.html (100%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_csrf.py (94%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_forms.py (92%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_middleware.py (95%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_models.py (100%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_sitemaps.py (87%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_templatetags.py (96%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/test_views.py (94%) rename {django/contrib/flatpages/tests => tests/flatpages_tests}/urls.py (100%) diff --git a/MANIFEST.in b/MANIFEST.in index be49755e0fe..03464ceff17 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 cbfff0cf2f0..00000000000 --- a/django/contrib/flatpages/tests/templates/404.html +++ /dev/null @@ -1 +0,0 @@ -

Oh Noes!

diff --git a/django/contrib/flatpages/tests/__init__.py b/tests/flatpages_tests/__init__.py similarity index 100% rename from django/contrib/flatpages/tests/__init__.py rename to tests/flatpages_tests/__init__.py diff --git a/django/contrib/flatpages/fixtures/example_site.json b/tests/flatpages_tests/fixtures/example_site.json similarity index 100% rename from django/contrib/flatpages/fixtures/example_site.json rename to tests/flatpages_tests/fixtures/example_site.json diff --git a/django/contrib/flatpages/fixtures/sample_flatpages.json b/tests/flatpages_tests/fixtures/sample_flatpages.json similarity index 100% rename from django/contrib/flatpages/fixtures/sample_flatpages.json rename to tests/flatpages_tests/fixtures/sample_flatpages.json diff --git a/django/contrib/flatpages/tests/settings.py b/tests/flatpages_tests/settings.py similarity index 100% rename from django/contrib/flatpages/tests/settings.py rename to tests/flatpages_tests/settings.py diff --git a/django/contrib/flatpages/tests/templates/flatpages/default.html b/tests/flatpages_tests/templates/flatpages/default.html similarity index 100% rename from django/contrib/flatpages/tests/templates/flatpages/default.html rename to tests/flatpages_tests/templates/flatpages/default.html diff --git a/django/contrib/flatpages/tests/templates/registration/login.html b/tests/flatpages_tests/templates/registration/login.html similarity index 100% rename from django/contrib/flatpages/tests/templates/registration/login.html rename to tests/flatpages_tests/templates/registration/login.html diff --git a/django/contrib/flatpages/tests/test_csrf.py b/tests/flatpages_tests/test_csrf.py similarity index 94% rename from django/contrib/flatpages/tests/test_csrf.py rename to tests/flatpages_tests/test_csrf.py index e661b12c7a8..d45ef34d2bb 100644 --- a/django/contrib/flatpages/tests/test_csrf.py +++ b/tests/flatpages_tests/test_csrf.py @@ -1,10 +1,10 @@ from django.contrib.auth.models import User -from django.contrib.auth.tests.utils import skipIfCustomUser -from django.test import Client, TestCase, override_settings +from django.test import Client, 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=( @@ -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', CSRF_FAILURE_VIEW='django.views.csrf.csrf_failure', TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, @@ -37,7 +37,6 @@ class FlatpageCSRFTests(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/') diff --git a/django/contrib/flatpages/tests/test_forms.py b/tests/flatpages_tests/test_forms.py similarity index 92% rename from django/contrib/flatpages/tests/test_forms.py rename to tests/flatpages_tests/test_forms.py index 8a6db742fa8..0ad817f15b7 100644 --- a/django/contrib/flatpages/tests/test_forms.py +++ b/tests/flatpages_tests/test_forms.py @@ -3,15 +3,20 @@ from __future__ import unicode_literals from django.conf import settings from django.contrib.flatpages.forms import FlatpageForm 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 +@modify_settings(INSTALLED_APPS={'append': ['django.contrib.flatpages', ]}) @override_settings(SITE_ID=1) class FlatpageAdminFormTests(TestCase): fixtures = ['example_site'] def setUp(self): + # Site fields cache needs to be cleared after flatpages is added to + # INSTALLED_APPS + Site._meta._expire_cache() self.form_data = { 'title': "A test page", 'content': "This is a test", diff --git a/django/contrib/flatpages/tests/test_middleware.py b/tests/flatpages_tests/test_middleware.py similarity index 95% rename from django/contrib/flatpages/tests/test_middleware.py rename to tests/flatpages_tests/test_middleware.py index 0e8415b0751..2bb29e09903 100644 --- a/django/contrib/flatpages/tests/test_middleware.py +++ b/tests/flatpages_tests/test_middleware.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', '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 FlatpageMiddlewareTests(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/') @@ -57,7 +56,6 @@ class FlatpageMiddlewareTests(TestCase): response = self.client.get('/no_such_flatpage/') self.assertEqual(response.status_code, 404) - @skipIfCustomUser def test_fallback_authenticated_flatpage(self): "A flatpage served by the middleware can require authentication" response = self.client.get('/sekrit/') @@ -84,6 +82,7 @@ class FlatpageMiddlewareTests(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/', @@ -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 dcfbef4e29e..5be4fe518a2 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 21d90da32eb..5f83c9e0303 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 b6fb25f9c3b..d7ce1c0c220 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 796b27c2bb8..3616d019e98 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 = [] @@ -142,6 +150,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: @@ -191,6 +200,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)