From b6a1368640e22ae940c4d240772ee26436d10d0e Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Tue, 13 Oct 2020 12:32:43 +0200 Subject: [PATCH] test_schemeedit: Use drag/drop test helpers --- .../document/tests/test_schemeedit.py | 91 +++++-------------- 1 file changed, 24 insertions(+), 67 deletions(-) diff --git a/orangecanvas/document/tests/test_schemeedit.py b/orangecanvas/document/tests/test_schemeedit.py index 6116cd6a7..b7a2592b9 100644 --- a/orangecanvas/document/tests/test_schemeedit.py +++ b/orangecanvas/document/tests/test_schemeedit.py @@ -23,7 +23,7 @@ from ...registry.tests import small_testing_registry -from ...gui.test import QAppTestCase, mouseMove +from ...gui.test import QAppTestCase, mouseMove, dragDrop, dragEnterLeave from ...utils import findf @@ -431,78 +431,50 @@ def test_drop_event(self): w.setRegistry(self.reg) workflow = w.scheme() desc = self.reg.widget("one") - view = w.view() + viewport = w.view().viewport() mime = QMimeData() mime.setData( "application/vnd.orange-canvas.registry.qualified-name", desc.qualified_name.encode("utf-8") ) - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - ev.setAccepted(False) - QApplication.sendEvent(view.viewport(), ev) - self.assertTrue(ev.isAccepted()) - - ev = QDragMoveEvent( - QPoint(11, 11), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - ev.setAccepted(False) - QApplication.sendEvent(view.viewport(), ev) - self.assertTrue(ev.isAccepted()) - - ev = QDropEvent( - QPoint(11, 11), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - ev.setAccepted(False) - QApplication.sendEvent(view.viewport(), ev) + + self.assertTrue(dragDrop(viewport, mime, QPoint(10, 10))) self.assertEqual(len(workflow.nodes), 1) self.assertEqual(workflow.nodes[0].description, desc) + dragEnterLeave(viewport, mime) + + self.assertEqual(len(workflow.nodes), 1) + def test_drag_drop(self): w = self.w w.setRegistry(self.reg) handler = TestDropHandler() w.setDropHandlers([handler]) - view = w.view() + viewport = w.view().viewport() mime = QMimeData() mime.setData(handler.format_, b'abc') - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) - self.assertTrue(ev.isAccepted()) - self.assertEqual(handler.accepts_calls, 1) - - ev = QDragMoveEvent( - QPoint(11, 11), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) - self.assertTrue(ev.isAccepted()) - self.assertEqual(handler.accepts_calls, 2) - - ev = QDropEvent( - QPoint(11, 11), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) + + dragDrop(viewport, mime, QPoint(10, 10)) + self.assertEqual(handler.doDrop_calls, 1) + self.assertGreaterEqual(handler.accepts_calls, 1) self.assertIsNone(w._userInteractionHandler()) handler.accepts_calls = 0 handler.doDrop_calls = 0 mime = QMimeData() mime.setData("application/prs.do-not-accept-this", b'abc') - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) - self.assertEqual(handler.accepts_calls, 1) - - ev = QDropEvent( - QPoint(11, 11), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) + + dragDrop(viewport, mime, QPoint(10, 10)) + + self.assertGreaterEqual(handler.accepts_calls, 1) self.assertEqual(handler.doDrop_calls, 0) self.assertIsNone(w._userInteractionHandler()) - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) - ev = QDragLeaveEvent() - QApplication.sendEvent(view.viewport(), ev) + dragEnterLeave(viewport, mime, QPoint(10, 10)) + self.assertIsNone(w._userInteractionHandler()) @mock.patch( @@ -523,30 +495,21 @@ def test_plugin_drag_drop(self): w.setRegistry(self.reg) w.setDropHandlers([handler]) workflow = w.scheme() - view = w.view() + viewport = w.view().viewport() # Test empty handler mime = QMimeData() mime.setData(TestDropHandler.format_, b'abc') - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) - ev = QDropEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) + dragDrop(viewport, mime, QPoint(10, 10)) + self.assertIsNone(w._userInteractionHandler()) # test create node handler mime = QMimeData() mime.setData(TestNodeFromMimeData.format_, b'abc') - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) + dragDrop(viewport, mime, QPoint(10, 10)) - ev = QDropEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) self.assertIsNone(w._userInteractionHandler()) self.assertEqual(len(workflow.nodes), 1) self.assertEqual(workflow.nodes[0].description.name, "one") @@ -559,18 +522,12 @@ def test_plugin_drag_drop(self): mime.setData(TestDropHandler.format_, b'abc') mime.setData(TestNodeFromMimeData.format_, b'abc') - ev = QDragEnterEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - QApplication.sendEvent(view.viewport(), ev) - ev = QDropEvent( - QPoint(10, 10), Qt.CopyAction, mime, Qt.LeftButton, Qt.NoModifier) - def exec(self, *args): return action_by_name(self.actions(), "-pick-me") # intercept QMenu.exec, force select the TestNodeFromMimeData handler with mock.patch.object(QMenu, "exec", exec): - QApplication.sendEvent(view.viewport(), ev) + dragDrop(viewport, mime, QPoint(10, 10)) self.assertEqual(len(workflow.nodes), 1) self.assertEqual(workflow.nodes[0].description.name, "one")