From d65e992cd705977ac6c34ae6279743dff84b7316 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 7 Apr 2010 17:07:23 -0400 Subject: [PATCH] more view tests --- example/example | Bin 0 -> 43008 bytes example/settings.py | 2 - example/templates/base.html | 11 ++- example/urls.py | 2 +- markupwiki/tests.py | 157 ++++++++++++++++++++++++++++++++---- 5 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 example/example diff --git a/example/example b/example/example new file mode 100644 index 0000000000000000000000000000000000000000..51ee816c73618148b4a23dfc8ed2f7ad59060eb5 GIT binary patch literal 43008 zcmeHQYfK!+9iQ3RyM;4vI2Je)mcwASn3w}&gDuM;=HfUuIDR12mYUO=Ta$C(j@%u7 zsSh2fQKd#z6{S+uen|VJm70F2`k{5yHdWGo>H8(Mk=lM})GCo$MXFR)l~YxnnVsF8 z-P;3<@dKCzhI#yF{{Q*SV|V}moBy3Zdpc7zwJW*&f>G2)fD9l6PiPtd;28enuQr^3 zTm~QKvdg0(oE1jzl7c?;A^JD^C;A6^&&nvL7CHAHfzqdtq9zh>MK2nc=gkEp|H9JZ z^~?*Il#wrHW`lC%7dwRm}zxYi%h@Dq73 zLODZLoHx^%yg6G;6?1$m5xq1C6;;>a@^Okl`l^wg%cTltp^(XCy(!7tb8n&3YgRS& zf_c;J)B&zf0T9@A(nisUYen-$(T{+6V-d@r!UPy95*9NHrb86bk4Rzlj1EC2n>KG0 zUYy5kIb|#rb2OczqT<=q6~loV#X)le4r*#}poDP{MzuJE=(7O-ic26M5O{b96renH zeZnxuM#qQ74_rwbBbUd_@q{sQ@IZQWI59SqJ~(Wca}&>u&z?;#UAizea%plVF?C^j z{>f@|$2klg?AL%+BL0s?^@h=5rCJ8;lN zmjwb00kZxPyaV7J=`HDh=)VG(oqzz*|Lq(Nn4{NACA`WzB=n$k{e#;8+?KwD-U4&@ z=YCwLs={h&ypo<0Yb>8n&E<1Ti>XC3zmTCy*g`51oWE8?rd zS66;#mliIYc~|+plr3cDvS!+0$XdFb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`#Gk>n>R~-gvL&ou9I5nX9RP;oYJ~59#|BpcJE_^p06sZAnfz#w0|{;o z#kDijK_qwx;_ga|>ty{y^jCm?#U&6B2y8ax{qM)VLwb9A*s}rk*}~$)S4)A5tJs4`EE?mUd0Dg( zI}eFQqqePv{BOn{Le!{AEj#4tm_|CWBarTBw|fwcl(;FP|Eoq%1N3L~CjM5AU!kv} zE9hzTGWx`}9eU9*fxxCC&?$H8uxw+nonW=f-Ldjg>;^=QLTATNTI9|c^z9Vk-Ewaa z{1m znBEpvGh_NF_0oWhQBMuP(h({u{osYGLb4s_+HUWC#c{82 zzEXc>OE4c1wORYT;OnLK4lLBTM=1IN&if2wUn-GF(-zB$dje!DBXZi{WGf>gB3hZ& z*v9Zo#Ijj4F_<|gC!P?&G<()1AU77|pb0Vj2RBEg^b+gh{$Fvo69oc+ZI6Ih|J#0u zMF#}}6%iooKZc$I=nnc9`T)I;-bH^xzem4DKSe*rp9r{(zKy<#zJ@;+^dKF|>XxL7|sx}&`G;AfI5~X1a4Vy_AZlYl$ z4I4-ps;6Nc4Qoj#*U)em4I?B()ikW4p+Z6_Ov4ZjWfDR}Ly3k^-2cTi6$tEH1jPE^ zxnnPSE)WpwU(5l4z|KX0*#APXAHaV28|h_KgFX+=-V+)n*oD8Cdk~g-Tw@XWFtTMv zDLB>?YN6l?^Z-)_SM1c|>>FIM*Z%U!#}xG_7NILx1X_=oT(~y+SCgRBw_8!qPQcO$ zUz@Z6*QipkzPE;N-A~b5iI1PqZpzUo#_~oJ2x`G$FM_}q^HANlmg{69T^w?+n?b$#V4$J#Uz}Wc6 zxqh<}PoKs8|DJX`QCT3cr4bP8e@hRa5MCf~PY8(he^2m<$^wBcjeuDHTYC6}@B)E* GLg4>`VE5<% literal 0 HcmV?d00001 diff --git a/example/settings.py b/example/settings.py index 04bbc56..4741cd6 100644 --- a/example/settings.py +++ b/example/settings.py @@ -1,8 +1,6 @@ DEBUG = True TEMPLATE_DEBUG = DEBUG -MANAGERS = ADMINS - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', diff --git a/example/templates/base.html b/example/templates/base.html index 4275f80..dfe64c7 100644 --- a/example/templates/base.html +++ b/example/templates/base.html @@ -1,2 +1,9 @@ -{% block content %} -{% endblock %} +{% if messages %} +
    + {% for message in messages %} + {{ message }} + {% endfor %} +
+{% endif %} + +{% block content %} {% endblock %} diff --git a/example/urls.py b/example/urls.py index 5a9bae8..b5bee8e 100644 --- a/example/urls.py +++ b/example/urls.py @@ -6,7 +6,7 @@ from django.conf.urls.defaults import * urlpatterns = patterns('', # Example: - # (r'^example/', include('example.foo.urls')), + (r'^wiki/', include('markupwiki.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: diff --git a/markupwiki/tests.py b/markupwiki/tests.py index 3d3a9c7..963b99c 100644 --- a/markupwiki/tests.py +++ b/markupwiki/tests.py @@ -125,9 +125,9 @@ class WikifyTests(TestCase): wikify_markup_wrapper(wrapped_upper_filter)) -class ViewArticleTests(TestCase): +class ViewTestsBase(TestCase): - urls = 'markupwiki.urls' + urls = 'example.urls' def setUp(self): self.admin = User.objects.create_superuser('admin', 'admin@admin.com', @@ -148,6 +148,8 @@ class ViewArticleTests(TestCase): author=self.frank, number=2, body='this is the final update') + + # article with space in title self.two_word_article = Article.objects.create(title='two_words', creator=self.admin) ArticleVersion.objects.create(article=self.two_word_article, @@ -155,52 +157,173 @@ class ViewArticleTests(TestCase): number=0, body='this article title has a space') + # locked article + self.locked = Article.objects.create(title='locked', creator=self.admin, + status=LOCKED) + ArticleVersion.objects.create(article=self.locked, author=self.frank, + number=0, body='lockdown') + + # clear cache at start of every test + cache.clear() + + + def login_as_user(self): + self.client.login(username='frank', password='password') + + def login_as_admin(self): + self.client.login(username='admin', password='password') + + +class ViewArticleTests(ViewTestsBase): def test_normal(self): ''' test accessing an article without a version specified ''' - resp = self.client.get('/test/') + resp = self.client.get('/wiki/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/') + resp = self.client.get('/wiki/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) + resp = self.client.get('/wiki/two words/') + self.assertRedirects(resp, '/wiki/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) + resp = self.client.get('/wiki/redirect/') + self.assertRedirects(resp, '/wiki/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) + self.login_as_user() + resp = self.client.get('/wiki/newpage/') + self.assertRedirects(resp, '/wiki/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.login_as_user() + resp = self.client.get('/wiki/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.login_as_user() + resp = self.client.get('/wiki/test/') self.assertNotContains(resp, '