add view_article tests
This commit is contained in:
parent
6d4f8105e5
commit
4d7f8a65e7
@ -2,10 +2,13 @@ import time
|
|||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.http import HttpRequest
|
||||||
from django.contrib.auth.models import User, AnonymousUser
|
from django.contrib.auth.models import User, AnonymousUser
|
||||||
from markupwiki.models import Article, PUBLIC, LOCKED, DELETED
|
from markupwiki.models import Article, ArticleVersion, PUBLIC, LOCKED, DELETED
|
||||||
from markupwiki import models
|
from markupwiki import models
|
||||||
from markupwiki.utils import make_wiki_links, wikify_markup_wrapper
|
from markupwiki.utils import make_wiki_links, wikify_markup_wrapper
|
||||||
|
from markupwiki import views
|
||||||
|
|
||||||
class ArticleTests(TestCase):
|
class ArticleTests(TestCase):
|
||||||
|
|
||||||
@ -91,6 +94,8 @@ class ArticleWriteLockTests(TestCase):
|
|||||||
|
|
||||||
class WikifyTests(TestCase):
|
class WikifyTests(TestCase):
|
||||||
|
|
||||||
|
urls = 'markupwiki.urls'
|
||||||
|
|
||||||
def _get_url(self, link, name=None):
|
def _get_url(self, link, name=None):
|
||||||
return '<a href="%s">%s</a>' % (reverse('view_article', args=[link]),
|
return '<a href="%s">%s</a>' % (reverse('view_article', args=[link]),
|
||||||
name or link)
|
name or link)
|
||||||
@ -118,3 +123,84 @@ class WikifyTests(TestCase):
|
|||||||
wrapped_upper_filter = wikify_markup_wrapper(lambda text: text.upper())
|
wrapped_upper_filter = wikify_markup_wrapper(lambda text: text.upper())
|
||||||
self.assertEquals(wrapped_upper_filter,
|
self.assertEquals(wrapped_upper_filter,
|
||||||
wikify_markup_wrapper(wrapped_upper_filter))
|
wikify_markup_wrapper(wrapped_upper_filter))
|
||||||
|
|
||||||
|
|
||||||
|
class ViewArticleTests(TestCase):
|
||||||
|
|
||||||
|
urls = 'markupwiki.urls'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.admin = User.objects.create_superuser('admin', 'admin@admin.com',
|
||||||
|
'password')
|
||||||
|
self.frank = User.objects.create_user('frank', 'frank@example.com',
|
||||||
|
'password')
|
||||||
|
self.test_article = Article.objects.create(title='test',
|
||||||
|
creator=self.admin)
|
||||||
|
ArticleVersion.objects.create(article=self.test_article,
|
||||||
|
author=self.admin,
|
||||||
|
number=0,
|
||||||
|
body='this is a test')
|
||||||
|
ArticleVersion.objects.create(article=self.test_article,
|
||||||
|
author=self.frank,
|
||||||
|
number=1,
|
||||||
|
body='this is an update')
|
||||||
|
ArticleVersion.objects.create(article=self.test_article,
|
||||||
|
author=self.frank,
|
||||||
|
number=2,
|
||||||
|
body='this is the final update')
|
||||||
|
self.two_word_article = Article.objects.create(title='two_words',
|
||||||
|
creator=self.admin)
|
||||||
|
ArticleVersion.objects.create(article=self.two_word_article,
|
||||||
|
author=self.frank,
|
||||||
|
number=0,
|
||||||
|
body='this article title has a space')
|
||||||
|
|
||||||
|
def test_normal(self):
|
||||||
|
''' test accessing an article without a version specified '''
|
||||||
|
resp = self.client.get('/test/')
|
||||||
|
self.assertContains(resp, 'this is the final update')
|
||||||
|
|
||||||
|
def test_specific_version(self):
|
||||||
|
''' test accessing a specific version of an article '''
|
||||||
|
resp = self.client.get('/test/history/1/')
|
||||||
|
self.assertContains(resp, 'this is an update')
|
||||||
|
|
||||||
|
def test_name_with_spaces(self):
|
||||||
|
''' test that a name with spaces is properly converted into a name with underscores '''
|
||||||
|
resp = self.client.get('/two words/')
|
||||||
|
self.assertRedirects(resp, '/two_words/', status_code=301)
|
||||||
|
|
||||||
|
def test_redirect(self):
|
||||||
|
''' test that a 302 is given for any article with a redirect_to '''
|
||||||
|
redirect = Article.objects.create(title='redirect', creator=self.admin,
|
||||||
|
redirect_to=self.test_article)
|
||||||
|
resp = self.client.get('/redirect/')
|
||||||
|
self.assertRedirects(resp, '/test/', status_code=302)
|
||||||
|
|
||||||
|
def test_missing_edit(self):
|
||||||
|
''' test that a 302 is given to the edit page if CREATE_MISSING_ARTICLE is True '''
|
||||||
|
views.CREATE_MISSING_ARTICLE = True
|
||||||
|
self.client.login(username='frank', password='password')
|
||||||
|
resp = self.client.get('/newpage/')
|
||||||
|
self.assertRedirects(resp, '/newpage/edit/', status_code=302)
|
||||||
|
|
||||||
|
def test_missing_404(self):
|
||||||
|
''' test that a 404 is given if CREATE_MISSING_ARTICLE is False '''
|
||||||
|
views.CREATE_MISSING_ARTICLE = False
|
||||||
|
self.client.login(username='frank', password='password')
|
||||||
|
resp = self.client.get('/newpage/')
|
||||||
|
self.assertContains(resp, '', status_code=404)
|
||||||
|
|
||||||
|
def test_staff_forms(self):
|
||||||
|
''' ensure that only admins can see the admin form '''
|
||||||
|
|
||||||
|
# make sure a normal user doesn't see the admin form
|
||||||
|
self.client.login(username='frank', password='password')
|
||||||
|
resp = self.client.get('/test/')
|
||||||
|
self.assertNotContains(resp, '<label for="id_status">')
|
||||||
|
|
||||||
|
# ...but an admin does
|
||||||
|
self.client.login(username='admin', password='password')
|
||||||
|
resp = self.client.get('/test/')
|
||||||
|
self.assertContains(resp, '<label for="id_status">')
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ def title_check(view):
|
|||||||
def new_view(request, title, *args, **kwargs):
|
def new_view(request, title, *args, **kwargs):
|
||||||
newtitle = title.replace(' ', '_')
|
newtitle = title.replace(' ', '_')
|
||||||
if newtitle != title:
|
if newtitle != title:
|
||||||
return redirect(request.path.replace(title, newtitle))
|
return redirect(request.path.replace(title, newtitle),
|
||||||
|
permanent=True)
|
||||||
else:
|
else:
|
||||||
return view(request, title, *args, **kwargs)
|
return view(request, title, *args, **kwargs)
|
||||||
return wraps(view)(new_view)
|
return wraps(view)(new_view)
|
||||||
|
Loading…
Reference in New Issue
Block a user