From f702dfbacc21c8347220d048e57681087ddfc123 Mon Sep 17 00:00:00 2001 From: Rohit prasad Date: Wed, 10 Apr 2024 01:58:57 +0530 Subject: [PATCH 1/4] seeing how it goes through CI --- tests/_test_msui/test_mscolab.py | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/_test_msui/test_mscolab.py b/tests/_test_msui/test_mscolab.py index aed8b0967..8366c3789 100644 --- a/tests/_test_msui/test_mscolab.py +++ b/tests/_test_msui/test_mscolab.py @@ -26,6 +26,7 @@ """ import os import sys +import weakref import fs import fs.errors import fs.opener.errors @@ -411,6 +412,64 @@ def assert_logout_text(): qtbot.wait_until(assert_label_text) # ToDo verify all operations disabled again without a visual check + def test_operation_while_switching_error(self, qtbot): + """Test that operation switching trigger the KeyError""" + + # more operations for the user + for op_name in ["second", "third"]: + assert add_operation(op_name, "description") + assert add_user_to_operation(path=op_name, emailid=self.userdata[0]) + + self._connect_to_mscolab(qtbot) + modify_config_file({"MSS_auth": {self.url: self.userdata[0]}}) + self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2]) + + # test after activating operation + self._activate_operation_at_index(0) + self.window.actionTopView.trigger() + + def assert_active_views(): + # check 1 view opened + assert len(self.window.get_active_views()) == 1 + qtbot.wait_until(assert_active_views) + topview_0 = self.window.listViews.item(0) + + # open multiple flightpath + topview_0.window.cbTools.currentIndexChanged.emit(6) + + # activate all operation, this enables them in the docking widget too + for _ in range(4): + self._activate_operation_at_index(1) + self._activate_operation_at_index(2) + self._activate_operation_at_index(0) + # ToDo refactor to be able to activate/deactivate by the docking widget and that it can be checked + + self._activate_flight_track_at_index(0) + with mock.patch("PyQt5.QtWidgets.QMessageBox.warning", return_value=QtWidgets.QMessageBox.Yes): + topview_0.window.close() + + def assert_window_closed(): + ref = weakref.ref(topview_0.window) + assert ref() is None + qtbot.wait_until(assert_window_closed) + + def assert_label_text(): + # verify logged in + assert self.window.usernameLabel.text() == self.userdata[1] + qtbot.wait_until(assert_label_text) + + self.window.mscolab.logout() + + def assert_logout_text(): + assert self.window.usernameLabel.text() == "User" + qtbot.wait_until(assert_logout_text) + + self._connect_to_mscolab(qtbot) + self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2]) + # verify logged in again + qtbot.wait_until(assert_label_text) + # ToDo verify all operations disabled again without a visual check + @mock.patch("PyQt5.QtWidgets.QFileDialog.getSaveFileName", return_value=(fs.path.join(mscolab_settings.MSCOLAB_DATA_DIR, 'test_export.ftml'), "Flight track (*.ftml)")) @@ -828,3 +887,12 @@ def _activate_operation_at_index(self, index): point = self.window.listOperationsMSC.visualItemRect(item).center() QtTest.QTest.mouseClick(self.window.listOperationsMSC.viewport(), QtCore.Qt.LeftButton, pos=point) QtTest.QTest.mouseDClick(self.window.listOperationsMSC.viewport(), QtCore.Qt.LeftButton, pos=point) + + def _activate_flight_track_at_index(self, index): + # The main window must be on top + self.window.activateWindow() + # get the item by its index + item = self.window.listFlightTracks.item(index) + point = self.window.listFlightTracks.visualItemRect(item).center() + QtTest.QTest.mouseClick(self.window.listFlightTracks.viewport(), QtCore.Qt.LeftButton, pos=point) + QtTest.QTest.mouseDClick(self.window.listFlightTracks.viewport(), QtCore.Qt.LeftButton, pos=point) From 1c2191fb7ea19087d220c1a0ca69b499cb8dbd92 Mon Sep 17 00:00:00 2001 From: rohit Date: Sun, 14 Apr 2024 00:49:01 +0530 Subject: [PATCH 2/4] updated --- tests/_test_msui/test_mscolab.py | 37 +++++++++++--------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/tests/_test_msui/test_mscolab.py b/tests/_test_msui/test_mscolab.py index 8366c3789..5b94fdee7 100644 --- a/tests/_test_msui/test_mscolab.py +++ b/tests/_test_msui/test_mscolab.py @@ -33,6 +33,7 @@ import requests.exceptions import mock import pytest +import random import mslib.utils.auth from mslib.mscolab.conf import mscolab_settings @@ -433,30 +434,18 @@ def assert_active_views(): assert len(self.window.get_active_views()) == 1 qtbot.wait_until(assert_active_views) topview_0 = self.window.listViews.item(0) + assert topview_0.window.tv_window_exists is True + topview_0.window.setAttribute(QtCore.Qt.WA_DeleteOnClose) # open multiple flightpath topview_0.window.cbTools.currentIndexChanged.emit(6) # activate all operation, this enables them in the docking widget too - for _ in range(4): - self._activate_operation_at_index(1) - self._activate_operation_at_index(2) - self._activate_operation_at_index(0) - # ToDo refactor to be able to activate/deactivate by the docking widget and that it can be checked - - self._activate_flight_track_at_index(0) - with mock.patch("PyQt5.QtWidgets.QMessageBox.warning", return_value=QtWidgets.QMessageBox.Yes): - topview_0.window.close() - - def assert_window_closed(): - ref = weakref.ref(topview_0.window) - assert ref() is None - qtbot.wait_until(assert_window_closed) - - def assert_label_text(): - # verify logged in - assert self.window.usernameLabel.text() == self.userdata[1] - qtbot.wait_until(assert_label_text) + for _ in range(6): + self._activate_operation_at_index(random.randint(0, 2)) + self._activate_operation_at_index(random.randint(0, 2)) + self._activate_operation_at_index(random.randint(0, 2)) + self._activate_flight_track_at_index(0) self.window.mscolab.logout() @@ -464,11 +453,11 @@ def assert_logout_text(): assert self.window.usernameLabel.text() == "User" qtbot.wait_until(assert_logout_text) - self._connect_to_mscolab(qtbot) - self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2]) - # verify logged in again - qtbot.wait_until(assert_label_text) - # ToDo verify all operations disabled again without a visual check + with pytest.raises(TypeError): + for _ in range(6): + self._activate_operation_at_index(random.randint(0, 2)) + self._activate_operation_at_index(random.randint(0, 2)) + self._activate_operation_at_index(random.randint(0, 2)) @mock.patch("PyQt5.QtWidgets.QFileDialog.getSaveFileName", return_value=(fs.path.join(mscolab_settings.MSCOLAB_DATA_DIR, 'test_export.ftml'), From d776c0a62f6b5b673ef46b80874137dd5a650116 Mon Sep 17 00:00:00 2001 From: rohit Date: Sun, 14 Apr 2024 01:48:12 +0530 Subject: [PATCH 3/4] updated II --- tests/_test_msui/test_mscolab.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/_test_msui/test_mscolab.py b/tests/_test_msui/test_mscolab.py index 5b94fdee7..06a892696 100644 --- a/tests/_test_msui/test_mscolab.py +++ b/tests/_test_msui/test_mscolab.py @@ -26,7 +26,6 @@ """ import os import sys -import weakref import fs import fs.errors import fs.opener.errors @@ -433,9 +432,9 @@ def assert_active_views(): # check 1 view opened assert len(self.window.get_active_views()) == 1 qtbot.wait_until(assert_active_views) + topview_0 = self.window.listViews.item(0) assert topview_0.window.tv_window_exists is True - topview_0.window.setAttribute(QtCore.Qt.WA_DeleteOnClose) # open multiple flightpath topview_0.window.cbTools.currentIndexChanged.emit(6) @@ -443,9 +442,16 @@ def assert_active_views(): # activate all operation, this enables them in the docking widget too for _ in range(6): self._activate_operation_at_index(random.randint(0, 2)) - self._activate_operation_at_index(random.randint(0, 2)) - self._activate_operation_at_index(random.randint(0, 2)) - self._activate_flight_track_at_index(0) + self._activate_flight_track_at_index(0) + + # Create the new operation + op_name = "fourth" + assert add_operation(op_name, "description") + assert add_user_to_operation(path=op_name, emailid=self.userdata[0]) + + for _ in range(4): + self._activate_operation_at_index(random.randint(0, 3)) + self._activate_flight_track_at_index(0) self.window.mscolab.logout() @@ -453,12 +459,6 @@ def assert_logout_text(): assert self.window.usernameLabel.text() == "User" qtbot.wait_until(assert_logout_text) - with pytest.raises(TypeError): - for _ in range(6): - self._activate_operation_at_index(random.randint(0, 2)) - self._activate_operation_at_index(random.randint(0, 2)) - self._activate_operation_at_index(random.randint(0, 2)) - @mock.patch("PyQt5.QtWidgets.QFileDialog.getSaveFileName", return_value=(fs.path.join(mscolab_settings.MSCOLAB_DATA_DIR, 'test_export.ftml'), "Flight track (*.ftml)")) From 765a50d980fc866ed8984088a7622d1611d5e861 Mon Sep 17 00:00:00 2001 From: rohit Date: Thu, 18 Apr 2024 00:17:31 +0530 Subject: [PATCH 4/4] modified test --- tests/_test_msui/test_mscolab.py | 48 +++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/_test_msui/test_mscolab.py b/tests/_test_msui/test_mscolab.py index d1c553c54..55f828520 100644 --- a/tests/_test_msui/test_mscolab.py +++ b/tests/_test_msui/test_mscolab.py @@ -415,15 +415,6 @@ def assert_logout_text(): def test_operation_while_switching_error(self, qtbot): """Test that operation switching trigger the KeyError""" - # more operations for the user - for op_name in ["second", "third"]: - assert add_operation(op_name, "description") - assert add_user_to_operation(path=op_name, emailid=self.userdata[0]) - - self._connect_to_mscolab(qtbot) - modify_config_file({"MSS_auth": {self.url: self.userdata[0]}}) - self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2]) - # test after activating operation self._activate_operation_at_index(0) self.window.actionTopView.trigger() @@ -435,23 +426,48 @@ def assert_active_views(): topview_0 = self.window.listViews.item(0) assert topview_0.window.tv_window_exists is True + # topview_0.window.setAttribute(QtCore.Qt.WA_DeleteOnClose) + + # def assert_attribute(): + # assert topview_0.window.testAttribute(QtCore.Qt.WA_DeleteOnClose) + # qtbot.wait_until(assert_attribute) # open multiple flightpath topview_0.window.cbTools.currentIndexChanged.emit(6) + def assert_dock_loaded(): + assert topview_0.window.docks[5] is not None + qtbot.wait_until(assert_dock_loaded) + + # more operations for the user + for op_name in ["second", "third"]: + assert add_operation(op_name, "description") + assert add_user_to_operation(path=op_name, emailid=self.userdata[0]) + + self._connect_to_mscolab(qtbot) + modify_config_file({"MSS_auth": {self.url: self.userdata[0]}}) + self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2]) + # activate all operation, this enables them in the docking widget too for _ in range(6): self._activate_operation_at_index(random.randint(0, 2)) self._activate_flight_track_at_index(0) - # Create the new operation - op_name = "fourth" - assert add_operation(op_name, "description") - assert add_user_to_operation(path=op_name, emailid=self.userdata[0]) + # # Create the new operation + # op_name = "fourth" + # assert add_operation(op_name, "description") + # assert add_user_to_operation(path=op_name, emailid=self.userdata[0]) + # + # for _ in range(4): + # self._activate_operation_at_index(random.randint(0, 3)) + # self._activate_flight_track_at_index(0) - for _ in range(4): - self._activate_operation_at_index(random.randint(0, 3)) - self._activate_flight_track_at_index(0) + with mock.patch("PyQt5.QtWidgets.QMessageBox.warning", return_value=QtWidgets.QMessageBox.Yes): + topview_0.window.close() + + def assert_window_closed(): + assert topview_0.window.tv_window_exists is False + qtbot.wait_until(assert_window_closed) self.window.mscolab.logout()