Commit d11a036c by benjaoming

initial tests for custom queryset methods

parent f2c2d4d2
......@@ -4,7 +4,9 @@ from django.test.client import Client
from wiki.models import URLPath
class WebTestBase(TestCase):
def setUp(self):
super(TestCase, self).setUp()
try:
......@@ -12,28 +14,36 @@ class WebTestBase(TestCase):
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret')
self.superuser1 = 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
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.root_article = URLPath.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'}
'content': 'The modified text',
'current_revision': '1',
'preview': '1',
# 'save': '1', # probably not too important
'summary': 'why edited',
'title': 'wiki test'}
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}))
return self.c.get(reverse('wiki:get', kwargs={'path': path}))
\ No newline at end of file
......@@ -8,6 +8,23 @@ import pprint
from .base import ArticleTestBase, WebTestBase
from wiki import models
class ModelTests(ArticleTestBase):
"""Tests basic model and queryset functionalities"""
def test_custom_querysets(self):
"""
Tests that the custom queryset methods work, this is important
because the pattern of building them is different from Django
1.5 to 1.6 to 1.7 so there will be 3 patterns in play at the
same time.
"""
self.assertEqual(models.Article.objects.can_read(self.superuser1).count(), 1)
self.assertEqual(models.Article.objects.can_write(self.superuser1).count(), 1)
self.assertEqual(models.Article.objects.active().count(), 1)
class RootArticleViewTests(WebTestBase):
......
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