def test_edit_order_add_rename_documents(self): app = self.app widget = self.widget mw = self.mw widget.edit_new_order(self.customer_id) widget.controller_part.view.setFocus(Qt.OtherFocusReason) self._fill_order_part("Order part one") # Put the cursor back on the first line so the next document drop is tied to it. QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_Up) app.processEvents() # app.exec_() # Drop a document tmp_file, tmp_path = self._make_tmp_file() mime_data = QMimeData() url = "file:///{}".format(os.path.abspath(tmp_path).replace('\\', '/')) mainlog.debug("Dropping at {}".format(QUrl(url).toString())) mime_data.setUrls([QUrl(url)]) make_document_drop(widget.documents_widget.view, QPoint(10, 10), mime_data) self._clear_tmp_file(tmp_file, tmp_path) # Now it has been dropped, rename it # (this tests things like non-delayed create, delayed rename) model = widget.documents_widget.model fn_ndx = model.prototype.index_of("filename") ndx = model.index(0, fn_ndx) model.setData(ndx, "New name", Qt.UserRole) #app.exec_() # Now save the whole order widget.setFocus() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() order = dao.order_dao.find_by_id(widget._current_order.order_id) #app.exec_() self.assertEqual(1, len(order.parts[0].documents), "One document was added on the first part") documents = [d for d in order.parts[0].documents] # Set to array self.assertEqual("New name", documents[0].filename, "Rename should've been applied")
def test_edit_order_documents(self): app = self.app widget = self.widget mw = self.mw # order = self._make_order() # order_id = order.order_id # widget.reset_order(order.order_id) widget.edit_new_order(self.customer_id) widget.controller_part.view.setFocus(Qt.OtherFocusReason) # QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_Escape) # modifier, delay # QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5, Qt.ShiftModifier) # modifier, delay # app.processEvents() self._fill_order_part("Order part two") # Put the cursor back on the first line so the next document drop is tied to it. QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_Up) app.processEvents() # app.exec_() tmp_file, tmp_path = self._make_tmp_file() mime_data = QMimeData() url = "file:///{}".format(os.path.abspath(tmp_path).replace('\\', '/')) mainlog.debug("Dropping at {}".format(QUrl(url).toString())) mime_data.setUrls([QUrl(url)]) make_document_drop(widget.documents_widget.view, QPoint(10, 10), mime_data) self._clear_tmp_file(tmp_file, tmp_path) # That's fine, but I'll need to pilot the file chooser dialog, and that's hard :-( # But even if I find my way around that, I'll have to mock the file server... :-( # b.click() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() order = dao.order_dao.find_by_id(widget._current_order.order_id) #app.exec_() self.assertEqual(1, len(order.parts[0].documents), "One document was added on the first part")
def _drag_urls ( self, urls ): mime_data = QMimeData() mime_data.setUrls( urls ) return mime_data
def _drag_files ( self, files ): mime_data = QMimeData() mime_data.setUrls( [ QUrl( file ) for file in files ] ) return mime_data