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 @@ -

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 f8616b3913..a3dd8d2cdd 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 09f500c6ae..8f05d8562b 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 f132aa07ac..26267036b2 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 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)