Commit 844bbd4a by Luke Plant

Pulled out some useful base classes for test cases

parent 13502c67
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
class WebTestBase(TestCase):
def setUp(self):
super(TestCase, self).setUp()
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret')
self.c = c = Client()
c.login(username='admin', password='secret')
class ArticleTestBase(WebTestBase):
"""Base class for web client tests, that sets up initial root article."""
def setUp(self):
super(ArticleTestBase, self).setUp()
response = self.c.post(reverse('wiki:root_create'), {'content': 'root article content', 'title': 'Root Article'}, follow=True)
self.assertEqual(response.status_code, 200) # sanity check
self.example_data = {
'content': 'The modified text',
'current_revision': '1',
'preview': '1',
#'save': '1', # probably not too important
'summary': 'why edited',
'title': 'wiki test'}
def tearDown(self):
super(ArticleTestBase, self).tearDown()
# clear Article cache before the next test
from wiki.models import Article
Article.objects.all().delete()
def get_by_path(self, path):
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
"""
return self.c.get(reverse('wiki:get', kwargs={'path': path}))
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
from __future__ import absolute_import from __future__ import absolute_import
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
import pprint import pprint
class InitialWebClientTest(TestCase): from .base import ArticleTestBase, WebTestBase
"""Tests by the dummy web client, with manual creating the root article."""
def setUp(self):
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret') class RootArticleViewTests(WebTestBase):
self.c = c = Client() """Tests for creating/viewing the root article."""
c.login(username='admin', password='secret')
def test_root_article(self): def test_root_article(self):
"""Test redirecting to /create-root/, creating the root article and a simple markup.""" """Test redirecting to /create-root/, creating the root article and a simple markup."""
...@@ -33,36 +23,10 @@ class InitialWebClientTest(TestCase): ...@@ -33,36 +23,10 @@ class InitialWebClientTest(TestCase):
self.assertContains(response, 'test heading h1</h1>') self.assertContains(response, 'test heading h1</h1>')
class WebClientTest(TestCase): class ArticleViewTests(ArticleTestBase):
"""Tests by the dummy web client.""" """
def setUp(self): Tests for article views, assuming a root article already created.
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret')
self.c = c = Client()
c.login(username='admin', password='secret')
response = self.c.post(reverse('wiki:root_create'), {'content': 'root article content', 'title': 'Root Article'})
self.example_data = {
'content': 'The modified text',
'current_revision': '1',
'preview': '1',
#'save': '1', # probably not too important
'summary': 'why edited',
'title': 'wiki test'}
def tearDown(self):
# clear Article cache before the next test
from wiki.models import Article
Article.objects.all().delete()
def get_by_path(self, path):
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
""" """
return self.c.get(reverse('wiki:get', kwargs={'path': path}))
def dump_db_status(self, message=''): def dump_db_status(self, message=''):
"""Debug printing of the complete important database content.""" """Debug printing of the complete important database content."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment