Skip to content

Commit

Permalink
fixed view appearance; started test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindm711 committed Jun 29, 2021
1 parent 7895db8 commit 2354ae9
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 67 deletions.
96 changes: 85 additions & 11 deletions mslib/msui/_tests/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,98 @@
from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.models import Permission, User
from mslib.msui.flighttrack import WaypointsTableModel
from mslib.msui.mscolab import MSSMscolabWindow
# from mslib.msui.mscolab import MSSMscolabWindow
from PyQt5 import QtCore, QtTest, QtWidgets
from mslib._tests.utils import mscolab_start_server
import mslib.msui.mss_pyui as mss_pyui
from mslib.msui import mscolab


PORTS = list(range(9481, 9530))


@pytest.mark.skipif(os.name == "nt",
reason="multiprocessing needs currently start_method fork")
class Test_Mscolab_connect_window():
def setup(self):
self.process, self.url, self.app, _, self.cm, self.fm = mscolab_start_server(PORTS)
QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.main_window = mss_pyui.MSSMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.main_window.show()
self.window = mscolab.MSColab_ConnectDialog(parent=self.main_window, mscolab=self.main_window.mscolab)
self.window.urlCb.setEditText(self.url)
self.main_window.mscolab.connect_window = self.window

def teardown(self):
self.window.hide()
self.main_window.hide()
QtWidgets.QApplication.processEvents()
self.application.quit()
QtWidgets.QApplication.processEvents()
self.process.terminate()

