diff --git a/markupwiki/tests.py b/markupwiki/tests.py index 45e0ad8..3d3a9c7 100644 --- a/markupwiki/tests.py +++ b/markupwiki/tests.py @@ -2,10 +2,13 @@ import time from django.core.cache import cache from django.core.urlresolvers import reverse 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 markupwiki.models import Article, PUBLIC, LOCKED, DELETED +from markupwiki.models import Article, ArticleVersion, PUBLIC, LOCKED, DELETED from markupwiki import models from markupwiki.utils import make_wiki_links, wikify_markup_wrapper +from markupwiki import views class ArticleTests(TestCase): @@ -91,6 +94,8 @@ class ArticleWriteLockTests(TestCase): class WikifyTests(TestCase): + urls = 'markupwiki.urls' + def _get_url(self, link, name=None): return '%s' % (reverse('view_article', args=[link]), name or link) @@ -118,3 +123,84 @@ class WikifyTests(TestCase): wrapped_upper_filter = wikify_markup_wrapper(lambda text: text.upper()) self.assertEquals(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, '