Permalink
Browse files

Redirect to 'view' after 'add'.

  • Loading branch information...
1 parent 6700f6f commit 4c6ec981cdcd4668113f4fc24760709ddb9c1e4e @dnouri dnouri committed Mar 5, 2012
Showing with 33 additions and 35 deletions.
  1. +26 −26 kotti/tests/browser.txt
  2. +1 −0 kotti/tests/test_functional.py
  3. +5 −6 kotti/tests/test_util_views.py
  4. +1 −3 kotti/views/util.py
View
@@ -66,16 +66,15 @@ Log in again, this time force an error:
Add a document
--------------
- >>> browser.open(testing.BASE_URL)
- >>> browser.getLink("Edit").click()
- >>> browser.open(testing.BASE_URL + '/@@add_document')
+ >>> browser.getLink("Add").click()
+ >>> browser.getLink("Document").click()
>>> "Add document to <em>Welcome to Kotti</em>" in browser.contents
True
>>> ctrl("Title").value = "Child One"
>>> ctrl("save").click()
>>> "Successfully added item" in browser.contents
True
- >>> browser.url == testing.BASE_URL + '/child-one/@@edit'
+ >>> browser.url == testing.BASE_URL + '/child-one/'
True
Edit the document
@@ -124,50 +123,49 @@ And now click the 'Cancel' button:
Add two more documents, at different levels
-------------------------------------------
- >>> browser.open(testing.BASE_URL + '/@@add_document')
+ >>> browser.open(testing.BASE_URL + '/')
+ >>> browser.getLink("Add").click()
+ >>> browser.getLink("Document").click()
>>> ctrl("Title").value = "Second Child"
>>> ctrl("save").click()
>>> "Successfully added item" in browser.contents
True
- >>> browser.url == testing.BASE_URL + '/second-child/@@edit'
+ >>> browser.url == testing.BASE_URL + '/second-child/'
True
- >>> browser.getLink("View").click()
- >>> browser.open(browser.url + '/@@add_document')
+ >>> browser.getLink("Add").click()
+ >>> browser.getLink("Document").click()
>>> ctrl("Title").value = "Grandchild"
>>> ctrl("save").click()
- >>> browser.url == testing.BASE_URL + '/second-child/grandchild/@@edit'
+ >>> browser.url == testing.BASE_URL + '/second-child/grandchild/'
True
-
- >>> browser.getLink("View").click()
>>> "Grandchild" in browser.contents
True
- >>> browser.url == testing.BASE_URL + '/second-child/grandchild/'
- True
Add another grandchild with the same name:
>>> browser.open(testing.BASE_URL + '/second-child')
- >>> browser.open(browser.url + '/@@add_document')
+ >>> browser.getLink("Add").click()
+ >>> browser.getLink("Document").click()
>>> ctrl("Title").value = "Grandchild"
>>> ctrl("save").click()
- >>> browser.url == testing.BASE_URL + '/second-child/grandchild-1/@@edit'
+ >>> browser.url == testing.BASE_URL + '/second-child/grandchild-1/'
True
-
If it's not possible to add something, the add menu is disabled:
>>> browser.open(testing.BASE_URL + '/second-child/grandchild-1')
>>> 'class="disabled"' in browser.contents
False
- >>> Document.type_info.addable_to = ()
- >>> File.type_info.addable_to = ()
- >>> browser.reload()
- >>> 'class="disabled"' in browser.contents
+ >>> try:
+ ... Document.type_info.addable_to = ()
+ ... File.type_info.addable_to = ()
+ ... browser.reload()
+ ... 'class="disabled"' in browser.contents
+ ... finally:
+ ... Document.type_info.addable_to = save_addable_document
+ ... File.type_info.addable_to = save_addable_file
True
- >>> Document.type_info.addable_to = save_addable_document
- >>> File.type_info.addable_to = save_addable_file
-
Reorder documents
-----------------
@@ -288,11 +286,13 @@ property:
>>> browser.open(testing.BASE_URL + '/child-one/second-child')
>>> browser.getLink('Paste').click()
>>> Document.type_info.addable_to = ()
- >>> browser.reload()
- >>> browser.getLink('Paste')
+ >>> try:
+ ... browser.reload()
+ ... browser.getLink('Paste')
+ ... finally:
+ ... Document.type_info.addable_to = save_addable_document
Traceback (most recent call last):
LinkNotFoundError
- >>> Document.type_info.addable_to = save_addable_document
We can rename an item:
@@ -48,6 +48,7 @@ def test_view_uploaded_file(self):
def test_tempstorage(self):
browser = self.test_it()
+ browser.getLink("Edit").click()
browser.getControl("Title").value = '' # the error
self.add_file(browser, contents='DEF')
browser.getControl('save').click()
@@ -511,24 +511,23 @@ def make(self):
from kotti.views.util import AddFormView
return AddFormView(Dummy(), DummyRequest())
- @patch('kotti.views.util.resource_url')
- def test_save_success_calls_add(self, resource_url):
+ def test_save_success_calls_add(self):
view = self.make()
view.add = MagicMock()
view.find_name = lambda appstruct: 'somename'
+ view.request.resource_url = lambda context: u''
view.save_success({'three': 3})
view.add.assert_called_with(three=3)
assert view.add.return_value == view.context['somename']
- @patch('kotti.views.util.resource_url')
- def test_save_success_redirects(self, resource_url):
- resource_url.return_value = 'someurl'
+ def test_save_success_redirects(self):
view = self.make()
view.add = MagicMock()
view.find_name = lambda appstruct: 'somename'
+ view.request.resource_url = lambda context: u'MagicMock'
result = view.save_success({'three': 3})
assert result.status == '302 Found'
- assert result.location == 'someurl'
+ assert result.location == 'MagicMock'
def test_save_success_redirects_custom_url(self):
view = self.make()
View
@@ -16,7 +16,6 @@
from pyramid.location import lineage
from pyramid.renderers import get_renderer
from pyramid.renderers import render
-from pyramid.url import resource_url
from pyramid.view import render_view_to_response
from pyramid_deform import FormView
from pyramid_deform import CSRFSchema
@@ -415,8 +414,7 @@ def save_success(self, appstruct):
name = self.find_name(appstruct)
new_item = self.context[name] = self.add(**appstruct)
self.request.session.flash(self.success_message, 'success')
- location = self.success_url or resource_url(
- new_item, self.request, '@@edit')
+ location = self.success_url or self.request.resource_url(new_item)
return HTTPFound(location=location)
def find_name(self, appstruct):

0 comments on commit 4c6ec98

Please sign in to comment.