tests: Update QMessageBox mockup

When the class is imported with 'from ... import QMessageBox', it needs
to be patched in the importing module, not the original place.
This commit is contained in:
Marek Marczykowski-Górecki 2020-07-30 03:01:47 +02:00
parent bb1995af2e
commit 5fdcf87b59
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -1396,7 +1396,7 @@ class QubeManagerThreadTest(unittest.TestCase):
class VMShutdownMonitorTest(unittest.TestCase): class VMShutdownMonitorTest(unittest.TestCase):
@unittest.mock.patch('PyQt5.QtWidgets.QMessageBox') @unittest.mock.patch('qubesmanager.qube_manager.QMessageBox')
@unittest.mock.patch('PyQt5.QtCore.QTimer') @unittest.mock.patch('PyQt5.QtCore.QTimer')
def test_01_vm_shutdown_correct(self, mock_timer, mock_question): def test_01_vm_shutdown_correct(self, mock_timer, mock_question):
mock_vm = unittest.mock.Mock() mock_vm = unittest.mock.Mock()
@ -1411,7 +1411,7 @@ class VMShutdownMonitorTest(unittest.TestCase):
self.assertEqual(mock_timer.call_count, 0) self.assertEqual(mock_timer.call_count, 0)
monitor.restart_vm_if_needed.assert_called_once_with() monitor.restart_vm_if_needed.assert_called_once_with()
@unittest.mock.patch('PyQt5.QtWidgets.QMessageBox') @unittest.mock.patch('qubesmanager.qube_manager.QMessageBox')
@unittest.mock.patch('PyQt5.QtCore.QTimer.singleShot') @unittest.mock.patch('PyQt5.QtCore.QTimer.singleShot')
def test_02_vm_not_shutdown_wait(self, mock_timer, mock_question): def test_02_vm_not_shutdown_wait(self, mock_timer, mock_question):
mock_question().clickedButton.return_value = 1 mock_question().clickedButton.return_value = 1
@ -1428,7 +1428,7 @@ class VMShutdownMonitorTest(unittest.TestCase):
self.assertEqual(mock_timer.call_count, 1) self.assertEqual(mock_timer.call_count, 1)
@unittest.mock.patch('PyQt5.QtWidgets.QMessageBox') @unittest.mock.patch('qubesmanager.qube_manager.QMessageBox')
@unittest.mock.patch('PyQt5.QtCore.QTimer.singleShot') @unittest.mock.patch('PyQt5.QtCore.QTimer.singleShot')
def test_03_vm_kill(self, mock_timer, mock_question): def test_03_vm_kill(self, mock_timer, mock_question):
mock_question().clickedButton.return_value = 1 mock_question().clickedButton.return_value = 1
@ -1448,7 +1448,7 @@ class VMShutdownMonitorTest(unittest.TestCase):
mock_vm.kill.assert_called_once_with() mock_vm.kill.assert_called_once_with()
monitor.restart_vm_if_needed.assert_called_once_with() monitor.restart_vm_if_needed.assert_called_once_with()
@unittest.mock.patch('PyQt5.QtWidgets.QMessageBox') @unittest.mock.patch('qubesmanager.qube_manager.QMessageBox')
@unittest.mock.patch('PyQt5.QtCore.QTimer.singleShot') @unittest.mock.patch('PyQt5.QtCore.QTimer.singleShot')
def test_04_check_later(self, mock_timer, mock_question): def test_04_check_later(self, mock_timer, mock_question):
mock_vm = unittest.mock.Mock() mock_vm = unittest.mock.Mock()