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