コード例 #1
0
ファイル: test_mss_pyui.py プロジェクト: aravindm711/MSS
    def test_add_plugins(self, mockopen, mockbox):
        assert len(self.window.menuImportFlightTrack.actions()) == 2
        assert len(self.window.menuExportActiveFlightTrack.actions()) == 2
        assert len(self.window.import_plugins) == 1
        assert len(self.window.export_plugins) == 1

        self.window.remove_plugins()
        self.window.add_import_plugins("qt")
        self.window.add_export_plugins("qt")
        assert len(self.window.import_plugins) == 1
        assert len(self.window.export_plugins) == 1
        assert len(self.window.menuImportFlightTrack.actions()) == 2
        assert len(self.window.menuExportActiveFlightTrack.actions()) == 2
        assert mockbox.critical.call_count == 0

        self.window.remove_plugins()
        with mock.patch("importlib.import_module",
                        new=ExceptionMock(Exception()).raise_exc):
            self.window.add_import_plugins("qt")
            self.window.add_export_plugins("qt")
            assert mockbox.critical.call_count == 2

        self.window.remove_plugins()
        with mock.patch("mslib.msui.mss_pyui.MSSMainWindow.add_plugin_submenu",
                        new=ExceptionMock(Exception()).raise_exc):
            self.window.add_import_plugins("qt")
            self.window.add_export_plugins("qt")
            assert mockbox.critical.call_count == 4

        self.window.remove_plugins()
        assert len(self.window.import_plugins) == 0
        assert len(self.window.export_plugins) == 0
        assert len(self.window.menuImportFlightTrack.actions()) == 1
        assert len(self.window.menuExportActiveFlightTrack.actions()) == 1
コード例 #2
0
    def test_create_dir_exceptions(self, mockexit, mockbox):
        with mock.patch("fs.open_fs", new=ExceptionMock(fs.errors.CreateFailed).raise_exc):
            self.window.data_dir = "://"
            self.window.create_dir()
            assert mockbox.critical.call_count == 1
            assert mockexit.call_count == 1

        with mock.patch("fs.open_fs", new=ExceptionMock(fs.opener.errors.UnsupportedProtocol).raise_exc):
            self.window.data_dir = "://"
            self.window.create_dir()
            assert mockbox.critical.call_count == 2
            assert mockexit.call_count == 2
コード例 #3
0
    def test_add_plugins(self, mockopen, mockbox):
        assert len(self.window.menuImport_Flight_Track.actions()) == 1
        assert len(self.window.menuExport_Active_Flight_Track.actions()) == 1
        assert len(self.window._imported_plugins) == 0
        assert len(self.window._exported_plugins) == 0
        self.window.add_plugins()
        assert len(self.window._imported_plugins) == 1
        assert len(self.window._exported_plugins) == 1
        assert len(self.window.menuImport_Flight_Track.actions()) == 2
        assert len(self.window.menuExport_Active_Flight_Track.actions()) == 2
        assert mockbox.critical.call_count == 0

        with mock.patch("importlib.import_module", new=ExceptionMock(Exception()).raise_exc):
            self.window.add_plugins()
            assert mockbox.critical.call_count == 2
        with mock.patch("mslib.msui.mss_pyui.MSSMainWindow.add_import_filter",
                        new=ExceptionMock(Exception()).raise_exc):
            self.window.add_plugins()
            assert mockbox.critical.call_count == 4

        self.window.remove_plugins()
        assert len(self.window.menuImport_Flight_Track.actions()) == 1
        assert len(self.window.menuExport_Active_Flight_Track.actions()) == 1
コード例 #4
0
ファイル: test_mscolab.py プロジェクト: Open-MSS/MSS
    def test_connect(self, mockset):
        for exc in [
                requests.exceptions.ConnectionError,
                requests.exceptions.InvalidSchema,
                requests.exceptions.InvalidURL, requests.exceptions.SSLError,
                Exception("")
        ]:
            with mock.patch("requests.get", new=ExceptionMock(exc).raise_exc):
                self.window.connect_handler()

        self._connect_to_mscolab()
        assert mockset.call_args_list == [
            mock.call("color: red;") for _ in range(5)
        ] + [mock.call("color: green;")]
コード例 #5
0
    def test_failed_authorize(self, mockbox, mockauth):
        class response:
            def __init__(self, code, text):
                self.status_code = code
                self.text = text

        self._connect_to_mscolab()
        with mock.patch("requests.Session.post", new=ExceptionMock(requests.exceptions.ConnectionError).raise_exc):
            self._login()
        with mock.patch("requests.Session.post", return_value=response(201, "False")):
            self._login()
        with mock.patch("requests.Session.post", return_value=response(401, "False")):
            self._login()

        # No return after self.error_dialog.showMessage('Oh no, server authentication were incorrect.')
        # causes 4 instead of 3 messages, I am not sure if this is on purpose.
        assert mockbox.return_value.showMessage.call_count == 4
コード例 #6
0
    def test_login(self, mockbox):
        self._connect_to_mscolab()
        self._login()
        # screen shows logout button
        assert self.window.label.text() == 'Welcome, a'
        assert self.window.loginWidget.isVisible() is False
        # test project listing visibility
        assert self.window.listProjects.model().rowCount() == 3
        # test logout
        QtTest.QTest.mouseClick(self.window.logoutButton, QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()
        assert self.window.listProjects.model().rowCount() == 0
        # ToDo understand why this is not cleared
        # assert self.window.label.text() == ""
        assert self.window.conn is None

        for exc in [requests.exceptions.ConnectionError, requests.exceptions.InvalidSchema,
                    requests.exceptions.InvalidURL, requests.exceptions.SSLError, Exception("")]:
            with mock.patch("requests.get", new=ExceptionMock(exc).raise_exc):
                self.window.connect_handler()
        assert mockbox.critical.call_count == 5
コード例 #7
0
ファイル: test_mscolab.py プロジェクト: Open-MSS/MSS
    def test_failed_authorize(self):
        class response:
            def __init__(self, code, text):
                self.status_code = code
                self.text = text

        # case: connection error when trying to login after connecting to server
        self._connect_to_mscolab()
        with mock.patch("PyQt5.QtWidgets.QWidget.setStyleSheet") as mockset:
            with mock.patch(
                    "requests.Session.post",
                    new=ExceptionMock(
                        requests.exceptions.ConnectionError).raise_exc):
                self._login()
                mockset.assert_has_calls(
                    [mock.call("color: red;"),
                     mock.call("")])

        # case: when the credentials are incorrect for login
        self._connect_to_mscolab()
        with mock.patch("PyQt5.QtWidgets.QWidget.setStyleSheet") as mockset:
            with mock.patch("requests.Session.post",
                            return_value=response(201, "False")):
                self._login()
                mockset.assert_has_calls([mock.call("color: red;")])

        # case: when http auth fails
        with mock.patch("PyQt5.QtWidgets.QWidget.setStyleSheet") as mockset:
            with mock.patch("requests.Session.post",
                            return_value=response(401, "Unauthorized Access")):
                self._login()
                # check if switched to HTTP Auth Page
                assert self.window.stackedWidget.currentIndex() == 2
                # press ok without entering server auth details
                okWidget = self.window.httpBb.button(self.window.httpBb.Ok)
                QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
                QtWidgets.QApplication.processEvents()
                mockset.assert_has_calls([mock.call("color: red;")])