Skip to content

Commit

Permalink
Merge branch 'develop' into remove-unnecessary-skips
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss authored Feb 15, 2024
2 parents fb7a4d7 + 167af85 commit 44ad0e1
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 250 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/testing-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ on:


jobs:
test-stable-scheduled:
uses:
./.github/workflows/testing.yml
with:
branch_name: stable
event_name: ${{ github.event_name }}
secrets:
PAT: ${{ secrets.PAT }}
trigger-testing-stable:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: benc-uk/workflow-dispatch@v1.2.2
with:
workflow: testing-stable.yml
ref: stable

test-develop-scheduled:
uses:
Expand Down
29 changes: 13 additions & 16 deletions tests/_test_msui/test_kmloverlay_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def test_get_file(self, mockopen): # Tests opening of QFileDialog
QtWidgets.QApplication.processEvents()
assert mockopen.call_count == 1

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_select_file(self, mockbox):
def test_select_file(self):
"""
Test All geometries and styles are being parsed without crashing
"""
Expand All @@ -100,27 +99,26 @@ def test_select_file(self, mockbox):
assert self.window.listWidget.item(index).checkState() == QtCore.Qt.Checked
index = index + 1
assert self.window.directory_location == path
assert mockbox.critical.call_count == 0
assert self.window.listWidget.count() == index
assert len(self.window.dict_files) == index
assert self.count_patches() == 9
self.window.select_all()
self.window.remove_file()

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_select_file_error(self, mockbox):
def test_select_file_error(self):
"""
Test that program mitigates loading a non-existing file
"""
# load a non existing path
self.window.select_all()
self.window.remove_file()
path = fs.path.join(sample_path, "satellite_predictor.txt")
filename = (path,) # converted to tuple
self.window.select_file(filename)
self.window.load_file()
QtWidgets.QApplication.processEvents()
assert mockbox.critical.call_count == 1
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as critbox:
# load a non existing path
self.window.select_all()
self.window.remove_file()
path = fs.path.join(sample_path, "satellite_predictor.txt")
filename = (path,) # converted to tuple
self.window.select_file(filename)
self.window.load_file()
QtWidgets.QApplication.processEvents()
critbox.assert_called_once()
self.window.listWidget.clear()
self.window.dict_files = {}

Expand Down Expand Up @@ -150,9 +148,8 @@ def test_remove_all_files(self):
assert self.window.dict_files == {} # Dictionary should be empty
assert self.count_patches() == 0

@mock.patch("PyQt5.QtWidgets.QMessageBox")
@mock.patch("mslib.msui.kmloverlay_dockwidget.get_save_filename", return_value=save_kml)
def test_merge_file(self, mocksave, mockbox):
def test_merge_file(self, mocksave):
"""
Test merging files into a single file without crashing
"""
Expand Down
24 changes: 7 additions & 17 deletions tests/_test_msui/test_linearview.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ def setup(self, qapp):
self.window.hide()
QtWidgets.QApplication.processEvents()

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_show(self, mockcrit):
assert mockcrit.critical.call_count == 0
def test_show(self):
pass

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_get(self, mockcrit):
def test_get(self):
self.window.get_settings()
assert mockcrit.critical.call_count == 0


class Test_MSSLinearViewWindow:
Expand All @@ -77,26 +74,21 @@ def setup(self, qapp):
self.window.hide()
QtWidgets.QApplication.processEvents()

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_open_wms(self, mockbox):
def test_open_wms(self):
self.window.cbTools.currentIndexChanged.emit(1)
QtWidgets.QApplication.processEvents()
assert mockbox.critical.call_count == 0

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_mouse_over(self, mockbox):
def test_mouse_over(self):
# Test mouse over
QtTest.QTest.mouseMove(self.window.mpl.canvas, QtCore.QPoint(782, 266), -1)
QtWidgets.QApplication.processEvents()
QtTest.QTest.mouseMove(self.window.mpl.canvas, QtCore.QPoint(100, 100), -1)
QtWidgets.QApplication.processEvents()

@mock.patch("PyQt5.QtWidgets.QMessageBox")
@mock.patch("mslib.msui.linearview.MSUI_LV_Options_Dialog")
def test_options(self, mockdlg, mockbox):
def test_options(self, mockdlg):
QtTest.QTest.mouseClick(self.window.lvoptionbtn, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
assert mockbox.critical.call_count == 0
assert mockdlg.call_count == 1
assert mockdlg.return_value.setModal.call_count == 1
assert mockdlg.return_value.exec_.call_count == 1
Expand Down Expand Up @@ -138,12 +130,10 @@ def query_server(self, url):
QtWidgets.QApplication.processEvents()
wait_until_signal(self.wms_control.cpdlg.canceled)

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_server_getmap(self, mockbox, qtbot):
def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
with qtbot.wait_signal(self.wms_control.image_displayed):
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
assert mockbox.critical.call_count == 0
51 changes: 28 additions & 23 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ def test_activate_operation(self):
assert self.window.mscolab.active_op_id is not None
assert self.window.mscolab.active_operation_name == self.operation_name

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_view_open(self, mockbox):
def test_view_open(self):
self._connect_to_mscolab()
modify_config_file({"MSS_auth": {self.url: self.userdata[0]}})
self._login(emailid=self.userdata[0], password=self.userdata[2])
Expand All @@ -334,10 +333,14 @@ def test_view_open(self, mockbox):
active_windows = self.window.get_active_views()
topview = active_windows[1]
tableview = active_windows[0]
self.window.mscolab.handle_update_permission(operation, uid, "viewer")
with mock.patch("PyQt5.QtWidgets.QMessageBox.information") as m:
self.window.mscolab.handle_update_permission(operation, uid, "viewer")
m.assert_called_once()
assert not tableview.btAddWayPointToFlightTrack.isEnabled()
assert any(action.text() == "Ins WP" and not action.isEnabled() for action in topview.mpl.navbar.actions())
self.window.mscolab.handle_update_permission(operation, uid, "creator")
with mock.patch("PyQt5.QtWidgets.QMessageBox.information") as m:
self.window.mscolab.handle_update_permission(operation, uid, "creator")
m.assert_called_once()
assert tableview.btAddWayPointToFlightTrack.isEnabled()
assert any(action.text() == "Ins WP" and action.isEnabled() for action in topview.mpl.navbar.actions())

Expand All @@ -362,8 +365,7 @@ def test_handle_export(self, mockbox):
("example.csv", "actionImportFlightTrackCSV", 5),
("example.txt", "actionImportFlightTrackTXT", 5),
("flitestar.txt", "actionImportFlightTrackFliteStar", 10)])
@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_import_file(self, mockbox, name):
def test_import_file(self, name):
self.window.remove_plugins()
with mock.patch("mslib.msui.msui_mainwindow.config_loader", return_value=self.import_plugins):
self.window.add_import_plugins("qt")
Expand All @@ -372,13 +374,16 @@ def test_import_file(self, mockbox, name):
# with parametrize it is maybe too fast
QtTest.QTest.qWait(100)
self._connect_to_mscolab()
modify_config_file({"MSS_auth": {self.url: self.userdata[0]}})
self._login(emailid=self.userdata[0], password=self.userdata[2])
self._activate_operation_at_index(0)
wp = self.window.mscolab.waypoints_model
assert len(wp.waypoints) == 2
for action in self.window.menuImportFlightTrack.actions():
if action.objectName() == name[1]:
action.trigger()
with mock.patch("PyQt5.QtWidgets.QMessageBox.information") as m:
action.trigger()
m.assert_called_once()
break
assert mockopen.call_count == 1
imported_wp = self.window.mscolab.waypoints_model
Expand Down Expand Up @@ -567,8 +572,7 @@ def test_update_category(self, mocktext, qtbot):
assert self.window.mscolab.active_op_id is not None
assert self.window.mscolab.active_operation_category == "new_category"

@mock.patch("PyQt5.QtWidgets.QMessageBox.information")
def test_any_special_category(self, mockbox, qtbot):
def test_any_special_category(self, qtbot):
self._connect_to_mscolab()
modify_config_file({"MSS_auth": {self.url: "something@something.org"}})
self._create_user(qtbot, "something", "something@something.org", "something")
Expand Down Expand Up @@ -692,34 +696,35 @@ def test_close_help_dialog(self):
QtWidgets.QApplication.processEvents()
assert self.window.mscolab.help_dialog is None

@mock.patch("PyQt5.QtWidgets.QMessageBox")
@mock.patch("sys.exit")
def test_create_dir_exceptions(self, mockexit, mockbox):
with mock.patch("fs.open_fs", new=ExceptionMock(fs.errors.CreateFailed).raise_exc):
def test_create_dir_exceptions(self):
with mock.patch("fs.open_fs", new=ExceptionMock(fs.errors.CreateFailed).raise_exc), \
mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as critbox, \
mock.patch("sys.exit") as mockexit:
self.window.mscolab.data_dir = "://"
self.window.mscolab.create_dir()
assert mockbox.critical.call_count == 1
assert mockexit.call_count == 1
critbox.assert_called_once()
mockexit.assert_called_once()

with mock.patch("fs.open_fs", new=ExceptionMock(fs.opener.errors.UnsupportedProtocol).raise_exc):
with mock.patch("fs.open_fs", new=ExceptionMock(fs.opener.errors.UnsupportedProtocol).raise_exc), \
mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as critbox, \
mock.patch("sys.exit") as mockexit:
self.window.mscolab.data_dir = "://"
self.window.mscolab.create_dir()
assert mockbox.critical.call_count == 2
assert mockexit.call_count == 2
critbox.assert_called_once()
mockexit.assert_called_once()

@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_profile_dialog(self, mockbox, qtbot):
def test_profile_dialog(self, qtbot):
self._connect_to_mscolab()
modify_config_file({"MSS_auth": {self.url: "something@something.org"}})
self._create_user(qtbot, "something", "something@something.org", "something")
self.window.mscolab.profile_action.trigger()
QtWidgets.QApplication.processEvents()
# case: default gravatar is set and no messagebox is called
assert mockbox.critical.call_count == 0
assert self.window.mscolab.prof_diag is not None
# case: trying to fetch non-existing gravatar
self.window.mscolab.fetch_gravatar(refresh=True)
assert mockbox.critical.call_count == 1
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as critbox:
self.window.mscolab.fetch_gravatar(refresh=True)
critbox.assert_called_once()
assert not self.window.mscolab.profile_dialog.gravatarLabel.pixmap().isNull()

def _connect_to_mscolab(self):
Expand Down
23 changes: 14 additions & 9 deletions tests/_test_msui/test_mscolab_merge_waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
mscolab_delete_all_operations, mscolab_delete_user)
from mslib.msui import mscolab
from mslib.msui import msui
from mslib.utils.config import modify_config_file


class Test_Mscolab_Merge_Waypoints:
Expand Down Expand Up @@ -85,6 +86,7 @@ def _connect_to_mscolab(self):
QtTest.QTest.qWait(500)

def _login(self, emailid="merge_waypoints_user", password="password"):
modify_config_file({"MSS_auth": {self.url: self.emailid}})
self.connect_window.loginEmailLe.setText(emailid)
self.connect_window.loginPasswordLe.setText(password)
QtTest.QTest.mouseClick(self.connect_window.loginBtn, QtCore.Qt.LeftButton)
Expand Down Expand Up @@ -112,8 +114,7 @@ def __init__(self, *args, **kwargs):


class Test_Overwrite_To_Server(Test_Mscolab_Merge_Waypoints):
@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_save_overwrite_to_server(self, mockbox, qtbot):
def test_save_overwrite_to_server(self, qtbot):
self.emailid = "save_overwrite@alpha.org"
self._create_user_data(emailid=self.emailid)
wp_server_before = self.window.mscolab.waypoints_model.waypoint_data(0)
Expand All @@ -135,8 +136,10 @@ def assert_():
# trigger save to server action from server options combobox
with mock.patch(
"mslib.msui.mscolab.MscolabMergeWaypointsDialog",
AutoClickOverwriteMscolabMergeWaypointsDialog):
AutoClickOverwriteMscolabMergeWaypointsDialog), \
mock.patch("PyQt5.QtWidgets.QMessageBox.information") as m:
self.window.serverOptionsCb.setCurrentIndex(2)
m.assert_called_once()

def assert_():
# get the updated waypoints model from the server
Expand All @@ -161,8 +164,7 @@ def __init__(self, *args, **kwargs):


class Test_Save_Keep_Server_Points(Test_Mscolab_Merge_Waypoints):
@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_save_keep_server_points(self, mockbox, qtbot):
def test_save_keep_server_points(self, qtbot):
self.emailid = "save_keepe@alpha.org"
self._create_user_data(emailid=self.emailid)
wp_server_before = self.window.mscolab.waypoints_model.waypoint_data(0)
Expand All @@ -182,8 +184,10 @@ def assert_():
wp_local_before = self.window.mscolab.waypoints_model.waypoint_data(0)

# trigger save to server action from server options combobox
with mock.patch("mslib.msui.mscolab.MscolabMergeWaypointsDialog", AutoClickKeepMscolabMergeWaypointsDialog):
with mock.patch("mslib.msui.mscolab.MscolabMergeWaypointsDialog", AutoClickKeepMscolabMergeWaypointsDialog), \
mock.patch("PyQt5.QtWidgets.QMessageBox.information") as m:
self.window.serverOptionsCb.setCurrentIndex(2)
m.assert_called_once()

def assert_():
# get the updated waypoints model from the server
Expand All @@ -203,8 +207,7 @@ def assert_():


class Test_Fetch_From_Server(Test_Mscolab_Merge_Waypoints):
@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_fetch_from_server(self, mockbox):
def test_fetch_from_server(self):
self.emailid = "fetch_from_server@alpha.org"
self._create_user_data(emailid=self.emailid)
wp_server_before = self.window.mscolab.waypoints_model.waypoint_data(0)
Expand All @@ -218,8 +221,10 @@ def test_fetch_from_server(self, mockbox):
assert wp_server_before.lat != wp_local_before.lat

# trigger save to server action from server options combobox
with mock.patch("mslib.msui.mscolab.MscolabMergeWaypointsDialog", AutoClickKeepMscolabMergeWaypointsDialog):
with mock.patch("mslib.msui.mscolab.MscolabMergeWaypointsDialog", AutoClickKeepMscolabMergeWaypointsDialog), \
mock.patch("PyQt5.QtWidgets.QMessageBox.information") as m:
self.window.serverOptionsCb.setCurrentIndex(1)
m.assert_called_once()
QtWidgets.QApplication.processEvents()
# get the updated waypoints model from the server
# ToDo understand why requesting in follow up test of self.window.waypoints_model not working
Expand Down
4 changes: 1 addition & 3 deletions tests/_test_msui/test_mscolab_save_merge_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import mock
from tests._test_msui.test_mscolab_merge_waypoints import Test_Mscolab_Merge_Waypoints
from mslib.msui import flighttrack as ft
from PyQt5 import QtCore, QtTest, QtWidgets


class Test_Save_Merge_Points(Test_Mscolab_Merge_Waypoints):
@mock.patch("PyQt5.QtWidgets.QMessageBox")
def test_save_merge_points(self, mockbox):
def test_save_merge_points(self):
self.emailid = "mergepoints@alpha.org"
self._create_user_data(emailid=self.emailid)
self.window.workLocallyCheckbox.setChecked(True)
Expand Down
Loading

0 comments on commit 44ad0e1

Please sign in to comment.