Kotti browser tests
===================

Setup
-----

   >>> from kotti import tests
   >>> from kotti.resources import Node, Document, DBSession

   >>> tools = tests.setUpFunctional()
   >>> browser = tools['Browser']()
   >>> browser.open(tests.BASE_URL)
   >>> session = DBSession()
   >>> root = session.query(Node).get(1)

Add a document
--------------

  >>> browser.open(tests.BASE_URL)
  >>> browser.getLink("Edit").click()
  >>> browser.getLink("Add").click()
  >>> browser.getControl("Title").value = "Child One"
  >>> browser.getControl("save").click()
  >>> "Successfully added item" in browser.contents
  True
  >>> browser.url == tests.BASE_URL + '/child-one/edit'
  True

Edit the document
-----------------

  >>> browser.getLink("Edit").click()
  >>> browser.getControl("Title").value = "First Child"
  >>> browser.getControl("save").click()
  >>> "Your changes have been saved" in browser.contents
  True
  >>> browser.getControl("Title").value
  'First Child'
  >>> browser.getLink("View").click()
  >>> "First Child" in browser.contents
  True

And now force a validation error:

  >>> browser.getLink("Edit").click()
  >>> browser.getControl("Title").value = ""
  >>> browser.getControl("save").click()
  >>> "There was a problem" in browser.contents
  True
  >>> browser.getControl("Title").value
  ''
  >>> browser.getLink("View").click()
  >>> "First Child" in browser.contents
  True

Add two more documents, at different levels
-------------------------------------------

  >>> browser.getLink("Edit").click()
  >>> browser.getLink("Add").click()
  >>> browser.getControl("Add to My Site").selected = True
  >>> browser.getControl("Continue").click()
  >>> browser.getControl("Title").value = "Second Child"
  >>> browser.getControl("save").click()
  >>> "Successfully added item" in browser.contents
  True
  >>> browser.url == tests.BASE_URL + '/second-child/edit'
  True

  >>> browser.getLink("Add").click()
  >>> browser.getControl("Add to Second Child").selected = True
  >>> browser.getControl("Continue").click()
  >>> browser.getControl("Title").value = "Grandchild"
  >>> browser.getControl("save").click()
  >>> browser.url == tests.BASE_URL + '/second-child/grandchild/edit'
  True

  >>> browser.getLink("View").click()
  >>> "Grandchild" in browser.contents
  True
  >>> browser.url == tests.BASE_URL + '/second-child/grandchild/'
  True

Reorder documents
-----------------

  >>> browser.open(tests.BASE_URL)
  >>> index = browser.contents.index
  >>> index("First Child") > index("Second Child")
  False
  >>> browser.getLink("Edit").click()
  >>> browser.getLink("Move").click()
  >>> browser.getControl("First Child").click()
  >>> "First Child reordered" in browser.contents
  True
  >>> browser.getLink("View").click()
  >>> index = browser.contents.index
  >>> index("First Child") > index("Second Child")
  True

Delete a document
-----------------

  >>> browser.open(tests.BASE_URL + '/second-child/grandchild/move')
  >>> browser.getControl(name="delete-confirm").displayValue = ['Yes']
  >>> browser.getControl("delete").click()
  >>> "Grandchild deleted" in browser.contents
  True
  >>> browser.url == tests.BASE_URL + '/second-child/edit'
  True

Copy and paste
--------------

  >>> browser.open(tests.BASE_URL + '/second-child/move')
  >>> browser.getControl(name="cut").click()
  >>> "Second Child cut" in browser.contents
  True

  >>> browser.open(tests.BASE_URL + '/child-one/move')
  >>> browser.getControl(name="paste").click()
  >>> "Second Child pasted" in browser.contents
  True

  >>> browser.open(tests.BASE_URL + '/child-one/second-child/')
  >>> browser.open(tests.BASE_URL + '/second-child/')
  Traceback (most recent call last):
  HTTPError: HTTP Error 404: Not Found

  >>> browser.open(tests.BASE_URL + '/child-one/second-child/move')
  >>> browser.getControl(name="copy").click()
  >>> "Second Child copied" in browser.contents
  True
  >>> browser.open(tests.BASE_URL + '/move')
  >>> browser.getControl(name="paste").click()
  >>> "Second Child pasted" in browser.contents
  True

We can paste twice since we copied:

  >>> browser.getControl(name="paste").click()
  >>> "Second Child pasted" in browser.contents
  True
  >>> browser.open(tests.BASE_URL + '/second-child/')
  >>> "Second Child" in browser.contents
  True
  >>> browser.open(tests.BASE_URL + '/second-child-1/')
  >>> "Second Child" in browser.contents
  True

We can also copy and paste items that contain children, like the whole
site:

  >>> browser.open(tests.BASE_URL + '/move')
  >>> browser.getControl(name="copy").click()
  >>> "My Site copied" in browser.contents
  True
  >>> browser.open(tests.BASE_URL + '/second-child/move')
  >>> browser.getControl(name="paste").click()
  >>> "My Site pasted" in browser.contents
  True
  >>> browser.open(tests.BASE_URL + '/second-child/my-site/')
  >>> browser.open(tests.BASE_URL + '/second-child/my-site/second-child/')

And finally cut and paste a tree:

  >>> browser.open(tests.BASE_URL + '/second-child/move')
  >>> browser.getControl(name="cut").click()
  >>> browser.open(tests.BASE_URL + '/child-one/second-child/move')
  >>> browser.getControl(name="paste").click()
  >>> "Second Child pasted" in browser.contents
  True
  >>> browser.open(tests.BASE_URL + '/second-child/')
  Traceback (most recent call last):
  HTTPError: HTTP Error 404: Not Found
  >>> browser.open(tests.BASE_URL + '/child-one/second-child/second-child')

Note how we can't cut and paste an item into itself:

  >>> browser.open(tests.BASE_URL + '/child-one/move')
  >>> browser.getControl(name="cut").click()
  >>> browser.getControl(name="paste")
  Traceback (most recent call last):
  LookupError: name 'paste'
  >>> browser.open(tests.BASE_URL + '/child-one/second-child/move')
  >>> browser.getControl(name="paste")
  Traceback (most recent call last):
  LookupError: name 'paste'

Whether we can paste or not also depends on the 'type_info.addable'
property:

  >>> browser.open(tests.BASE_URL + '/child-one/move')
  >>> browser.getControl(name="copy").click()
  >>> browser.open(tests.BASE_URL + '/child-one/second-child/move')
  >>> browser.getControl(name="paste")
  <SubmitControl name='paste' type='submitbutton'>
  >>> save_addable = Document.type_info.addable_to
  >>> Document.type_info.addable_to = ()
  >>> browser.reload()
  >>> browser.getControl(name="paste")
  Traceback (most recent call last):
  LookupError: name 'paste'
  >>> Document.type_info.addable_to = save_addable

We can rename an item:

  >>> browser.open(tests.BASE_URL + '/child-one/second-child/move')
  >>> browser.getControl("New name").value
  'second-child'
  >>> browser.getControl("New title").value
  'Second Child'
  >>> browser.getControl("New name").value = "third-child"
  >>> browser.getControl("New title").value = "My Third Child"
  >>> browser.getControl(name="rename").click()
  >>> "Item renamed" in browser.contents
  True
  >>> browser.url == tests.BASE_URL + '/child-one/third-child/move'
  True
  >>> browser.getLink("View").click()
  >>> "My Third Child" in browser.contents
  True

We cannot rename the root:

  >>> browser.open(tests.BASE_URL + '/move')
  >>> browser.getControl("New name")
  Traceback (most recent call last):
  LookupError: label 'New name'

