def keyRelease(self, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Sends a Qt key release event. See QTest.keyRelease for details. """ QTest.keyRelease(widget, key, modifier, delay) self.qWait(20)
def test_send_pushButton_will_warn_the_user_to_set_the_media_files_path_if_it_is_not_set_before(self): """testing if send_pushButton will warn the user to set the media files path in preferences if it is not set before """ # set a proper EDL file edl_path = os.path.abspath('../previs/test_data/test_v001.edl') self.dialog.edl_path_lineEdit.setText(edl_path) # patch QMessageBox.critical method original = QtGui.QMessageBox.critical QtGui.QMessageBox = PatchedMessageBox self.assertEqual(PatchedMessageBox.called_function, '') self.assertEqual(PatchedMessageBox.title, '') self.assertEqual(PatchedMessageBox.message, '') # now hit it QTest.mouseClick(self.dialog.send_pushButton, Qt.LeftButton) # restore QMessageBox.critical QtGui.QMessageBox.critical = original self.assertEqual(PatchedMessageBox.called_function, 'critical') self.assertEqual(PatchedMessageBox.title, 'Error') self.assertEqual( "Media path doesn't exists", PatchedMessageBox.message )
def keyPress(self, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Sends a Qt key press event. See QTest.keyPress for details. """ QTest.keyPress(widget, key, modifier, delay) self.qWait(20)
def test_copy_button_clicked_with_no_selection_on_to_task_tree_view(self): """testing if a QMessageDialog will be displayed when the copy button selected and no selection is made in to_task_tree_vie """ # select one task in from_task_tree_view # Select Task4 in from_task_tree_view selection_model = self.dialog.from_task_tree_view.selectionModel() model = self.dialog.from_task_tree_view.model() project1_item = model.item(0, 0) self.dialog.from_task_tree_view.expand(project1_item.index()) task1_item = project1_item.child(0, 0) self.dialog.from_task_tree_view.expand(task1_item.index()) task4_item = task1_item.child(0, 0) selection_model.select( task4_item.index(), QtGui.QItemSelectionModel.Select ) self.assertEqual(PatchedMessageBox.called_function, '') # now try to copy it QTest.mouseClick(self.dialog.copy_push_button, Qt.LeftButton) self.assertEqual(PatchedMessageBox.called_function, 'critical') self.assertEqual(PatchedMessageBox.title, 'Error') self.assertEqual(PatchedMessageBox.message, 'Please select a task from <b>To Task</b> list')
def test_clicking_picker_button_opens_picker_window(self): QTest.mouseClick(self.controller.add_button, Qt.LeftButton) picker_window_open = False for widget in QApplication.topLevelWidgets(): if isinstance(widget, lyrical.LyricalPicker): picker_window_open = True self.assertTrue(picker_window_open)
def test_place_item(self): """ Tests the workflow of placing an item """ # Make sure the dockwidget is out of the way self.mw.history_dock_widget.hide() # Select insertion mode QTest.keyClick(self.mw, QtCore.Qt.Key_F2) self.app.processEvents() # Place item QTest.mouseClick( self.mw._view.viewport(), QtCore.Qt.LeftButton, pos=self.mw._view.geometry().center() ) self.app.processEvents() logic_item_count = 0 for item in self.mw._view.scene().items(): if isinstance(item, logicitems.LogicItem): logic_item_count += 1 self.assertEqual(1, logic_item_count)
def keyClick(self, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Simulate clicking a key. See QTest.keyClick for details. """ QTest.keyClick(widget, key, modifier, delay) self.qWait(20)
def mouseMove(widget, pos=None, delay=-1): """Simulate moving the mouse. See QTest.mouseMove for details. """ pos = qt.QPoint(pos[0], pos[1]) if pos is not None else qt.QPoint() QTest.mouseMove(widget, pos, delay)
def keyClicks(self, widget, sequence, modifier=qt.Qt.NoModifier, delay=-1): """Simulate clicking a sequence of keys. See QTest.keyClick for details. """ QTest.keyClicks(widget, sequence, modifier, delay) self.qWait(20)
def test_add_task_without_description(self): itemsBefore = self.form.listWidget.count() '''ensures AddTaskEdit is empty''' QTest.keyClicks(self.form.AddTaskEdit, "") addButton = self.form.AddTaskButton QTest.mouseClick(addButton, Qt.LeftButton) '''assert no items were added''' self.assertEqual(self.form.listWidget.count(), itemsBefore)
def test_add_task_with_description(self): itemsBefore = self.form.listWidget.count() '''ensures AddTaskEdit contains text''' QTest.keyClicks(self.form.AddTaskEdit, "task one") addButton = self.form.AddTaskButton QTest.mouseClick(addButton, Qt.LeftButton) '''assert there is one more item''' self.assertEqual(self.form.listWidget.count(), itemsBefore+1)
def keyEvent(self, action, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Sends a Qt key event. See QTest.keyEvent for details. """ QTest.keyEvent(action, widget, key, modifier, delay) self.qWait(20)
def testKeyEvent(self): widget = QLineEdit() key = Qt.Key_A eventFilter = KeyEventFilter(widget, QEvent.KeyPress, key) widget.installEventFilter(eventFilter) QTest.keyClick(widget, key) self.assert_(eventFilter.processed)
def mouseMove(self, widget, pos=None, delay=-1): """Simulate moving the mouse. See QTest.mouseMove for details. """ pos = qt.QPoint(int(pos[0]), int( pos[1])) if pos is not None else qt.QPoint() QTest.mouseMove(widget, pos, delay) self.qWait(20)
def mouseRelease(widget, button, modifier=None, pos=None, delay=-1): """Simulate releasing a mouse button. See QTest.mouseRelease for details. """ if modifier is None: modifier = qt.Qt.KeyboardModifiers() pos = qt.QPoint(pos[0], pos[1]) if pos is not None else qt.QPoint() QTest.mouseRelease(widget, button, modifier, pos, delay)
def mouseRelease(self, widget, button, modifier=None, pos=None, delay=-1): """Simulate releasing a mouse button. See QTest.mouseRelease for details. """ if modifier is None: modifier = qt.Qt.KeyboardModifiers() pos = qt.QPoint(pos[0], pos[1]) if pos is not None else qt.QPoint() QTest.mouseRelease(widget, button, modifier, pos, delay) self.qWait(20)
def test_close_button_closes_ui(self): """testing if the close button is closing the ui """ self.dialog.show() self.assertEqual(self.dialog.isVisible(), True) # now run the UI QTest.mouseClick(self.dialog.close_pushButton, Qt.LeftButton) self.assertEqual(self.dialog.isVisible(), False)
def mousePress(self, widget, button, modifier=None, pos=None, delay=-1): """Simulate pressing a mouse button. See QTest.mousePress for details. """ if modifier is None: modifier = qt.Qt.KeyboardModifiers() pos = qt.QPoint(pos[0], pos[1]) if pos is not None else qt.QPoint() QTest.mousePress(widget, button, modifier, pos, delay) self.qWait(20)
def test_app_should_write_text_when_sample_button_click(simple_app, capsys): """ Given: A running app. When: The init test button is clicked. Then: A welcome test should return. """ button = simple_app.button QTest.mouseClick(button, QtCore.Qt.LeftButton) out, err = capsys.readouterr() assert "Start coding for {{ cookiecutter.repo_name }}" in str(out)
def setTransGear(this, gearAttr, nameID): if nameID == 'Name': IDName = 'ID' else: IDName = 'Name' this.tTran.gNameIDSearch.clear() QTest.keyClicks(this.tTran.gNameIDSearch, gearAttr[nameID]) if this.tTran.gDissAmbSearch.count() > 1: this.tTran.gDissAmbSearch.setCurrentIndex(this.tTran.gDissAmbSearch.findText(gearAttr[IDName]))
def qWaitForWindowExposed(self, window, timeout=None): """Waits until the window is shown in the screen. See QTest.qWaitForWindowExposed for details. """ result = qWaitForWindowExposedAndActivate(window, timeout) if self.TIMEOUT_WAIT: QTest.qWait(self.TIMEOUT_WAIT) return result
def test_send_pushButton_will_copy_mxf_files_to_media_files_folder(self): """testing if send_pushButton will copy the mxf files to media files folder """ # create a proper edl file with proper files in a temp location # there should be MXF files tempdir = tempfile.gettempdir() media_files_path = os.path.join(tempdir, 'avid_media_file_path') try: os.mkdir(media_files_path) except OSError: pass self.remove_files.append(media_files_path) mxf_file_names = [ 'SEQ001_HSNI_003_0010_v001.mxf', 'SEQ001_HSNI_003_0020_v001.mxf', 'SEQ001_HSNI_003_0030_v001.mxf' ] edl_path = os.path.abspath('../previs/test_data/test_v001.edl') for mxf_file_name in mxf_file_names: media_file_full_path = os.path.join(tempdir, mxf_file_name) with open(media_file_full_path, 'w') as f: f.write('') self.remove_files.append(media_file_full_path) # set the avid media files folder path self.dialog.media_files_path_lineEdit.setText(media_files_path) # set the edl path self.dialog.edl_path_lineEdit.setText(edl_path) # now check before the files are not there self.assertFalse( os.path.exists(os.path.join(media_files_path, mxf_file_names[0]))) self.assertFalse( os.path.exists(os.path.join(media_files_path, mxf_file_names[1]))) self.assertFalse( os.path.exists(os.path.join(media_files_path, mxf_file_names[2]))) # self.show_dialog(self.dialog) # now hit it QTest.mouseClick(self.dialog.send_pushButton, Qt.LeftButton) # now check if the files are there self.assertTrue( os.path.exists(os.path.join(media_files_path, mxf_file_names[0]))) self.assertTrue( os.path.exists(os.path.join(media_files_path, mxf_file_names[1]))) self.assertTrue( os.path.exists(os.path.join(media_files_path, mxf_file_names[2])))
def test_change_order_customer(self): customer2 = self._customer_dao.make( "AAAA") # Name chosen so it happens first int he customer dialog self._customer_dao.save(customer2) app = self.app widget = self.widget mw = self.mw self._make_basic_preorder() self._encode_imputable_operation("Description2") self._encode_imputable_operation("Description3") QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() # Make sure the test is set up correctly preorder = self.order_dao.find_by_id_frozen( widget._current_order.order_id) assert preorder.customer_id == self.customer.customer_id # We're going to have a modal dialog for the new # customer name. So we prepare to click on it. timer = QTimer() timer.timeout.connect(self._lookup) timer.setSingleShot(True) timer.start(1000) widget.change_customer() # app.exec_() # Wait for the timer to shoot mainlog.debug("test_change_order_customer" * 10) mainlog.debug(app.focusWidget()) widget.setFocus( Qt.OtherFocusReason) # This refocus was introduced for linux app.processEvents() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() mainlog.debug("test_change_order_customer") preorder = self.order_dao.find_by_id_frozen( widget._current_order.order_id) assert preorder.customer_id == customer2.customer_id mainlog.debug("test_change_order_customer") self.order_dao.delete(preorder.order_id) self.dao.customer_dao.delete(customer2.customer_id)
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 setUp(self): super(TestFindOrderGUI, self).setUp() self.widget = FindOrderDialog(None) self._order = self._make_order() self.dao.order_dao.recompute_position_labels(self._order) session().commit() self.widget.show() QTest.qWaitForWindowShown(self.widget)
def mouseDClick(self, widget, button, modifier=None, pos=None, delay=-1): """Simulate double clicking a mouse button. See QTest.mouseDClick for details. """ if modifier is None: modifier = qt.Qt.KeyboardModifiers() pos = qt.QPoint(int(pos[0]), int( pos[1])) if pos is not None else qt.QPoint() QTest.mouseDClick(widget, button, modifier, pos, delay) self.qWait(20)
def testBasic(self): '''QTest.mouseClick with QCheckBox''' button = QPushButton() button.setCheckable(True) button.setChecked(False) QTest.mouseClick(button, Qt.LeftButton) self.assert_(button.isChecked()) QTest.mouseClick(button, Qt.LeftButton) self.assertFalse(button.isChecked())
def setUp(self): super(TestEditTimetracks,self).setUp() #operation_definition_cache.reload() self._order = self._make_order() mainlog.debug("Accoutnig label {}".format(self._order.accounting_label)) self.dao.order_dao.recompute_position_labels(self._order) session().commit() self.widget.show() QTest.qWaitForWindowShown(self.widget) self.app.processEvents()
def test_change_order_customer_cancelled(self): customer2 = self._customer_dao.make( "AAAA") # Name chosen so it happens first int he customer dialog self._customer_dao.save(customer2) app = self.app widget = self.widget mw = self.mw self._make_basic_preorder() self._encode_imputable_operation("Description2") self._encode_imputable_operation("Description3") QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() # Make sure the test is set up correctly preorder = self.order_dao.find_by_id_frozen( widget._current_order.order_id) assert preorder.customer_id == self.customer.customer_id # We're going to have a modal dialog for the new # customer name. So we prepare to click on it. timer = QTimer() timer.timeout.connect(self._cancel_dialog) timer.setSingleShot(True) timer.start(1000) # Had 250, my linux seems to prefer 1000 widget.change_customer() # blocks app.processEvents() # app.exec_() # Wait for the timer to shoot widget.setFocus( Qt.OtherFocusReason) # This refocus was introduced for linux for i in range(1000): app.processEvents() # Linux needs a break mainlog.debug("Pressing ctrl-S on this widget : {}".format( app.focusWidget())) # app.exec_() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() preorder = self.order_dao.find_by_id_frozen( widget._current_order.order_id) assert preorder.customer_id == self.customer.customer_id self.order_dao.delete(preorder.order_id) self.dao.customer_dao.delete(customer2.customer_id)
def test_happy(self): order = self._make_order() dao.order_dao.save(order) session().commit() order_id = order.order_id session().close() b = self.widget.buttons.button(QDialogButtonBox.Ok) self.widget.set_preorder( order_id) QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_Enter) self.app.processEvents()
def _scan(self,barcode): """ Simulate a real barcode scan. """ bc = str(barcode) + str(BarCode(barcode)._checksum()) mainlog.debug("Sending a scan : {}".format(bc)) QTest.keyClicks(self.app.focusWidget(), bc) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_Enter) # modifier, delay self.app.processEvents()
def test_create_order_and_report_on_operation(self): app = self.app widget = self.widget mw = self.mw self._make_basic_preorder() # add some more operation self._encode_not_imputable_operation() widget._set_state(OrderStatusType.order_ready_for_production) self.prepare_to_click_dialog("confirm_estimate_sent") # Save 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) mainlog.debug(order) mainlog.debug(order.parts[0]) mainlog.debug(order.parts[0].production_file[0]) operation = order.parts[0].production_file[0].operations[0] employee_id = dao.employee_dao.any().employee_id d1 = datetime(2013, 0o5, 26, 8) self.server = JsonCallWrapper(ClockService(), JsonCallWrapper.IN_PROCESS_MODE) self.server.record_pointage_on_operation( operation.operation_id, employee_id, d1, "nostromo", TaskActionReportType.start_task, None) d2 = datetime(2013, 5, 26, 10, 54) self.server.record_pointage_on_operation( operation.operation_id, employee_id, d2, "nostromo", TaskActionReportType.stop_task, None) order = dao.order_dao.find_by_id(widget._current_order.order_id) operation = order.parts[0].production_file[0].operations[0] widget.edit_new_order( self.customer.customer_id) # Force the order reset below app.processEvents() widget.reset_order(order.order_id, overwrite=True) widget.refresh_action() m = widget.controller_operation.model self.assertEqual(2.9, m.data(m.index(0, 4), Qt.UserRole)) m = widget.controller_part.model self.assertEqual(80, m.data(m.index(0, 4), Qt.UserRole)) self.assertEqual(111, m.data(m.index(0, 6), Qt.UserRole))
def setUp(self): self.app = QtGui.QApplication.instance() if not self.app: self.app = QtGui.QApplication([]) settings_mock = SettingsMock() setup_settings(settings_mock) self.mw = main_window.MainWindow() self.mw.show() QTest.qWaitForWindowShown(self.mw)
def setUp(self): self.window = MainWindow() self.window.show() QTest.qWaitForWindowShown(self.window) self.tree_view = self.window.findChild(QTreeView, "tree_view") self.list_view = self.window.findChild(QListView, "list_view") SearchDialog.exec_ = MagicMock(return_value=SearchDialog.Accepted) SearchDialog.result_value = MagicMock( return_value=ExampleDataFactory.new_pytvdb_show("HIMYM")) Show.update = MagicMock()
def test_copy_button_clicked_with_no_selection_on_from_task_tree_view(self): """testing if a QMessageDialog will be displayed when the copy button selected and no selection is made in from_task_tree_view """ self.assertEqual(PatchedMessageBox.called_function, '') # now try to copy it QTest.mouseClick(self.dialog.copy_push_button, Qt.LeftButton) self.assertEqual(PatchedMessageBox.called_function, 'critical') self.assertEqual(PatchedMessageBox.title, 'Error') self.assertEqual(PatchedMessageBox.message, 'Please select a task from <b>From Task</b> list')
def _fill_in_valid_credentials(self): QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_D) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_K) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_Tab) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_K) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_K) # modifier, delay self.app.processEvents()
def setUp(self): super(TestSupplyOrderSlipGUI, self).setUp() self.widget = EditSupplyOrderPanel(None) self._order = self._make_order() mainlog.debug("Accounting label {}".format( self._order.accounting_label)) self.dao.order_dao.recompute_position_labels(self._order) session().commit() self.widget.show() QTest.qWaitForWindowShown(self.widget)
def test_change_order_part_state(self): order = self._make_order() order_part = self._order_part_dao.make(order) order_part.description = u"Part 2" order_part.position = 2 self._order_part_dao.save(order_part) order_part = self._order_part_dao.make(order) order_part.description = u"Part 3" order_part.position = 3 self._order_part_dao.save(order_part) self._order_dao.change_order_state( order.order_id, OrderStatusType.order_ready_for_production) # self.order_overview_widget.month_today() self.order_overview_widget.refresh_action() self.order_overview_widget.retake_focus() # self.app.exec_() # Select the first order part (we assume they are properly ordered) v = self.order_overview_widget.current_orders_overview.table_view v.setCurrentIndex(v.model().index(0, 0)) QTest.mouseMove(v) # QTest.mouseClick(self.order_overview_widget.current_orders_overview.table_view, # Qt.RightButton, delay=500) # self.order_overview_widget.current_orders_overview.popup_parts() timer = QTimer() timer.timeout.connect(self._click_context_menu) timer.setSingleShot(True) timer.start(1000) # I can't have the menu to popup using museClicks, so I # do it this way. FIXME Taht's not right because nothing prooves # that my context menu is shown on mouse clicks... self.app.sendEvent( self.order_overview_widget.current_orders_overview.table_view, QContextMenuEvent(QContextMenuEvent.Keyboard, QPoint(10, 10))) # self.app.exec_() order = self.order_dao.find_by_id(order.order_id) self.assertEqual(OrderPartStateType.aborted, order.parts[0].state) self.assertEqual(OrderPartStateType.ready_for_production, order.parts[1].state) self.assertEqual(OrderPartStateType.ready_for_production, order.parts[2].state)
def test_create_order_and_report_on_order(self): # python test_integration.py TestEditOrderParts.test_create_order_and_report_on_order app = self.app widget = self.widget mw = self.mw clock_server = ClockServer(dao) self._make_basic_preorder() app.processEvents() widget._set_state(OrderStatusType.order_ready_for_production) self.prepare_to_click_dialog("confirm_estimate_sent") # Save QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents() app.processEvents() app.processEvents() self.assertTrue(widget._current_order.order_id > 0) order = dao.order_dao.find_by_id(widget._current_order.order_id) bc = BarCodeIdentifier.code_for(order, self.opdef_order) employee_id = dao.employee_dao.any().employee_id d1 = datetime(2013, 0o5, 26, 8) # clock_server.recordPointage(bc,employee_id, datetime.strftime(d1, "%Y%m%dT%H:%M:%S"),"Nostromo") d2 = datetime(2013, 0o5, 26, 10, 54) # clock_server.recordPointage(bc,employee_id, datetime.strftime(d2, "%Y%m%dT%H:%M:%S"),"Nostromo") self.server = JsonCallWrapper(ClockService(), JsonCallWrapper.IN_PROCESS_MODE) self.server.record_pointage_on_order( order.order_id, self.opdef_order.operation_definition_id, employee_id, d1, "nostromo", TaskActionReportType.start_task, None) self.server.record_pointage_on_order( order.order_id, self.opdef_order.operation_definition_id, employee_id, d2, "nostromo", TaskActionReportType.stop_task, None) order = dao.order_dao.find_by_id(widget._current_order.order_id) widget.edit_new_order( self.customer.customer_id) # Force the order reset below app.processEvents() widget.reset_order(order.order_id, overwrite=True) app.processEvents()
def testConfigureDialog(self): if self.pixmap_unavailable: return from mapclientplugins.pointcloudserializerstep.widgets.configuredialog import ConfigureDialog, ConfigureDialogState state = ConfigureDialogState() d = ConfigureDialog(state) self.assertEqual(d._ui.buttonBox.button(QtGui.QDialogButtonBox.Ok).isEnabled(), False) QTest.keyClicks(d._ui.identifierLineEdit, 'hello') self.assertEqual(d._ui.buttonBox.button(QtGui.QDialogButtonBox.Ok).isEnabled(), True) # QTest.mouseClick(d._ui.buttonBox.button(QtGui.QDialogButtonBox.Ok), QtCore.Qt.LeftButton) newstate = d.getState() self.assertEqual(newstate.identifier(), 'hello')
def test_encode_supply_order(self): supplier = blank_dto(Supplier) supplier.fullname = "Tessier-Ashpool" supplier_id = supplier_service.save(supplier) supplier = supplier_service.find_by_id(supplier_id) self._pg_locks("on start") app = self.app widget = self.widget widget.edit_new(supplier) self.encode_text("PARTONE") app.processEvents() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_Enter) app.processEvents() self.encode_text("11") app.processEvents() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_Enter) app.processEvents() self.encode_text("22") app.processEvents() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_Enter) app.processEvents() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay app.processEvents()
def setUp(self): self.search = Search(string="how i", expected_row=2, expected_count=6) self.dialog = SearchDialog() self.dialog.show() QTest.qWaitForWindowShown(self.dialog) self.assertEqual(self.dialog.ui.search_text_field.text(), "", "Default Search Text is not empty") self.assertEqual(self.dialog.model.rowCount(), 0, "Result model not cleared")
def _click_context_menu(self): mainlog.debug("hello " * 100) active_widget = self.app.activePopupWidget() mainlog.debug(active_widget) # active_widget = self.app.focusWidget() mainlog.debug(active_widget) active_widget.setFocus() #QApplication. for i in range(10): self.app.processEvents() QTest.keyEvent(QTest.Click, active_widget, Qt.Key_Down) # enter menu for i in range(10): self.app.processEvents() QTest.keyEvent(QTest.Click, active_widget, Qt.Key_Down) # skip modify command self.app.processEvents() QTest.keyEvent(QTest.Click, active_widget, Qt.Key_Down) # Skip priority self.app.processEvents() import time for i in range(50): # time.sleep(0.1) self.app.processEvents() QTest.keyEvent( QTest.Click, active_widget, Qt.Key_Enter) # At this point we're on "order part -> aborted" self.app.processEvents() mainlog.debug("_click_context_menu : done")
def test_copy_button_clicked_with_no_selection_on_from_task_tree_view( self): """testing if a QMessageDialog will be displayed when the copy button selected and no selection is made in from_task_tree_view """ self.assertEqual(PatchedMessageBox.called_function, '') # now try to copy it QTest.mouseClick(self.dialog.copy_push_button, Qt.LeftButton) self.assertEqual(PatchedMessageBox.called_function, 'critical') self.assertEqual(PatchedMessageBox.title, 'Error') self.assertEqual(PatchedMessageBox.message, 'Please select a task from <b>From Task</b> list')
def test_campusLinkLastYears(self): self.ui.tabWid.setCurrentIndex(2) gear = tests.mkGear('J', 10) tests.enterGearInfo(self, gear) QTest.mouseClick(self.tGear.updtBut, QtCore.Qt.LeftButton) self.ui.tabWid.setCurrentIndex(1) self.tMemb.nameSearch.clear() memb = tests.mkMember('A', 1, forms=True, campusLink=True, formsDate=Util.convert_date('Qt2DB', QtCore.QDate.currentDate().addDays(1)), campusDate=Util.convert_date('Qt2DB', QtCore.QDate.currentDate().addDays(-10))) QTest.keyClicks(self.tMemb.nameSearch, memb['FirstName'] + ' ' + memb['LastName']) tests.enterMemberInfo(self, memb) self.assertTrue(self.tMemb.Button_addUpdButClick()) self.ui.tabWid.setCurrentIndex(0) setTransGear(self, gear, 'Name') setTransMemb(self, memb) QTest.mouseClick(self.tTran.payBut, QtCore.Qt.LeftButton) QTest.mouseClick(self.tTran.payWind.payBut, QtCore.Qt.LeftButton) self.tTran.payWind.close() self.tTran.radioOut.click() self.assertTrue(self.tTran.trans())
def test_copy_button_clicked_with_same_task_is_selected_in_both_sides(self): """testing if a QMessageDialog will warn the user about he/she selected the same task in both tree views """ # select one task in from_task_tree_view # Select Task4 in from_task_tree_view selection_model = self.dialog.from_task_tree_view.selectionModel() model = self.dialog.from_task_tree_view.model() project1_item = model.item(0, 0) self.dialog.from_task_tree_view.expand(project1_item.index()) task1_item = project1_item.child(0, 0) self.dialog.from_task_tree_view.expand(task1_item.index()) task4_item = task1_item.child(0, 0) selection_model.select( task4_item.index(), QtGui.QItemSelectionModel.Select ) # Select Task4 in to_task_tree_view selection_model = self.dialog.to_task_tree_view.selectionModel() model = self.dialog.to_task_tree_view.model() project1_item = model.item(0, 0) self.dialog.to_task_tree_view.expand(project1_item.index()) task1_item = project1_item.child(0, 0) self.dialog.to_task_tree_view.expand(task1_item.index()) task4_item = task1_item.child(0, 0) selection_model.select( task4_item.index(), QtGui.QItemSelectionModel.Select ) self.assertEqual(PatchedMessageBox.called_function, '') # now try to copy it QTest.mouseClick(self.dialog.copy_push_button, Qt.LeftButton) self.assertEqual(PatchedMessageBox.called_function, 'critical') self.assertEqual(PatchedMessageBox.title, 'Error') self.assertEqual(PatchedMessageBox.message, 'Please select two different tasks')
def test_encode_a_few_timetracks(self): # python test_integration.py TestEditTimetracks.test_create_order_and_report_on_order app = self.app widget = self.widget self._pg_locks("before init ") widget.set_employee_and_date(self.employee.employee_id, date.today()) self._encode_imputable_operation(5) self._pg_locks("after encoding a row") widget.buttons.button(QDialogButtonBox.Ok).click() self._pg_locks("after OK click") # Now we check the time was actually reported session().refresh(self._order) self.assertEqual( 5.0, self._order.parts[0].total_hours) session().commit() self._pg_locks("after commit") # Now we reopen the dialog and make sure our work still appears # there. widget.set_employee_and_date(self.employee.employee_id, date.today()) self._pg_locks("after set employee and before show") widget.show() self._pg_locks("After second show") app.processEvents() self._pg_locks("After process events") app.processEvents() QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_F5, Qt.ShiftModifier) # modifier, delay app.processEvents() self._encode_imputable_operation() app.processEvents() widget.buttons.button(QDialogButtonBox.Ok).click() # app.exec_() self._pg_locks("when test finished")
def test_copy_paste_from_order_overview_to_order_edit(self): order = self._make_order() # An order with one part order_part = self._order_part_dao.make(order) order_part.description = u"Part 2" order_part.notes = "Notes 2" order_part.position = 2 self._order_part_dao.save(order_part) order_part = self._order_part_dao.make(order) order_part.description = u"Part 3" order_part.notes = "Notes 3" order_part.position = 3 self._order_part_dao.save(order_part) self._order_dao.change_order_state( order.order_id, OrderStatusType.order_ready_for_production) # self._order_dao.recompute_position_labels(order) ops = self.dao.operation_dao.operations_for_order_parts_frozen( [1011, 1014, 1013]) assert ops[1011] assert 1013 not in ops assert 1014 not in ops self.stack.setCurrentWidget(self.order_overview_widget) # self.order_overview_widget.month_today() self.order_overview_widget.refresh_action() self.order_overview_widget.retake_focus() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_A, Qt.ControlModifier) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_C, Qt.ControlModifier) # modifier, delay self.app.processEvents() # Now that we have copied, we'd like to paste ! self.stack.setCurrentWidget(self.edit_order_widget) self.edit_order_widget.edit_new_order(self.customer.customer_id) self.edit_order_widget.controller_part.view.setFocus( Qt.OtherFocusReason) QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_V, Qt.ControlModifier) # modifier, delay self.app.processEvents() QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_S, Qt.ControlModifier) # modifier, delay self.app.processEvents() order = self.order_dao.find_by_id(order.order_id) self.assertEqual(3, len(order.parts)) self.assertEqual(1, len(order.parts[0].operations)) self.assertEqual(0, len(order.parts[1].operations)) self.assertEqual(u"Notes 2", order.parts[1].notes) self.assertEqual(u"Notes 3", order.parts[2].notes)
def generateEvent(self): o = QTest.touchEvent(self) o.press(0, QPoint(10, 10)) o.commit() del o QTest.touchEvent(self).press(0, QPoint(10, 10)) QTest.touchEvent(self).stationary(0).press(1, QPoint(40, 10)) QTest.touchEvent(self).move(0, QPoint(12, 12)).move(1, QPoint(45, 5)) QTest.touchEvent(self).release(0, QPoint(12, 12)).release(1, QPoint(45, 5)) QTimer.singleShot(200, self.deleteLater)
def test_lulu_about_qt_box(self): """ Tests whether the about Qt dialog opens correctly via the menu """ # Make sure the dock widget is out of the way self.mw.history_dock_widget.hide() # Open file menu QTest.mouseClick( self.mw.menu_bar, QtCore.Qt.LeftButton, pos=self.mw.menu_bar.actionGeometry( self.mw.menu_help.menuAction()).center()) self.assertTrue(self.mw.menu_help.isVisible()) # As the modal about dialog will block in it's event queue, # queue the check itself. called = False def check_open_and_dismiss(window): nonlocal called self.assertIsInstance(window, QtGui.QMessageBox) QTest.keyClick(window, QtCore.Qt.Key_Escape) QtGui.QApplication.instance().processEvents() called = True delayed_perform_on_modal(check_open_and_dismiss) # Click about QTest.mouseClick( self.mw.menu_help, QtCore.Qt.LeftButton, pos=self.mw.menu_help.actionGeometry( self.mw.action_about_qt).center()) # # Modal event queue running here until dialog is dismissed # self.assertTrue(called) def is_main_window_active_yet(): self.app.processEvents() return self.app.activeWindow() == self.mw try_repeatedly(is_main_window_active_yet) self.assertEqual(self.app.activeWindow(), self.mw)
def test_encode_normal_delivery_slip(self): self._pg_locks("on start") app = self.app widget = self.widget order = self._make_order() order.parts[0].qty = 10 order.parts[0].sell_price = 10 self.order_dao.change_order_parts_state( order.order_id, [order.parts[0].order_part_id], OrderPartStateType.ready_for_production) self.show_order(order) widget.set_data(order.order_id) widget.show() widget._start_edit() app.processEvents() self._encode_part("5") self._pg_locks() for i in range(10000): # print(i) app.processEvents() self.prepare_to_click_dialog("confirmDSCreation") # from dialog_utils import confirmationBox # confirmationBox("uytyutyutyutyu","iyiuyuiyiuyuiy","teststetstetsets") # confirmationBox("uytyutyutyutyu","iyiuyuiyiuyuiy","teststetstetsets") mainlog.debug("submit form") for i in range(10000): # print(i) app.processEvents() # Submit form print((app.focusWidget())) QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_Enter) last_slip_id = self.delivery_slip_dao.find_last_slip_id() ds = self.delivery_slip_dao.find_by_id(last_slip_id) assert ds.delivery_slip_parts[0].quantity_out == 5 assert ds.delivery_slip_parts[0].order_part_id == order.parts[ 0].order_part_id
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 test_update_pushButton_will_call_environment_update_versions_method(self): """testing if update_pushButton will call Test_Environment.update_versions method """ self.assertRaises( KeyError, self.test_environment.test_data.__getitem__, 'update_versions' ) # self.show_dialog(self.dialog) QTest.mouseClick(self.dialog.update_pushButton, Qt.LeftButton) #print self.test_environment.test_data self.assertEqual( 1, self.test_environment.test_data['update_versions']['call_count'] )