[f82ab8c] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | |
---|
| 4 | from PyQt4.QtGui import QApplication |
---|
| 5 | from PyQt4.QtTest import QTest |
---|
[e540cd2] | 6 | from PyQt4 import QtCore |
---|
[f82ab8c] | 7 | from DroppableDataLoadWidget import DroppableDataLoadWidget |
---|
[481ff26] | 8 | from GuiUtils import * |
---|
[e540cd2] | 9 | from UnitTesting.TestUtils import QtSignalSpy |
---|
[f82ab8c] | 10 | |
---|
| 11 | app = QApplication(sys.argv) |
---|
| 12 | |
---|
| 13 | class DroppableDataLoadWidgetTest(unittest.TestCase): |
---|
| 14 | '''Test the DroppableDataLoadWidget GUI''' |
---|
| 15 | def setUp(self): |
---|
| 16 | '''Create the GUI''' |
---|
[481ff26] | 17 | class dummy_manager(object): |
---|
| 18 | def communicator(self): |
---|
| 19 | return Communicate() |
---|
| 20 | def perspective(self): |
---|
| 21 | return MyPerspective() |
---|
| 22 | |
---|
| 23 | self.form = DroppableDataLoadWidget(None, guimanager=dummy_manager()) |
---|
[e540cd2] | 24 | |
---|
| 25 | # create dummy mime object |
---|
| 26 | self.mime_data = QtCore.QMimeData() |
---|
| 27 | self.testfile = 'testfile.txt' |
---|
| 28 | self.mime_data.setUrls([QtCore.QUrl(self.testfile)]) |
---|
[481ff26] | 29 | |
---|
| 30 | def testDragIsOK(self): |
---|
| 31 | """ |
---|
| 32 | Test the item being dragged over the load widget |
---|
| 33 | """ |
---|
[e540cd2] | 34 | good_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0), |
---|
| 35 | QtCore.Qt.CopyAction, |
---|
| 36 | self.mime_data, |
---|
| 37 | QtCore.Qt.LeftButton, |
---|
| 38 | QtCore.Qt.NoModifier) |
---|
| 39 | mime_data = QtCore.QMimeData() |
---|
| 40 | bad_drag_event = QtGui.QDragMoveEvent(QtCore.QPoint(0,0), |
---|
| 41 | QtCore.Qt.CopyAction, |
---|
| 42 | mime_data, |
---|
| 43 | QtCore.Qt.LeftButton, |
---|
| 44 | QtCore.Qt.NoModifier) |
---|
| 45 | |
---|
| 46 | # Call the drag handler with good event |
---|
| 47 | self.assertTrue(self.form.dragIsOK(good_drag_event)) |
---|
| 48 | |
---|
| 49 | # Call the drag handler with bad event |
---|
| 50 | self.assertFalse(self.form.dragIsOK(bad_drag_event)) |
---|
[481ff26] | 51 | |
---|
| 52 | def testDropEvent(self): |
---|
| 53 | """ |
---|
| 54 | Test what happens if an object is dropped onto the load widget |
---|
| 55 | """ |
---|
[e540cd2] | 56 | spy_file_read = QtSignalSpy(self.form, self.form.communicator.fileReadSignal) |
---|
| 57 | |
---|
| 58 | drop_event = QtGui.QDropEvent(QtCore.QPoint(0,0), |
---|
| 59 | QtCore.Qt.CopyAction, |
---|
| 60 | self.mime_data, |
---|
| 61 | QtCore.Qt.LeftButton, |
---|
| 62 | QtCore.Qt.NoModifier) |
---|
| 63 | |
---|
| 64 | self.form.dropEvent(drop_event) |
---|
| 65 | QtGui.qApp.processEvents() |
---|
| 66 | self.assertEqual(spy_file_read.count(), 1) |
---|
| 67 | self.assertIn(self.testfile, str(spy_file_read.signal(index=0))) |
---|
| 68 | |
---|
[f82ab8c] | 69 | |
---|
| 70 | if __name__ == "__main__": |
---|
| 71 | unittest.main() |
---|