Esempio n. 1
0
    def test_eventFilter_whenKeyCPressed_SelectsPreviousRowAndEmitsClickEvent(
            self, hosts_table_view, selection_model, selected_row,
            mock_clipboard):
        expected_data = MagicMock()
        expected_data.toString = Mock(return_value="some clipboard data")
        control_modifier = mock.patch.object(QApplication,
                                             'keyboardModifiers',
                                             return_value=Qt.ControlModifier)
        clipboard = mock.patch.object(QApplication,
                                      'clipboard',
                                      return_value=mock_clipboard)

        self.mock_view.ui.HostsTableView = hosts_table_view
        event_filter = MyEventFilter(self.mock_view, self.mock_main_window)
        self.simulateKeyPress(Qt.Key_C)
        self.mock_receiver = hosts_table_view
        selected_row.data = Mock(return_value=expected_data)
        selection_model.currentIndex = Mock(return_value=selected_row)
        self.mock_receiver.selectionModel = Mock(return_value=selection_model)

        with control_modifier, clipboard:
            result = event_filter.eventFilter(self.mock_receiver,
                                              self.mock_event)
            self.assertTrue(result)
            mock_clipboard.setText.assert_called_once_with(
                "some clipboard data")
Esempio n. 2
0
    def test_eventFilter_whenKeyPressedIsClose_InvokesAppExit(self):
        event_filter = MyEventFilter(self.mock_view, self.mock_main_window)
        self.mock_event.type = Mock(return_value=QEvent.Close)

        result = event_filter.eventFilter(self.mock_main_window,
                                          self.mock_event)
        self.assertTrue(result)
        self.mock_event.ignore.assert_called_once()
        self.mock_view.appExit.assert_called_once()
Esempio n. 3
0
    def test_eventFilter_whenKeyUpPressed_SelectsPreviousRowAndEmitsClickEvent(
            self, hosts_table_view, selection_model, selected_row):
        self.mock_view.ui.HostsTableView = hosts_table_view
        event_filter = MyEventFilter(self.mock_view, self.mock_main_window)
        self.simulateKeyPress(Qt.Key_Up)
        self.mock_receiver = hosts_table_view
        selected_row.row = Mock(return_value=1)
        selection_model.selectedRows = Mock(return_value=[selected_row])
        self.mock_receiver.selectionModel = Mock(return_value=selection_model)

        result = event_filter.eventFilter(self.mock_receiver, self.mock_event)
        self.assertTrue(result)
        self.mock_receiver.selectRow.assert_called_once_with(0)
        self.mock_receiver.clicked.emit.assert_called_with(selected_row)
Esempio n. 4
0
    projectManager = ProjectManager(shell, repositoryFactory, appLogger)
    nmapExporter = DefaultNmapExporter(shell, appLogger)
    toolCoordinator = ToolCoordinator(shell, nmapExporter)
    # Model prep (logic, db and models)
    logic = Logic(shell, projectManager, toolCoordinator)

    startupLog.info("Creating temporary project at application start...")
    logic.createNewTemporaryProject()

    viewState = ViewState()
    view = View(viewState, ui, MainWindow, shell)  # View prep (gui)
    controller = Controller(
        view, logic)  # Controller prep (communication between model and view)
    view.qss = qss_file

    myFilter = MyEventFilter(view, MainWindow)  # to capture events
    app.installEventFilter(myFilter)

    # Center the application in screen
    x = app.desktop().screenGeometry().center().x()
    y = app.desktop().screenGeometry().center().y()
    MainWindow.move(x - MainWindow.geometry().width() / 2,
                    y - MainWindow.geometry().height() / 2)

    # Show main window
    MainWindow.show()

    startupLog.info("Legion started successfully.")
    try:
        loop.run_forever()
    except KeyboardInterrupt:
Esempio n. 5
0
 def test_eventFilter_onDefaultAction_CallsParentEventFilter(self):
     event_filter = MyEventFilter(self.mock_view, self.mock_main_window)
     result = event_filter.eventFilter(QObject(), QEvent(QEvent.Scroll))
     self.assertFalse(result)