summaryrefslogtreecommitdiff
path: root/docs/tutorials/wiki2/src/tests
diff options
context:
space:
mode:
authorSteve Piercy <web@stevepiercy.com>2016-02-28 22:30:22 -0800
committerSteve Piercy <web@stevepiercy.com>2016-02-28 22:30:22 -0800
commit3e30040da7c2d5c38b330727b48d9f6b852956d9 (patch)
treeb413abc85048bd7a3697b8844b0f250b8bc66bb9 /docs/tutorials/wiki2/src/tests
parentde3062576ce5aa8b2e854626a48e3f5c46b29cb7 (diff)
downloadpyramid-3e30040da7c2d5c38b330727b48d9f6b852956d9.tar.gz
pyramid-3e30040da7c2d5c38b330727b48d9f6b852956d9.tar.bz2
pyramid-3e30040da7c2d5c38b330727b48d9f6b852956d9.zip
redirect to edit page when user attempts to add page that already exists
- update src/*/views/default.py - update src/*/routes.py - write new test - revise docs, double-checking line counts and highlighting
Diffstat (limited to 'docs/tutorials/wiki2/src/tests')
-rw-r--r--docs/tutorials/wiki2/src/tests/tutorial/routes.py8
-rw-r--r--docs/tutorials/wiki2/src/tests/tutorial/tests/test_views.py12
2 files changed, 19 insertions, 1 deletions
diff --git a/docs/tutorials/wiki2/src/tests/tutorial/routes.py b/docs/tutorials/wiki2/src/tests/tutorial/routes.py
index c7c3a2120..f0a8b7f96 100644
--- a/docs/tutorials/wiki2/src/tests/tutorial/routes.py
+++ b/docs/tutorials/wiki2/src/tests/tutorial/routes.py
@@ -1,4 +1,7 @@
-from pyramid.httpexceptions import HTTPNotFound
+from pyramid.httpexceptions import (
+ HTTPNotFound,
+ HTTPFound,
+)
from pyramid.security import (
Allow,
Everyone,
@@ -19,6 +22,9 @@ def includeme(config):
def new_page_factory(request):
pagename = request.matchdict['pagename']
+ if request.dbsession.query(Page).filter_by(name=pagename).count() > 0:
+ next_url = request.route_url('edit_page', pagename=pagename)
+ raise HTTPFound(location=next_url)
return NewPage(pagename)
class NewPage(object):
diff --git a/docs/tutorials/wiki2/src/tests/tutorial/tests/test_views.py b/docs/tutorials/wiki2/src/tests/tutorial/tests/test_views.py
index 5253183df..2c945ab33 100644
--- a/docs/tutorials/wiki2/src/tests/tutorial/tests/test_views.py
+++ b/docs/tutorials/wiki2/src/tests/tutorial/tests/test_views.py
@@ -98,6 +98,18 @@ class AddPageTests(BaseTest):
from tutorial.views.default import add_page
return add_page(request)
+ def test_it_pageexists(self):
+ from ..models import Page
+ from ..routes import NewPage
+ request = testing.DummyRequest({'form.submitted': True,
+ 'body': 'Hello yo!'},
+ dbsession=self.session)
+ request.user = self.makeUser('foo', 'editor')
+ request.context = NewPage('AnotherPage')
+ self._callFUT(request)
+ pagecount = self.session.query(Page).filter_by(name='AnotherPage').count()
+ self.assertGreater(pagecount, 0)
+
def test_it_notsubmitted(self):
from ..routes import NewPage
request = dummy_request(self.session)