def _connect_to_mscolab(self):
self.window.urlCb.setEditText(self.url)
QtTest.QTest.mouseClick(self.window.connectBtn, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
QtTest.QTest.qWait(500)

def _login(self, emailid="a", password="a"):
self.window.loginEmailLe.setText(emailid)
self.window.loginPasswordLe.setText(password)
QtTest.QTest.mouseClick(self.window.loginBtn, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
QtTest.QTest.qWait(500)

@mock.patch("mslib.msui.mscolab.QtWidgets.QErrorMessage.showMessage")
def _create_user(self, username, email, password, mockbox):
QtTest.QTest.mouseClick(self.window.addUserBtn, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
self.window.newUsernameLe.setText(str(username))
QtWidgets.QApplication.processEvents()
self.window.newEmailLe.setText(str(email))
QtWidgets.QApplication.processEvents()
self.window.newPasswordLe.setText(str(password))
QtWidgets.QApplication.processEvents()
self.window.newConfirmPasswordLe.setText(str(password))
QtWidgets.QApplication.processEvents()
okWidget = self.window.newUserBb.button(self.window.newUserBb.Ok)
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
# ToDo get rid of that QMessageBox

def test_url_combo(self):
assert self.window.urlCb.count() >= 1

def test_login(self):
# pytest.skip("Failing randomly for unknown reasons #870")
self._connect_to_mscolab()
self._login()
QtWidgets.QApplication.processEvents()
# show logged in widgets
assert self.main_window.usernameLabel.text() == 'a'
assert self.main_window.mscolab.connect_window is None
# test project listing visibility
assert self.main_window.listProjectsMSC.model().rowCount() == 3
# test logout
self.main_window.mscolab.logout_action.trigger()
QtWidgets.QApplication.processEvents()
assert self.main_window.listProjectsMSC.model().rowCount() == 0
# ToDo understand why this is not cleared
# assert self.window.label.text() == ""
assert self.main_window.mscolab.conn is None

def test_add_user(self):
self._connect_to_mscolab()
self._create_user("something", "something@something.org", "something")
self._login("something@something.org", "something")
# screen shows logout button
assert self.main_window.usernameLabel.text() == 'something'
assert self.main_window.mscolab.connect_window is None


# @pytest.mark.skipif(os.name == "nt",
# reason="multiprocessing needs currently start_method fork")
@pytest.mark.skip(reason="Yet to refactor for new UI")
class Test_Mscolab(object):
sample_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "docs", "samples", "flight-tracks")

Expand Down Expand Up @@ -221,14 +303,6 @@ def test_add_project(self):
self._create_project("Alpha", "Description Alpha")
assert self.window.listProjects.model().rowCount() == 1

def test_add_user(self):
self._connect_to_mscolab()
self._create_user("something", "something@something.org", "something")
self._login("something@something.org", "something")
# screen shows logout button
assert self.window.label.text() == 'Welcome, something'
assert self.window.loginWidget.isVisible() is False

def test_close_help_dialog(self):
QtTest.QTest.mouseClick(self.window.helpBtn, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
Expand Down
19 changes: 11 additions & 8 deletions mslib/msui/_tests/test_mss_pyui.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_plugin_csv_read(self, mockopen):
assert self.window.listFlightTracks.count() == 1
assert mockopen.call_count == 0
self.window.last_save_directory = self.sample_path
self.window.actionImportFlightTrackCSV()
self.window.actionImportFlightTrackCSV.trigger()
QtWidgets.QApplication.processEvents()
assert self.window.listFlightTracks.count() == 2
assert mockopen.call_count == 1
Expand All @@ -170,27 +170,29 @@ def test_plugin_csv_write(self, mocksave):
assert self.window.listFlightTracks.count() == 1
assert mocksave.call_count == 0
self.window.last_save_directory = ROOT_DIR
self.window.actionExportFlightTrackCSV()
self.window.actionExportFlightTrackCSV.trigger()
assert mocksave.call_count == 1
assert os.path.exists(self.save_csv)
os.remove(self.save_csv)

@mock.patch("mslib.msui.mss_pyui.get_open_filename", return_value=os.path.join(sample_path, u"example.txt"))
def test_plugin_txt_read(self, mockopen):
self.window.add_import_filter("_TXT", "txt", load_from_txt)
self.window.add_plugin_submenu("_TXT", "txt", plugin_type="Import")
self.window.import_plugins['txt'] = load_from_txt
assert self.window.listFlightTracks.count() == 1
assert mockopen.call_count == 0
self.window.last_save_directory = self.sample_path
self.window.actionImportFlightTrack_TXT()
self.window.actionImportFlightTrack_TXT.trigger()
assert mockopen.call_count == 1
QtWidgets.QApplication.processEvents()
assert self.window.listFlightTracks.count() == 2

@mock.patch("mslib.msui.mss_pyui.get_save_filename", return_value=save_txt)
def test_plugin_txt_write(self, mocksave):
self.window.add_export_filter("_TXT", "txt", save_to_txt)
self.window.add_plugin_submenu("_TXT", "txt", plugin_type="Export")
self.window.export_plugins['txt'] = save_to_txt
self.window.last_save_directory = ROOT_DIR
self.window.actionExportFlightTrack_TXT()
self.window.actionExportFlightTrack_TXT.trigger()
assert mocksave.call_count == 1
QtWidgets.QApplication.processEvents()
assert self.window.listFlightTracks.count() == 1
Expand All @@ -201,9 +203,10 @@ def test_plugin_txt_write(self, mocksave):
return_value=os.path.join(sample_path, u"flitestar.txt"))
def test_plugin_flitestar(self, mockopen):
self.window.last_save_directory = self.sample_path
self.window.add_import_filter("_FliteStar", "txt", load_from_flitestar)
self.window.add_plugin_submenu("_FliteStar", "fls", plugin_type="Import")
self.window.import_plugins['fls'] = load_from_flitestar
assert self.window.listFlightTracks.count() == 1
self.window.actionImportFlightTrack_FliteStar()
self.window.actionImportFlightTrack_FliteStar.trigger()
QtWidgets.QApplication.processEvents()
assert self.window.listFlightTracks.count() == 2
assert mockopen.call_count == 1
5 changes: 4 additions & 1 deletion mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def open_connect_window(self):

def after_login(self, emailid, url, r):
self.connect_window.close()
self.connect_window = None
# fill value of mscolab url if found in QSettings storage
self.settings = load_settings_qsettings('mscolab', default_settings={'auth': {}, 'server_settings': {}})

Expand All @@ -457,7 +458,7 @@ def after_login(self, emailid, url, r):
self.user_menu = QtWidgets.QMenu()
# self.user_menu.addAction("Profile")
# self.user_menu.addAction("Help")
self.user_menu.addAction("Logout", self.logout)
self.logout_action = self.user_menu.addAction("Logout", self.logout)
self.ui.userOptionsTb.setPopupMode(QtWidgets.QToolButton.InstantPopup)
self.ui.userOptionsTb.setMenu(self.user_menu)
self.ui.userOptionsTb.show()
Expand Down Expand Up @@ -1300,6 +1301,8 @@ def change_view_wp_model(self):
self.create_view_msc(_type)
self.ui.raise_()
self.ui.activateWindow()
# for window in self.active_view_windows[:]:
# window.setFlightTrackModel(self.waypoints_model)

def force_close_view_windows(self):
for window in self.active_view_windows[:]:
Expand Down
55 changes: 28 additions & 27 deletions mslib/msui/mss_pyui.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class MSSMainWindow(QtWidgets.QMainWindow, ui.Ui_MSSMainWindow):

viewsChanged = QtCore.pyqtSignal(name="viewsChanged")

def __init__(self, *args):
def __init__(self, mscolab_data_dir=None, *args):
super(MSSMainWindow, self).__init__(*args)
self.setupUi(self)
self.setWindowIcon(QtGui.QIcon(icons('32x32')))
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(self, *args):
self.statusBar.showMessage(self.status())

# Create MSColab instance to handle all MSColab functionalities
self.mscolab = mscolab.MSSMscolab(parent=self)
self.mscolab = mscolab.MSSMscolab(parent=self, data_dir=mscolab_data_dir)

# Setting up MSColab Tab
self.connectBtn.clicked.connect(self.mscolab.open_connect_window)
Expand Down Expand Up @@ -357,30 +357,30 @@ def preload_wms(urls):
logging.debug("Contents of WMS_SERVICE_CACHE: %s", wms_control.WMS_SERVICE_CACHE.keys())
pdlg.close()

def add_plugin_submenu(self, name, extension, plugin_type="Import"):
if plugin_type == "Import":
menu = self.menuImportFlightTrack
action_name = "actionImportFlightTrack" + clean_string(name)
handler = self.handle_import_local
elif plugin_type == "Export":
menu = self.menuExportActiveFlightTrack
action_name = "actionExportFlightTrack" + clean_string(name)
handler = self.handle_export_local

if hasattr(self, action_name):
raise ValueError(f"'{action_name}' has already been set!")
action = QtWidgets.QAction(self)
action.setObjectName(action_name)
action.setText(QtCore.QCoreApplication.translate("MSSMainWindow", name, None))
action.triggered.connect(functools.partial(handler, name, extension))
menu.addAction(action)
setattr(self, action_name, action)

def add_plugins(self):
def add_plugin_submenu(name, extension, plugin_type="Import"):
if plugin_type == "Import":
menu = self.menuImportFlightTrack
action_name = "actionImportFlightTrack" + clean_string(name)
handler = self.handle_import_local
elif plugin_type == "Export":
menu = self.menuExportActiveFlightTrack
action_name = "actionExportFlightTrack" + clean_string(name)
handler = self.handle_export_local

if hasattr(self, action_name):
raise ValueError(f"'{action_name}' has already been set!")
action = QtWidgets.QAction(self)
action.setObjectName(action_name)
action.setText(QtCore.QCoreApplication.translate("MSSMainWindow", name, None))
action.triggered.connect(functools.partial(handler, name, extension))
menu.addAction(action)
setattr(self, action_name, action)

add_plugin_submenu("FTML", "ftml", plugin_type="Import")
add_plugin_submenu("CSV", "csv", plugin_type="Import")
add_plugin_submenu("FTML", "ftml", plugin_type="Export")
add_plugin_submenu("CSV", "csv", plugin_type="Export")
self.add_plugin_submenu("FTML", "ftml", plugin_type="Import")
self.add_plugin_submenu("CSV", "csv", plugin_type="Import")
self.add_plugin_submenu("FTML", "ftml", plugin_type="Export")
self.add_plugin_submenu("CSV", "csv", plugin_type="Export")
self.actionImportFlightTrackFTML.setVisible(False)
self.actionExportFlightTrackFTML.setVisible(False)

Expand All @@ -391,7 +391,7 @@ def add_plugin_submenu(name, extension, plugin_type="Import"):
try:
imported_module = importlib.import_module(module)
self.import_plugins[extension] = getattr(imported_module, function)
add_plugin_submenu(name, extension, plugin_type="Import")
self.add_plugin_submenu(name, extension, plugin_type="Import")
# wildcard exception to be resilient against error introduced by user code
except Exception as ex:
logging.error("Error on import: %s: %s", type(ex), ex)
Expand All @@ -407,7 +407,7 @@ def add_plugin_submenu(name, extension, plugin_type="Import"):
try:
imported_module = importlib.import_module(module)
self.export_plugins[extension] = getattr(imported_module, function)
add_plugin_submenu(name, extension, plugin_type="Export")
self.add_plugin_submenu(name, extension, plugin_type="Export")
# wildcard exception to be resilient against error introduced by user code
except Exception as ex:
logging.error("Error on import: %s: %s", type(ex), ex)
Expand Down Expand Up @@ -880,6 +880,7 @@ def main():
application.setApplicationDisplayName("MSS")
application.setAttribute(QtCore.Qt.AA_DisableWindowContextHelpButton)
mainwindow = MSSMainWindow()
mainwindow.setStyleSheet("QListWidget { border: 1px solid grey; }")
mainwindow.create_new_flight_track()
mainwindow.show()
sys.exit(application.exec_())
Expand Down
5 changes: 1 addition & 4 deletions mslib/msui/qt5/ui_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setupUi(self, MSSMainWindow):
self.userOptionsHL.setStretch(0, 1)
self.verticalLayout.addLayout(self.userOptionsHL)
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setStyleSheet("::tab-bar { alignment: left; } ::pane{}")
self.tabWidget.setStyleSheet("::tab-bar { alignment: left; } ::pane {}")
self.tabWidget.setObjectName("tabWidget")
self.localTab = QtWidgets.QWidget()
self.localTab.setObjectName("localTab")
Expand All @@ -54,7 +54,6 @@ def setupUi(self, MSSMainWindow):
self.gridLayout_4.setVerticalSpacing(10)
self.gridLayout_4.setObjectName("gridLayout_4")
self.listFlightTracks = QtWidgets.QListWidget(self.localTab)
self.listFlightTracks.setStyleSheet("border: 1px solid grey;")
self.listFlightTracks.setObjectName("listFlightTracks")
self.gridLayout_4.addWidget(self.listFlightTracks, 1, 0, 1, 2)
self.openFlightTracksLabel = QtWidgets.QLabel(self.localTab)
Expand Down Expand Up @@ -84,7 +83,6 @@ def setupUi(self, MSSMainWindow):
self.workLocallyCheckbox.setObjectName("workLocallyCheckbox")
self.gridLayout_2.addWidget(self.workLocallyCheckbox, 3, 0, 1, 1)
self.listProjectsMSC = QtWidgets.QListWidget(self.shareTab)
self.listProjectsMSC.setStyleSheet("border: 1px solid grey;")
self.listProjectsMSC.setObjectName("listProjectsMSC")
self.gridLayout_2.addWidget(self.listProjectsMSC, 1, 0, 1, 3)
self.projectOptionsCb = QtWidgets.QComboBox(self.shareTab)
Expand All @@ -107,7 +105,6 @@ def setupUi(self, MSSMainWindow):
self.openViewsLabel.setObjectName("openViewsLabel")
self.openViewsVL.addWidget(self.openViewsLabel)
self.listViews = QtWidgets.QListWidget(self.openViewsGb)
self.listViews.setStyleSheet("border: 1px solid grey;")
self.listViews.setObjectName("listViews")
self.openViewsVL.addWidget(self.listViews)
self.verticalLayout.addWidget(self.openViewsGb)
Expand Down
20 changes: 4 additions & 16 deletions mslib/msui/ui/ui_mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="styleSheet">
<string notr="true">::tab-bar { alignment: left; } ::pane{}</string>
<string notr="true">::tab-bar { alignment: left; } ::pane {}</string>
</property>
<property name="currentIndex">
<number>0</number>
Expand Down Expand Up @@ -120,11 +120,7 @@
<number>10</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QListWidget" name="listFlightTracks">
<property name="styleSheet">
<string notr="true">border: 1px solid grey;</string>
</property>
</widget>
<widget class="QListWidget" name="listFlightTracks"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="openFlightTracksLabel">
Expand Down Expand Up @@ -197,11 +193,7 @@
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QListWidget" name="listProjectsMSC">
<property name="styleSheet">
<string notr="true">border: 1px solid grey;</string>
</property>
</widget>
<widget class="QListWidget" name="listProjectsMSC"/>
</item>
<item row="3" column="2">
<widget class="QComboBox" name="projectOptionsCb"/>
Expand Down Expand Up @@ -247,11 +239,7 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="listViews">
<property name="styleSheet">
<string notr="true">border: 1px solid grey;</string>
</property>
</widget>
<widget class="QListWidget" name="listViews"/>
</item>
</layout>
</widget>
Expand Down

0 comments on commit 2354ae9

Please sign in to comment.