Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Insoleet committed Feb 6, 2016
1 parent ba72c70 commit d64291f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/sakia/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def refresh(self):
self.refresh_contacts()

def import_account(self):
import_dialog = ImportAccountDialog(self.app, self)
import_dialog = ImportAccountDialog(self.app, self.widget)
import_dialog.exec_()

def import_account_accepted(self, account_name):
Expand All @@ -398,7 +398,7 @@ def import_account_accepted(self, account_name):

def export_account(self):
# Testable way of using a QFileDialog
export_dialog = QFileDialog(self)
export_dialog = QFileDialog(self.widget)
export_dialog.setObjectName('ExportFileDialog')
export_dialog.setWindowTitle(self.tr("Export an account"))
export_dialog.setNameFilter(self.tr("All account files (*.acc)"))
Expand Down
2 changes: 1 addition & 1 deletion src/sakia/gui/process_cfg_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..tools.exceptions import KeyAlreadyUsed, Error, NoPeerAvailable
from ..tools.decorators import asyncify

from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QDialog, QMessageBox
from PyQt5.QtCore import QRegExp
from PyQt5.QtGui import QRegExpValidator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def setUp(self):
self.main_window = MainWindow.startup(self.application)

def tearDown(self):
self.main_window.widget.close()
self.tearDownQuamash()

def test_action_about(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def setUp(self):
self.main_window = MainWindow.startup(self.application)

def tearDown(self):
self.main_window.widget.close()
self.tearDownQuamash()

def test_menubar(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def test_create_account(self):
process_account = ProcessConfigureAccount(self.application,
None)

async def open_dialog(process_account):
result = await process_account.async_exec()
self.assertEqual(result, QDialog.Accepted)

def close_dialog():
if process_account.isVisible():
process_account.close()
Expand All @@ -52,11 +48,11 @@ async def exec_test():
process_account.page_init,
msg="Current widget : {0}".format(process_account.stacked_pages.currentWidget().objectName()))
QTest.mouseClick(process_account.button_next, Qt.LeftButton)
await asyncio.sleep(1)

self.assertEqual(process_account.stacked_pages.currentWidget(),
process_account.page_gpg,
msg="Current widget : {0}".format(process_account.stacked_pages.currentWidget().objectName()))

QTest.keyClicks(process_account.edit_salt, "testsakia")
self.assertFalse(process_account.button_next.isEnabled())
self.assertFalse(process_account.button_generate.isEnabled())
Expand All @@ -74,6 +70,7 @@ async def exec_test():
self.assertEqual(process_account.label_info.text(),
"B7J4sopyfqzi3uh4Gzsdnp1XHc87NaxY7rqW2exgivCa")
QTest.mouseClick(process_account.button_next, Qt.LeftButton)
await asyncio.sleep(1)

self.assertEqual(process_account.stacked_pages.currentWidget(),
process_account.page__communities,
Expand All @@ -83,14 +80,15 @@ async def exec_test():
await asyncio.sleep(1)
QTest.mouseClick(process_account.button_next, Qt.LeftButton)
self.assertEqual(len(self.application.accounts), 1)
await asyncio.sleep(0.1)
self.assertEqual(self.application.current_account.name, "test")
self.assertEqual(self.application.preferences['account'], "test")
self.assertEqual(len(self.application.current_account.wallets), 1)
await asyncio.sleep(0)
await asyncio.sleep(1)

self.lp.call_later(10, close_dialog)
asyncio.ensure_future(exec_test())
self.lp.run_until_complete(open_dialog(process_account))
self.lp.run_until_complete(process_account.async_exec())

if __name__ == '__main__':
logging.basicConfig( stream=sys.stderr )
Expand Down
9 changes: 7 additions & 2 deletions src/sakia/tests/unit/gui/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setUp(self):

def change_current_account(account_name):
type(self.app).current_account = PropertyMock(return_value=self.account_doe)
self.app.get_account = Mock(side_effect=lambda name: self.app.accounts[name])
self.app.change_current_account = Mock(side_effect=change_current_account)
type(self.app).current_account = PropertyMock(return_value=self.account_joe)
self.app.accounts = {'joe':self.account_joe,
Expand All @@ -46,10 +47,12 @@ def test_change_account(self):
label_status = Mock()
label_time = Mock()
combo_referentials = Mock()
mainwindow = MainWindow(self.app, self.homescreen, self.community_view, widget, ui, label_icon,
mainwindow = MainWindow(self.app, self.account_joe, self.homescreen, self.community_view, widget, ui, label_icon,
label_status, label_time, combo_referentials, self.password_asker)
mainwindow.refresh = Mock()
mainwindow.action_change_account("doe")
self.app.change_current_account.assert_called_once_with(self.account_doe)
mainwindow.change_account()

self.community_view.change_account.assert_called_once_with(self.account_doe, self.password_asker)
self.password_asker.change_account.assert_called_once_with(self.account_doe)
Expand All @@ -67,10 +70,12 @@ def test_change_account_from_none(self):
label_time = Mock()
combo_referentials = Mock()
type(self.app).current_account = PropertyMock(return_value=None)
mainwindow = MainWindow(self.app, self.homescreen, self.community_view, widget, ui, label_icon,
mainwindow = MainWindow(self.app, None, self.homescreen, self.community_view, widget, ui, label_icon,
label_status, label_time, combo_referentials, self.password_asker)
mainwindow.refresh = Mock()
mainwindow.action_change_account("doe")
self.app.change_current_account.assert_called_once_with(self.account_doe)
mainwindow.change_account()

self.community_view.change_account.assert_called_once_with(self.account_doe, self.password_asker)
self.password_asker.change_account.assert_called_once_with(self.account_doe)
Expand Down

0 comments on commit d64291f

Please sign in to comment.