Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logout problem with multipe flightpath docking widget #2319

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mslib/msui/topview.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ def __init__(self, parent=None, mainwindow=None, model=None, _id=None,
self.mainwindow_signal_permission_revoked = mainwindow.signal_permission_revoked
self.mainwindow_signal_render_new_permission = mainwindow.signal_render_new_permission
self.mainwindow_signal_activate_flighttrack = mainwindow.signal_activate_flighttrack
self.mainwindow_signal_activate_operation = mainwindow.signal_activate_operation
self.mainwindow_signal_login_mscolab = mainwindow.signal_login_mscolab
self.mainwindow_signal_logout_mscolab = mainwindow.signal_logout_mscolab
self.mainwindow_listFlightTracks = mainwindow.listFlightTracks
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those lines were duplicated

self.mainwindow_filterCategoryCb = mainwindow.filterCategoryCb
self.mainwindow_listOperationsMSC = mainwindow.listOperationsMSC
Expand Down Expand Up @@ -362,7 +359,7 @@ def openTool(self, index):
mscolab_server_url=self.mscolab_server_url,
token=self.token)

self.mainwindow_signal_logout_mscolab.connect(lambda: self.signal_logout_mscolab.emit())
self.mainwindow_signal_logout_mscolab.connect(self.signal_logout_mscolab.emit)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in #2310 (commits) this was the culprit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please file an issue to change this type of lambda everywhere? I've seen it in other places as well and the construct is generally problematic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a follow up: #2320

self.mainwindow_signal_listFlighttrack_doubleClicked.connect(
lambda: self.signal_listFlighttrack_doubleClicked.emit())
self.mainwindow_signal_permission_revoked.connect(
Expand Down
77 changes: 77 additions & 0 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,74 @@ def assert_logout_text():
qtbot.wait_until(assert_label_text)
# ToDo verify all operations disabled again without a visual check

def test_multiple_flightpath_switching_to_flighttrack_and_logout(self, qtbot):
"""
checks that we can switch in topviews with the multiple flightpath dockingwidget
between local flight track and operations, and we are able to cycle a login/logout
"""
# 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)
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)
Comment on lines +440 to +442
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that setAttribute is an immediate action that does not require this kind of wait, but I wouldn't know how to find out if this is definitely the case.


# open multiple flightpath first window
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)

# activate all operation, this enables them in the docking widget too
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():
assert topview_0.window.tv_window_exists is False
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)
Comment on lines +465 to +468
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self._login method is implemented in a way that the login should be finished by the time it returns (i.e. it does such a wait internally). That means this wait_until could be a plain assert, same with where it is used again further down. This only applies to the login though, not to the logout.


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)"))
Expand Down Expand Up @@ -828,3 +896,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)