From ba10be70322027074e5f9defc1423eb0cc77473c Mon Sep 17 00:00:00 2001 From: Jens Page Date: Thu, 10 May 2012 17:09:29 -0400 Subject: [PATCH] Fixed #18408 -- Isolated flatpages tests from existing sites. Resolves Flatpages test issues by: - Creating an example_site fixture - Overriding project SITE_ID setting to 1 - Normalizing the use of the hardcoded (1) site_id to settings.SITE_ID --- AUTHORS | 1 + django/contrib/flatpages/fixtures/example_site.json | 11 +++++++++++ django/contrib/flatpages/tests/csrf.py | 3 ++- django/contrib/flatpages/tests/forms.py | 5 ++++- django/contrib/flatpages/tests/middleware.py | 12 +++++++----- django/contrib/flatpages/tests/templatetags.py | 1 + django/contrib/flatpages/tests/views.py | 8 +++++--- 7 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 django/contrib/flatpages/fixtures/example_site.json diff --git a/AUTHORS b/AUTHORS index 0e29608f75a1..45a0544e6573 100644 --- a/AUTHORS +++ b/AUTHORS @@ -401,6 +401,7 @@ answer newbie questions, and generally made Django that much better: Christian Oudard oggie rob oggy + Jens Page Jay Parlar Carlos Eduardo de Paula John Paulett diff --git a/django/contrib/flatpages/fixtures/example_site.json b/django/contrib/flatpages/fixtures/example_site.json new file mode 100644 index 000000000000..71aa84de1277 --- /dev/null +++ b/django/contrib/flatpages/fixtures/example_site.json @@ -0,0 +1,11 @@ +[ + { + "pk": 1, + "model": "sites.site", + "fields": { + "domain": "example.com", + "name": "example.com" + } + } +] + diff --git a/django/contrib/flatpages/tests/csrf.py b/django/contrib/flatpages/tests/csrf.py index a8b9c2804c4d..e64c4bb10252 100644 --- a/django/contrib/flatpages/tests/csrf.py +++ b/django/contrib/flatpages/tests/csrf.py @@ -18,9 +18,10 @@ TEMPLATE_DIRS=( os.path.join(os.path.dirname(__file__), 'templates'), ), + SITE_ID=1, ) class FlatpageCSRFTests(TestCase): - fixtures = ['sample_flatpages'] + fixtures = ['sample_flatpages', 'example_site'] urls = 'django.contrib.flatpages.tests.urls' def setUp(self): diff --git a/django/contrib/flatpages/tests/forms.py b/django/contrib/flatpages/tests/forms.py index eb37e9ec291e..0e54176aa25d 100644 --- a/django/contrib/flatpages/tests/forms.py +++ b/django/contrib/flatpages/tests/forms.py @@ -5,7 +5,10 @@ from django.test.utils import override_settings from django.utils import translation +@override_settings(SITE_ID=1) class FlatpageAdminFormTests(TestCase): + fixtures = ['example_site'] + def setUp(self): self.form_data = { 'title': "A test page", @@ -89,5 +92,5 @@ def test_flatpage_nosites(self): self.assertEqual( f.errors, - {'sites': [u'This field is required.']}) + {'sites': [translation.ugettext(u'This field is required.')]}) diff --git a/django/contrib/flatpages/tests/middleware.py b/django/contrib/flatpages/tests/middleware.py index fa9d735c0c82..4afa4ff98223 100644 --- a/django/contrib/flatpages/tests/middleware.py +++ b/django/contrib/flatpages/tests/middleware.py @@ -19,9 +19,10 @@ TEMPLATE_DIRS=( os.path.join(os.path.dirname(__file__), 'templates'), ), + SITE_ID=1, ) class FlatpageMiddlewareTests(TestCase): - fixtures = ['sample_flatpages'] + fixtures = ['sample_flatpages', 'example_site'] urls = 'django.contrib.flatpages.tests.urls' def test_view_flatpage(self): @@ -75,7 +76,7 @@ def test_fallback_flatpage_special_chars(self): enable_comments=False, registration_required=False, ) - fp.sites.add(1) + fp.sites.add(settings.SITE_ID) response = self.client.get('/some.very_special~chars-here/') self.assertEqual(response.status_code, 200) @@ -96,9 +97,10 @@ def test_fallback_flatpage_special_chars(self): TEMPLATE_DIRS=( os.path.join(os.path.dirname(__file__), 'templates'), ), + SITE_ID=1, ) class FlatpageMiddlewareAppendSlashTests(TestCase): - fixtures = ['sample_flatpages'] + fixtures = ['sample_flatpages', 'example_site'] urls = 'django.contrib.flatpages.tests.urls' def test_redirect_view_flatpage(self): @@ -130,7 +132,7 @@ def test_redirect_fallback_flatpage_special_chars(self): enable_comments=False, registration_required=False, ) - fp.sites.add(1) + fp.sites.add(settings.SITE_ID) response = self.client.get('/some.very_special~chars-here') self.assertRedirects(response, '/some.very_special~chars-here/', status_code=301) @@ -144,7 +146,7 @@ def test_redirect_fallback_flatpage_root(self): enable_comments=False, registration_required=False, ) - fp.sites.add(1) + fp.sites.add(settings.SITE_ID) response = self.client.get('/') self.assertEqual(response.status_code, 200) diff --git a/django/contrib/flatpages/tests/templatetags.py b/django/contrib/flatpages/tests/templatetags.py index de6a0a90fbc2..aebc62277e6e 100644 --- a/django/contrib/flatpages/tests/templatetags.py +++ b/django/contrib/flatpages/tests/templatetags.py @@ -18,6 +18,7 @@ TEMPLATE_DIRS=( os.path.join(os.path.dirname(__file__), 'templates'), ), + SITE_ID=1, ) class FlatpageTemplateTagTests(TestCase): fixtures = ['sample_flatpages'] diff --git a/django/contrib/flatpages/tests/views.py b/django/contrib/flatpages/tests/views.py index 997bfabec865..b69bd6abb426 100644 --- a/django/contrib/flatpages/tests/views.py +++ b/django/contrib/flatpages/tests/views.py @@ -19,9 +19,10 @@ TEMPLATE_DIRS=( os.path.join(os.path.dirname(__file__), 'templates'), ), + SITE_ID=1, ) class FlatpageViewTests(TestCase): - fixtures = ['sample_flatpages'] + fixtures = ['sample_flatpages', 'example_site'] urls = 'django.contrib.flatpages.tests.urls' def test_view_flatpage(self): @@ -85,9 +86,10 @@ def test_view_flatpage_special_chars(self): TEMPLATE_DIRS=( os.path.join(os.path.dirname(__file__), 'templates'), ), + SITE_ID=1, ) class FlatpageViewAppendSlashTests(TestCase): - fixtures = ['sample_flatpages'] + fixtures = ['sample_flatpages', 'example_site'] urls = 'django.contrib.flatpages.tests.urls' def test_redirect_view_flatpage(self): @@ -119,7 +121,7 @@ def test_redirect_view_flatpage_special_chars(self): enable_comments=False, registration_required=False, ) - fp.sites.add(1) + fp.sites.add(settings.SITE_ID) response = self.client.get('/flatpage_root/some.very_special~chars-here') self.assertRedirects(response, '/flatpage_root/some.very_special~chars-here/', status_code=301)