Skip to content

Commit

Permalink
Moved contrib.flatpages tests out of contrib.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Feb 11, 2015
1 parent 197dd4b commit d3a7250
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 26 deletions.
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
1 change: 0 additions & 1 deletion django/contrib/flatpages/tests/templates/404.html

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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=[
Expand All @@ -15,7 +15,7 @@
'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,
Expand All @@ -37,7 +37,6 @@ def test_view_non_existent_flatpage(self):
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/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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=[
Expand All @@ -17,7 +17,7 @@
'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,
)
Expand All @@ -35,7 +35,6 @@ def test_view_non_existent_flatpage(self):
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/')
Expand All @@ -57,7 +56,6 @@ def test_fallback_non_existent_flatpage(self):
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/')
Expand All @@ -84,6 +82,7 @@ def test_fallback_flatpage_special_chars(self):
self.assertContains(response, "<p>Isn't it special!</p>")


@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings(
APPEND_SLASH=True,
LOGIN_URL='/accounts/login/',
Expand All @@ -95,7 +94,7 @@ def test_fallback_flatpage_special_chars(self):
'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,
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@


@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -15,7 +15,7 @@
'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,
)
Expand Down Expand Up @@ -46,7 +46,6 @@ def test_get_flatpages_tag_for_anon_user(self):
}))
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', '[email protected]', 's3krit')
Expand Down Expand Up @@ -85,7 +84,6 @@ def test_get_flatpages_with_prefix_for_anon_user(self):
}))
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', '[email protected]', 's3krit')
Expand Down
Original file line number Diff line number Diff line change
@@ -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=[
Expand All @@ -17,7 +17,7 @@
'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,
)
Expand All @@ -35,7 +35,6 @@ def test_view_non_existent_flatpage(self):
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/')
Expand Down Expand Up @@ -72,6 +71,7 @@ def test_view_flatpage_special_chars(self):
self.assertContains(response, "<p>Isn't it special!</p>")


@modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'})
@override_settings(
APPEND_SLASH=True,
LOGIN_URL='/accounts/login/',
Expand All @@ -83,7 +83,7 @@ def test_view_flatpage_special_chars(self):
'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,
)
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
'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 = []
Expand Down Expand Up @@ -140,6 +148,7 @@ def no_available_apps(self):
# 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:
Expand Down Expand Up @@ -189,6 +198,9 @@ def no_available_apps(self):
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)
Expand Down

0 comments on commit d3a7250

Please sign in to comment.