[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container/ftests - test_contents.py:1.5

Garrett Smith garrett at mojave-corp.com
Thu Oct 2 12:23:20 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/container/ftests
In directory cvs.zope.org:/tmp/cvs-serv1046/src/zope/app/browser/container/ftests

Modified Files:
	test_contents.py 
Log Message:
Added defensive code to contents UI that handes missing clipboard items.
This fixes a series of problems that arise when a copied item is deleted.

There are still some minor issues remaining:

- It's possible that the clipboard contain items that are deleted. It seems to
me that clipboard items should be removed when their source items are
removed.

- One cannot paste multiple times from a cut object since the clipboard
contains only a reference to the source item, which is made invalid by
the first paste/move operation.

=== Zope3/src/zope/app/browser/container/ftests/test_contents.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/container/ftests/test_contents.py:1.4	Sun Sep 21 13:30:27 2003
+++ Zope3/src/zope/app/browser/container/ftests/test_contents.py	Thu Oct  2 12:23:19 2003
@@ -160,6 +160,97 @@
         self.assert_(dc.title == 'test title')
 
 
+    def test_pasteable_for_deleted_clipboard_item(self):
+        """Tests Paste button visibility when copied item is deleted."""
+
+        root = self.getRootFolder()
+        root['foo'] = File()    # item to be copied/deleted
+        root['bar'] = File()    # ensures that there's always an item in
+                                # the collection view
+        get_transaction().commit()
+
+        # confirm foo in contents, Copy button visible, Paste not visible
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        self.assert_(response.getBody().find(
+            '<a href="foo/@@SelectedManagementView.html">foo</a>') != -1)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_copy_button"') != -1)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_paste_button"') == -1)
+
+        # copy foo - confirm Paste visible
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
+            'ids' : ('foo',),
+            'container_copy_button' : '' })
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+            'http://localhost/@@contents.html')
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_paste_button"') != -1)
+
+        # delete foo -> nothing valid to paste -> Paste should not be visible
+        del root['foo']
+        get_transaction().commit()
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_paste_button"') == -1)      
+
+
+    def test_paste_for_deleted_clipboard_item(self):
+        """Tests paste operation when one of two copied items is deleted."""
+
+        root = self.getRootFolder()
+        root['foo'] = File()
+        root['bar'] = File()
+        get_transaction().commit()
+
+        # confirm foo/bar in contents, Copy button visible, Paste not visible
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        self.assert_(response.getBody().find(
+            '<a href="foo/@@SelectedManagementView.html">foo</a>') != -1)
+        self.assert_(response.getBody().find(
+            '<a href="bar/@@SelectedManagementView.html">bar</a>') != -1)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_copy_button"') != -1)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_paste_button"') == -1)
+
+        # copy foo and bar - confirm Paste visible
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
+            'ids' : ('foo', 'bar'),
+            'container_copy_button' : '' })
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+            'http://localhost/@@contents.html')
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_paste_button"') != -1)
+
+        # delete only foo -> bar still available -> Paste should be visible
+        del root['foo']
+        get_transaction().commit()
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        self.assert_(response.getBody().find(
+            '<input type="submit" name="container_paste_button"') != -1)
+
+        # paste clipboard contents - only bar should be copied
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
+            'container_paste_button' : '' })
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+            'http://localhost/@@contents.html')
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        root._p_jar.sync()
+        self.assertEqual(tuple(root.keys()), ('bar', 'bar-2'))
+
 
 def test_suite():
     suite = unittest.TestSuite()




More information about the Zope3-Checkins mailing list