Skip to content

Commit

Permalink
Fixed #18408 -- Isolated flatpages tests from existing sites.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jens Page authored and claudep committed May 31, 2012
1 parent ea4e0aa commit ba10be7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ answer newbie questions, and generally made Django that much better:
Christian Oudard <christian.oudard@gmail.com>
oggie rob <oz.robharvey@gmail.com>
oggy <ognjen.maric@gmail.com>
Jens Page
Jay Parlar <parlar@gmail.com>
Carlos Eduardo de Paula <carlosedp@gmail.com>
John Paulett <john@paulett.org>
Expand Down
11 changes: 11 additions & 0 deletions django/contrib/flatpages/fixtures/example_site.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"pk": 1,
"model": "sites.site",
"fields": {
"domain": "example.com",
"name": "example.com"
}
}
]

3 changes: 2 additions & 1 deletion django/contrib/flatpages/tests/csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion django/contrib/flatpages/tests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.')]})

12 changes: 7 additions & 5 deletions django/contrib/flatpages/tests/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions django/contrib/flatpages/tests/templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TEMPLATE_DIRS=(
os.path.join(os.path.dirname(__file__), 'templates'),
),
SITE_ID=1,
)
class FlatpageTemplateTagTests(TestCase):
fixtures = ['sample_flatpages']
Expand Down
8 changes: 5 additions & 3 deletions django/contrib/flatpages/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit ba10be7

Please sign in to comment.