Commit d11a036c by benjaoming

initial tests for custom queryset methods

parent f2c2d4d2
...@@ -4,7 +4,9 @@ from django.test.client import Client ...@@ -4,7 +4,9 @@ from django.test.client import Client
from wiki.models import URLPath from wiki.models import URLPath
class WebTestBase(TestCase): class WebTestBase(TestCase):
def setUp(self): def setUp(self):
super(TestCase, self).setUp() super(TestCase, self).setUp()
try: try:
...@@ -12,28 +14,36 @@ class WebTestBase(TestCase): ...@@ -12,28 +14,36 @@ class WebTestBase(TestCase):
User = get_user_model() User = get_user_model()
except ImportError: except ImportError:
from django.contrib.auth.models import User 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() self.c = c = Client()
c.login(username='admin', password='secret') c.login(username='admin', password='secret')
class ArticleTestBase(WebTestBase): class ArticleTestBase(WebTestBase):
"""Base class for web client tests, that sets up initial root article.""" """Base class for web client tests, that sets up initial root article."""
def setUp(self): def setUp(self):
super(ArticleTestBase, self).setUp() super(ArticleTestBase, self).setUp()
response = self.c.post(reverse('wiki:root_create'), {'content': 'root article content', 'title': 'Root Article'}, follow=True) response = self.c.post(
self.assertEqual(response.status_code, 200) # sanity check 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.root_article = URLPath.root().article
self.example_data = { self.example_data = {
'content': 'The modified text', 'content': 'The modified text',
'current_revision': '1', 'current_revision': '1',
'preview': '1', 'preview': '1',
#'save': '1', # probably not too important # 'save': '1', # probably not too important
'summary': 'why edited', 'summary': 'why edited',
'title': 'wiki test'} 'title': 'wiki test'}
def get_by_path(self, path): def get_by_path(self, path):
"""Get the article response for the path. """Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title 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 ...@@ -8,6 +8,23 @@ import pprint
from .base import ArticleTestBase, WebTestBase 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): 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