diff options
author | Josh Smeaton <josh.smeaton@gmail.com> | 2015-02-23 11:53:57 +1100 |
---|---|---|
committer | Josh Smeaton <josh.smeaton@gmail.com> | 2015-03-05 10:10:32 +1100 |
commit | 39a7eed1bbf12020a077e4bec3d82e08f171a021 (patch) | |
tree | 225be14a94d57517d9de646569498eb45d0a4352 /tests/flatpages_tests | |
parent | d6969abf239d52f6dfed7384c6ceb7df7e618342 (diff) | |
download | django-39a7eed1bbf12020a077e4bec3d82e08f171a021.tar.gz |
Converted test fixtures to setUpTestData methods
Diffstat (limited to 'tests/flatpages_tests')
-rw-r--r-- | tests/flatpages_tests/fixtures/example_site.json | 11 | ||||
-rw-r--r-- | tests/flatpages_tests/fixtures/sample_flatpages.json | 63 | ||||
-rw-r--r-- | tests/flatpages_tests/test_csrf.py | 30 | ||||
-rw-r--r-- | tests/flatpages_tests/test_forms.py | 8 | ||||
-rw-r--r-- | tests/flatpages_tests/test_middleware.py | 37 | ||||
-rw-r--r-- | tests/flatpages_tests/test_templatetags.py | 30 | ||||
-rw-r--r-- | tests/flatpages_tests/test_views.py | 37 |
7 files changed, 131 insertions, 85 deletions
diff --git a/tests/flatpages_tests/fixtures/example_site.json b/tests/flatpages_tests/fixtures/example_site.json deleted file mode 100644 index 71aa84de12..0000000000 --- a/tests/flatpages_tests/fixtures/example_site.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "pk": 1, - "model": "sites.site", - "fields": { - "domain": "example.com", - "name": "example.com" - } - } -] - diff --git a/tests/flatpages_tests/fixtures/sample_flatpages.json b/tests/flatpages_tests/fixtures/sample_flatpages.json deleted file mode 100644 index 885af1eb60..0000000000 --- a/tests/flatpages_tests/fixtures/sample_flatpages.json +++ /dev/null @@ -1,63 +0,0 @@ -[ - { - "pk": 1, - "model": "flatpages.flatpage", - "fields": { - "registration_required": false, - "title": "A Flatpage", - "url": "/flatpage/", - "template_name": "", - "sites": [ - 1 - ], - "content": "Isn't it flat!", - "enable_comments": false - } - }, - { - "pk": 2, - "model": "flatpages.flatpage", - "fields": { - "registration_required": false, - "title": "A Nested Flatpage", - "url": "/location/flatpage/", - "template_name": "", - "sites": [ - 1 - ], - "content": "Isn't it flat and deep!", - "enable_comments": false - } - }, - - { - "pk": 101, - "model": "flatpages.flatpage", - "fields": { - "registration_required": true, - "title": "Sekrit Flatpage", - "url": "/sekrit/", - "template_name": "", - "sites": [ - 1 - ], - "content": "Isn't it sekrit!", - "enable_comments": false - } - }, - { - "pk": 102, - "model": "flatpages.flatpage", - "fields": { - "registration_required": true, - "title": "Sekrit Nested Flatpage", - "url": "/location/sekrit/", - "template_name": "", - "sites": [ - 1 - ], - "content": "Isn't it sekrit and deep!", - "enable_comments": false - } - } -]
\ No newline at end of file diff --git a/tests/flatpages_tests/test_csrf.py b/tests/flatpages_tests/test_csrf.py index a3dd8d2cdd..5ce77dbe79 100644 --- a/tests/flatpages_tests/test_csrf.py +++ b/tests/flatpages_tests/test_csrf.py @@ -1,4 +1,6 @@ from django.contrib.auth.models import User +from django.contrib.flatpages.models import FlatPage +from django.contrib.sites.models import Site from django.test import Client, TestCase, modify_settings, override_settings from .settings import FLATPAGES_TEMPLATES @@ -21,7 +23,33 @@ from .settings import FLATPAGES_TEMPLATES SITE_ID=1, ) class FlatpageCSRFTests(TestCase): - fixtures = ['sample_flatpages', 'example_site'] + + @classmethod + def setUpTestData(cls): + # don't use the manager because we want to ensure the site exists + # with pk=1, regardless of whether or not it already exists. + cls.site1 = Site(pk=1, domain='example.com', name='example.com') + cls.site1.save() + cls.fp1 = FlatPage.objects.create( + url='/flatpage/', title='A Flatpage', content="Isn't it flat!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp2 = FlatPage.objects.create( + url='/location/flatpage/', title='A Nested Flatpage', content="Isn't it flat and deep!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp3 = FlatPage.objects.create( + url='/sekrit/', title='Sekrit Flatpage', content="Isn't it sekrit!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp4 = FlatPage.objects.create( + url='/location/sekrit/', title='Sekrit Nested Flatpage', content="Isn't it sekrit and deep!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp1.sites.add(cls.site1) + cls.fp2.sites.add(cls.site1) + cls.fp3.sites.add(cls.site1) + cls.fp4.sites.add(cls.site1) def setUp(self): self.client = Client(enforce_csrf_checks=True) diff --git a/tests/flatpages_tests/test_forms.py b/tests/flatpages_tests/test_forms.py index 8f05d8562b..6e6721494b 100644 --- a/tests/flatpages_tests/test_forms.py +++ b/tests/flatpages_tests/test_forms.py @@ -11,7 +11,13 @@ from django.utils import translation @modify_settings(INSTALLED_APPS={'append': ['django.contrib.flatpages', ]}) @override_settings(SITE_ID=1) class FlatpageAdminFormTests(TestCase): - fixtures = ['example_site'] + + @classmethod + def setUpTestData(cls): + # don't use the manager because we want to ensure the site exists + # with pk=1, regardless of whether or not it already exists. + cls.site1 = Site(pk=1, domain='example.com', name='example.com') + cls.site1.save() def setUp(self): # Site fields cache needs to be cleared after flatpages is added to diff --git a/tests/flatpages_tests/test_middleware.py b/tests/flatpages_tests/test_middleware.py index 26267036b2..c6b040775e 100644 --- a/tests/flatpages_tests/test_middleware.py +++ b/tests/flatpages_tests/test_middleware.py @@ -1,11 +1,42 @@ from django.conf import settings from django.contrib.auth.models import User from django.contrib.flatpages.models import FlatPage +from django.contrib.sites.models import Site from django.test import TestCase, modify_settings, override_settings from .settings import FLATPAGES_TEMPLATES +class TestDataMixin(object): + + @classmethod + def setUpTestData(cls): + # don't use the manager because we want to ensure the site exists + # with pk=1, regardless of whether or not it already exists. + cls.site1 = Site(pk=1, domain='example.com', name='example.com') + cls.site1.save() + cls.fp1 = FlatPage.objects.create( + url='/flatpage/', title='A Flatpage', content="Isn't it flat!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp2 = FlatPage.objects.create( + url='/location/flatpage/', title='A Nested Flatpage', content="Isn't it flat and deep!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp3 = FlatPage.objects.create( + url='/sekrit/', title='Sekrit Flatpage', content="Isn't it sekrit!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp4 = FlatPage.objects.create( + url='/location/sekrit/', title='Sekrit Nested Flatpage', content="Isn't it sekrit and deep!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp1.sites.add(cls.site1) + cls.fp2.sites.add(cls.site1) + cls.fp3.sites.add(cls.site1) + cls.fp4.sites.add(cls.site1) + + @modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'}) @override_settings( LOGIN_URL='/accounts/login/', @@ -21,8 +52,7 @@ from .settings import FLATPAGES_TEMPLATES TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) -class FlatpageMiddlewareTests(TestCase): - fixtures = ['sample_flatpages', 'example_site'] +class FlatpageMiddlewareTests(TestDataMixin, TestCase): def test_view_flatpage(self): "A flatpage can be served through a view, even when the middleware is in use" @@ -98,8 +128,7 @@ class FlatpageMiddlewareTests(TestCase): TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) -class FlatpageMiddlewareAppendSlashTests(TestCase): - fixtures = ['sample_flatpages', 'example_site'] +class FlatpageMiddlewareAppendSlashTests(TestDataMixin, TestCase): def test_redirect_view_flatpage(self): "A flatpage can be served through a view and should add a slash" diff --git a/tests/flatpages_tests/test_templatetags.py b/tests/flatpages_tests/test_templatetags.py index a0dd961c35..994491e1a0 100644 --- a/tests/flatpages_tests/test_templatetags.py +++ b/tests/flatpages_tests/test_templatetags.py @@ -1,4 +1,6 @@ from django.contrib.auth.models import AnonymousUser, User +from django.contrib.flatpages.models import FlatPage +from django.contrib.sites.models import Site from django.template import Context, Template, TemplateSyntaxError from django.test import TestCase, modify_settings, override_settings @@ -20,7 +22,33 @@ from .settings import FLATPAGES_TEMPLATES SITE_ID=1, ) class FlatpageTemplateTagTests(TestCase): - fixtures = ['sample_flatpages'] + + @classmethod + def setUpTestData(cls): + # don't use the manager because we want to ensure the site exists + # with pk=1, regardless of whether or not it already exists. + cls.site1 = Site(pk=1, domain='example.com', name='example.com') + cls.site1.save() + cls.fp1 = FlatPage.objects.create( + url='/flatpage/', title='A Flatpage', content="Isn't it flat!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp2 = FlatPage.objects.create( + url='/location/flatpage/', title='A Nested Flatpage', content="Isn't it flat and deep!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp3 = FlatPage.objects.create( + url='/sekrit/', title='Sekrit Flatpage', content="Isn't it sekrit!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp4 = FlatPage.objects.create( + url='/location/sekrit/', title='Sekrit Nested Flatpage', content="Isn't it sekrit and deep!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp1.sites.add(cls.site1) + cls.fp2.sites.add(cls.site1) + cls.fp3.sites.add(cls.site1) + cls.fp4.sites.add(cls.site1) def test_get_flatpages_tag(self): "The flatpage template tag retrieves unregistered prefixed flatpages by default" diff --git a/tests/flatpages_tests/test_views.py b/tests/flatpages_tests/test_views.py index 7582a7284a..4e9e38768b 100644 --- a/tests/flatpages_tests/test_views.py +++ b/tests/flatpages_tests/test_views.py @@ -1,11 +1,42 @@ from django.conf import settings from django.contrib.auth.models import User from django.contrib.flatpages.models import FlatPage +from django.contrib.sites.models import Site from django.test import TestCase, modify_settings, override_settings from .settings import FLATPAGES_TEMPLATES +class TestDataMixin(object): + + @classmethod + def setUpTestData(cls): + # don't use the manager because we want to ensure the site exists + # with pk=1, regardless of whether or not it already exists. + cls.site1 = Site(pk=1, domain='example.com', name='example.com') + cls.site1.save() + cls.fp1 = FlatPage.objects.create( + url='/flatpage/', title='A Flatpage', content="Isn't it flat!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp2 = FlatPage.objects.create( + url='/location/flatpage/', title='A Nested Flatpage', content="Isn't it flat and deep!", + enable_comments=False, template_name='', registration_required=False + ) + cls.fp3 = FlatPage.objects.create( + url='/sekrit/', title='Sekrit Flatpage', content="Isn't it sekrit!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp4 = FlatPage.objects.create( + url='/location/sekrit/', title='Sekrit Nested Flatpage', content="Isn't it sekrit and deep!", + enable_comments=False, template_name='', registration_required=True + ) + cls.fp1.sites.add(cls.site1) + cls.fp2.sites.add(cls.site1) + cls.fp3.sites.add(cls.site1) + cls.fp4.sites.add(cls.site1) + + @modify_settings(INSTALLED_APPS={'append': 'django.contrib.flatpages'}) @override_settings( LOGIN_URL='/accounts/login/', @@ -21,8 +52,7 @@ from .settings import FLATPAGES_TEMPLATES TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) -class FlatpageViewTests(TestCase): - fixtures = ['sample_flatpages', 'example_site'] +class FlatpageViewTests(TestDataMixin, TestCase): def test_view_flatpage(self): "A flatpage can be served through a view" @@ -87,8 +117,7 @@ class FlatpageViewTests(TestCase): TEMPLATES=FLATPAGES_TEMPLATES, SITE_ID=1, ) -class FlatpageViewAppendSlashTests(TestCase): - fixtures = ['sample_flatpages', 'example_site'] +class FlatpageViewAppendSlashTests(TestDataMixin, TestCase): def test_redirect_view_flatpage(self): "A flatpage can be served through a view and should add a slash" |