Skip to content

Commit

Permalink
Fixed tests to work with all Django versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartTC committed Nov 25, 2016
1 parent 5db9d2e commit 6035237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 6 additions & 0 deletions wakawaka/tests/test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

# Django 1.8/1.9 Middleware style
from django import get_version
from distutils.version import StrictVersion
if StrictVersion(get_version()) < StrictVersion('1.10'):
MIDDLEWARE_CLASSES = MIDDLEWARE

ROOT_URLCONF = 'wakawaka.tests.test_project.urls'

TEMPLATES = [
Expand Down
17 changes: 8 additions & 9 deletions wakawaka/tests/test_wakawaka.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class WakaWakaTestCase(testcases.TestCase):
"""
General integrity tests around the project.
"""
def create_superuser(self, username='superuser', password='foobar'):
return User.objects.create_superuser(
username, '{}@example.com'.format(username), password)
def login_superuser(self, create=True, username='superuser', password='foobar'):
if create:
User.objects.create_superuser(
username, '{}@example.com'.format(username), password)
self.client.login(username=username, password=password)

def test_calling_home_redircts_to_wikiindex(self):
"""
Expand Down Expand Up @@ -49,8 +51,7 @@ def test_if_user_logged_in_page_form_is_displayed(self):
"""
If a user is logged in, we redirect to a Create Page form.
"""
user = self.create_superuser()
self.client.force_login(user)
user = self.login_superuser()

# Calling /WikiIndex/ will result in a redirect to /edit/
response = self.client.get(reverse('wakawaka_index'), follow=True)
Expand All @@ -63,8 +64,7 @@ def test_pageform_invalid(self):
At a bare minimum, the PageForm needs a 'content' field. Otherwise
the form is displayed again, having errors.
"""
user = self.create_superuser()
self.client.force_login(user)
user = self.login_superuser()

data = {}
edit_url = reverse('wakawaka_edit', kwargs={'slug': 'WikiIndex'})
Expand All @@ -80,8 +80,7 @@ def test_pageform_valid(self):
content = 'This is the content of the new WikiIndex page'
formatted = '<p>This is the content of the new <a href="/WikiIndex/">WikiIndex</a> page</p>'

user = self.create_superuser()
self.client.force_login(user)
self.login_superuser()

data = {'content': content}
edit_url = reverse('wakawaka_edit', kwargs={'slug': 'WikiIndex'})
Expand Down

0 comments on commit 6035237

Please sign in to comment.