From 6b0ce5d1aec1c22a833a6132aa93461375ee3ec0 Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Wed, 26 Feb 2020 16:24:49 +0530 Subject: [PATCH 1/6] Graphical Qt Tests --- src/bitmessageqt/__init__.py | 7 + src/bitmessageqt/settings.py | 27 +-- src/graphicaltesting/__init__.py | 0 .../test_addressgeneration.py | 88 ++++++++++ src/graphicaltesting/test_addsubscription.py | 68 ++++++++ src/graphicaltesting/test_appstart.py | 9 + src/graphicaltesting/test_blackwhitelist.py | 108 ++++++++++++ src/graphicaltesting/test_chans.py | 14 ++ src/graphicaltesting/test_messagesend.py | 74 ++++++++ src/graphicaltesting/test_networkstatus.py | 13 ++ src/graphicaltesting/test_settingwindow.py | 158 ++++++++++++++++++ src/graphicaltesting/testinitialization.py | 30 ++++ src/graphicaltesting/testloader.py | 18 ++ src/gtesting.py | 7 + src/state.py | 2 + 15 files changed, 613 insertions(+), 10 deletions(-) create mode 100644 src/graphicaltesting/__init__.py create mode 100644 src/graphicaltesting/test_addressgeneration.py create mode 100644 src/graphicaltesting/test_addsubscription.py create mode 100644 src/graphicaltesting/test_appstart.py create mode 100644 src/graphicaltesting/test_blackwhitelist.py create mode 100644 src/graphicaltesting/test_chans.py create mode 100644 src/graphicaltesting/test_messagesend.py create mode 100644 src/graphicaltesting/test_networkstatus.py create mode 100644 src/graphicaltesting/test_settingwindow.py create mode 100644 src/graphicaltesting/testinitialization.py create mode 100644 src/graphicaltesting/testloader.py create mode 100644 src/gtesting.py diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 440d36b2..9c964dde 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1617,6 +1617,9 @@ class MyForm(settingsmixin.SMainWindow): def showConnectDialog(self): dialog = dialogs.ConnectDialog(self) + if state.qttesting: + from graphicaltesting import test_appstart + test_appstart.connectme(dialog) if dialog.exec_(): if dialog.radioButtonConnectNow.isChecked(): BMConfigParser().remove_option( @@ -4160,4 +4163,8 @@ def run(): if not BMConfigParser().getboolean('bitmessagesettings', 'startintray'): myapp.show() + if state.qttesting: + from graphicaltesting import testinitialization + testinitialization.test_initialize(myapp) + sys.exit(app.exec_()) diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 011d38ed..f86e29e5 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -499,16 +499,23 @@ class SettingsDialog(QtGui.QDialog): if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: # If the time period is less than 5 hours, we give # zero values to all fields. No message will be sent again. - QtGui.QMessageBox.about( - self, - _translate("MainWindow", "Will not resend ever"), - _translate( - "MainWindow", - "Note that the time limit you entered is less" - " than the amount of time Bitmessage waits for" - " the first resend attempt therefore your" - " messages will never be resent.") - ) + if state.qttesting: + print( + "Note that the time limit you entered is less than the amount" + " of time Bitmessage waits for the first resend attempt therefore" + " your messages will never be resent." + ) + else: + QtGui.QMessageBox.about( + self, + _translate("MainWindow", "Will not resend ever"), + _translate( + "MainWindow", + "Note that the time limit you entered is less" + " than the amount of time Bitmessage waits for" + " the first resend attempt therefore your" + " messages will never be resent.") + ) self.config.set( 'bitmessagesettings', 'stopresendingafterxdays', '0') self.config.set( diff --git a/src/graphicaltesting/__init__.py b/src/graphicaltesting/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/graphicaltesting/test_addressgeneration.py b/src/graphicaltesting/test_addressgeneration.py new file mode 100644 index 00000000..322b9e32 --- /dev/null +++ b/src/graphicaltesting/test_addressgeneration.py @@ -0,0 +1,88 @@ +from random import choice +from string import ascii_lowercase + +from PyQt4.QtTest import QTest + +from bitmessageqt import address_dialogs +from bmconfigparser import BMConfigParser +from testloader import BitmessageTestCase + + +class BitmessageTest_AddressGeneration(BitmessageTestCase): + """Testing Environment""" + + def test_generateaddress(self): + """Method clicks on new label pushbutton and create new address with random label""" + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(500) + try: + random_label = "" + self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") + QTest.qWait(50) + self.myapp.ui.pushButtonNewAddress.setStyleSheet("") + label_gen_obj = address_dialogs.NewAddressDialog() + QTest.qWait(500) + address_count = len(BMConfigParser().addresses()) + QTest.qWait(400) + for _ in range(12): + random_label = random_label + choice(ascii_lowercase) + label_gen_obj.newaddresslabel.setText(random_label) + QTest.qWait(5) + QTest.qWait(500) + label_gen_obj.accept() + QTest.qWait(800) + self.assertEqual(len(BMConfigParser().addresses()), address_count + 1) + self.assertEqual(str(BMConfigParser().get(BMConfigParser().addresses()[-1], "label")), random_label) + print("\n Test Pass :--> Address Generated Successfully \n") + self.assertTrue(True, " \n Test Pass :--> Address Generated Successfully") + return 1 # if every thing is ok + except: + print("\n Test Fail :--> Address Generatation Failed or Taking too much time to generate address \n") + self.assertTrue(False, " \n Test Fail :--> Address Generation Failed!") + return 0 # if test fail + + def test_generateaddresswithpassphrase(self): + """Clicks on the create new label with passphrase pushbutton and generates 8 address""" + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(500) + try: + random_password1, random_password2 = "", "" + self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") + QTest.qWait(50) + self.myapp.ui.pushButtonNewAddress.setStyleSheet("") + label_gen_obj = address_dialogs.NewAddressDialog() + QTest.qWait(500) + address_count = len(BMConfigParser().addresses()) + QTest.qWait(400) + label_gen_obj.radioButtonDeterministicAddress.click() + QTest.qWait(400) + for i in range(15): + random_password1 += choice(ascii_lowercase) + label_gen_obj.lineEditPassphrase.setText(random_password1) + QTest.qWait(5) + QTest.qWait(500) + for i in random_password1: + random_password2 += i + label_gen_obj.lineEditPassphraseAgain.setText(random_password2) + QTest.qWait(5) + QTest.qWait(800) + label_gen_obj.accept() + self.assertEqual(random_password1, random_password2) + print(" Creating Address ......") + QTest.qWait(3000) + print(" Please Wait.! Creating 8 Address ......") + QTest.qWait(3000) + self.assertEqual(len(BMConfigParser().addresses()), address_count + 8) + QTest.qWait(100) + print("\n Test Pass :--> Address Generated Successfully with passphrase \n") + self.assertTrue(True, " \n Test Pass :--> Address Generated Successfully with passphrase") + return 1 + except: + QTest.qWait(100) + print( + "\n Test Fail :--> Address Generatation Failed with passphrase" + " or Taking too much time to generate address \n") + self.assertTrue(False, " \n Test Fail :--> Address Generatation Failed with passphrase") + return 0 diff --git a/src/graphicaltesting/test_addsubscription.py b/src/graphicaltesting/test_addsubscription.py new file mode 100644 index 00000000..1760db94 --- /dev/null +++ b/src/graphicaltesting/test_addsubscription.py @@ -0,0 +1,68 @@ +from random import choice +from string import ascii_lowercase + +from PyQt4 import QtCore, QtGui +from PyQt4.QtTest import QTest + +import shared +from bitmessageqt import dialogs +from bmconfigparser import BMConfigParser +from helper_sql import sqlQuery +from testloader import BitmessageTestCase + + +class BitmessageTest_AddSubscription(BitmessageTestCase): + def test_subscription(self): + """Test for subscription functionality""" + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + QTest.qWait(500) + if BMConfigParser().addresses(): + try: + self.dialog = dialogs.NewSubscriptionDialog(self.myapp) + self.dialog.show() + QTest.qWait(800) + random_label = "" + for _ in range(30): + random_label += choice(ascii_lowercase) + self.dialog.lineEditLabel.setText(random_label) + QTest.qWait(5) + QTest.qWait(500) + rand_address = choice(BMConfigParser().addresses()) + random_address = "" + for x in range(len(rand_address)): + random_address += rand_address[x] + self.dialog.lineEditAddress.setText(random_address) + QTest.qWait(5) + QTest.qWait(500) + QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + try: + QTest.qWait(800) + address, label = self.dialog.data + except AttributeError: + QTest.qWait(500) + print("\n Test Fail :--> Error, While Creating subscription list. \n") + return 0 + if shared.isAddressInMySubscriptionsList(address): + print( + "\n Test Fail :--> You cannot add the same address to your subscriptions twice." + " Perhaps rename the existing one if you want. \n") + QTest.qWait(500) + return 0 + self.myapp.addSubscription(address, label) + sub_add = sqlQuery("select address from subscriptions where label='" + random_label + "'")[0] + self.assertEqual(random_address, sub_add[0]) + print("\n Test Pass :--> Subscription Done Successfully! \n") + QTest.qWait(100) + self.assertTrue(True, " \n Test Pass :--> Subscription Done Successfully!") + return 1 + except: + QTest.qWait(100) + print("\n Test Fail :--> Error Occured while adding address to subscription list! \n") + self.assertTrue(False, " \n Test Fail :--> Error Occured while adding address to subscription list! ") + return 0 + else: + QTest.qWait(100) + print("\n Test Fail :--> No Address Found! \n") + self.assertTrue(False, " \n Test Fail :--> No Address Found!") + return 0 diff --git a/src/graphicaltesting/test_appstart.py b/src/graphicaltesting/test_appstart.py new file mode 100644 index 00000000..bcd023e5 --- /dev/null +++ b/src/graphicaltesting/test_appstart.py @@ -0,0 +1,9 @@ +from PyQt4 import QtCore, QtGui +from PyQt4.QtTest import QTest + + +def connectme(dialog): + """Automate the connect dialog, when run for first time""" + dialog.show() + QTest.qWait(1200) + QtCore.QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) diff --git a/src/graphicaltesting/test_blackwhitelist.py b/src/graphicaltesting/test_blackwhitelist.py new file mode 100644 index 00000000..2750a36f --- /dev/null +++ b/src/graphicaltesting/test_blackwhitelist.py @@ -0,0 +1,108 @@ +from random import choice +from string import ascii_lowercase + +from PyQt4 import QtCore, QtGui +from PyQt4.QtTest import QTest + +from addresses import addBMIfNotPresent +from bitmessageqt import blacklist +from bitmessageqt.dialogs import AddAddressDialog +from bitmessageqt.utils import avatarize +from bmconfigparser import BMConfigParser +from helper_sql import sqlExecute, sqlQuery +from testloader import BitmessageTestCase +from tr import _translate + + +class BitmessageTest_BlackandWhiteList(BitmessageTestCase): + """Blacklist and Whitelist address add functionality tests""" + + def test_blackwhitelist(self): + """Tab switch to blacklist and add the address on blacklist and whitelist""" + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + QTest.qWait(500) + try: + self.blacklist_obj = blacklist.Blacklist() + self.dialog = AddAddressDialog(self.myapp) + blacklistcount = len(sqlQuery("Select * from blacklist")) + self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() + self.checkblacklist(self.myapp) + QTest.qWait(500) + self.assertEqual(blacklistcount + 1, len(sqlQuery("Select * from blacklist"))) + whitelistcount = len(sqlQuery("Select * from whitelist")) + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() + self.checkblacklist(self.myapp) + QTest.qWait(500) + self.assertEqual(whitelistcount + 1, len(sqlQuery("Select * from whitelist"))) + except: + pass + + def checkblacklist(self, myapp): + # pylint: disable=too-many-statements + QTest.qWait(1000) + self.dialog.lineEditLabel.setText("") + self.dialog.lineEditAddress.setText("") + self.dialog.show() + QTest.qWait(800) + random_label = "" + for _ in range(30): + random_label += choice(ascii_lowercase) + self.dialog.lineEditLabel.setText(random_label) + QTest.qWait(5) + QTest.qWait(500) + rand_address = choice(BMConfigParser().addresses()) + random_address = "" + for x in range(len(rand_address)): + random_address += rand_address[x] + self.dialog.lineEditAddress.setText(random_address) + QTest.qWait(5) + QTest.qWait(500) + QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + if self.dialog.labelAddressCheck.text() == _translate("MainWindow", "Address is valid."): + address = addBMIfNotPresent(str(self.dialog.lineEditAddress.text())) + t = (address,) + if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": + sql = """select * from blacklist where address=?""" + else: + sql = """select * from whitelist where address=?""" + queryreturn = sqlQuery(sql, *t) + if queryreturn == []: + self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(False) + self.blacklist_obj.tableWidgetBlacklist.insertRow(0) + newItem = QtGui.QTableWidgetItem(unicode(self.dialog.lineEditLabel.text().toUtf8(), "utf-8")) + newItem.setIcon(avatarize(address)) + self.blacklist_obj.tableWidgetBlacklist.setItem(0, 0, newItem) + newItem = QtGui.QTableWidgetItem(address) + newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + self.blacklist_obj.tableWidgetBlacklist.setItem(0, 1, newItem) + self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(True) + t = (str(self.dialog.lineEditLabel.text().toUtf8()), address, True) + if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": + sql = """INSERT INTO blacklist VALUES (?,?,?)""" + sqlExecute(sql, *t) + black_list_value = sqlQuery("Select address from blacklist where label='" + random_label + "'")[0] + print("\n Test Pass :--> Address Added to the blacklist! \n") + self.assertEqual(black_list_value[0], random_address) + return + else: + sql = """INSERT INTO whitelist VALUES (?,?,?)""" + sqlExecute(sql, *t) + white_list_value = sqlQuery("Select address from whitelist where label='" + random_label + "'")[0] + print("\n Test Pass :--> Address Added to the whitelist! \n") + self.assertEqual(white_list_value[0], random_address) + return + else: + QTest.qWait(100) + print( + "\n Test Fail :--> You cannot add the same address to your list twice." + " Perhaps rename the existing one if you want. \n") + self.assertTrue( + False, "\n Test Fail :--> You cannot add the same address to your list twice." + " Perhaps rename the existing one if you want.") + return 0 + else: + QTest.qWait(100) + print("\n Test Fail :--> The address you entered was invalid. Ignoring it. \n") + self.assertTrue(False, " \n Test Fail :--> The address you entered was invalid. Ignoring it.") + return 0 diff --git a/src/graphicaltesting/test_chans.py b/src/graphicaltesting/test_chans.py new file mode 100644 index 00000000..6ccbe346 --- /dev/null +++ b/src/graphicaltesting/test_chans.py @@ -0,0 +1,14 @@ +from PyQt4.QtTest import QTest + +from testloader import BitmessageTestCase + + +class BitmessageTest_ChansTest(BitmessageTestCase): + def test_chans(self): + """Switch to chans window and test""" + QTest.qWait(1200) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.chans) + # QTest.mouseClick(self.myapp.ui.pushButtonAddChan, Qt.LeftButton) + # self.assertEqual('foo'.upper(), 'F00') + print("\n Test Pass :--> Chans Test Passed! \n") + return 1 diff --git a/src/graphicaltesting/test_messagesend.py b/src/graphicaltesting/test_messagesend.py new file mode 100644 index 00000000..f5471dc8 --- /dev/null +++ b/src/graphicaltesting/test_messagesend.py @@ -0,0 +1,74 @@ +import random +from random import choice +from string import ascii_lowercase + +from PyQt4.QtCore import Qt +from PyQt4.QtTest import QTest + +from bmconfigparser import BMConfigParser +from helper_sql import sqlQuery +from testloader import BitmessageTestCase + + +class BitmessageTest_MessageTesting(BitmessageTestCase): + """Test Message Sending functionality""" + + def test_msgsend(self): + """Auto-fill senders address, receivers address, subject and message and sends the message""" + try: + if BMConfigParser().addresses(): + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + QTest.qWait(800) + self.myapp.ui.comboBoxSendFrom.setCurrentIndex( + random.randrange(1, len(BMConfigParser().addresses()) + 1) + ) + QTest.qWait(800) + rand_address = choice(BMConfigParser().addresses()) + random_address = "" + for x in range(len(rand_address)): + random_address += rand_address[x] + self.myapp.ui.lineEditTo.setText(random_address) + QTest.qWait(1) + QTest.qWait(800) + random_subject = "" + for x in range(40): + random_subject += choice(ascii_lowercase) + self.myapp.ui.lineEditSubject.setText(random_subject) + QTest.qWait(1) + QTest.qWait(800) + random_message = "" + for x in range(200): + random_message += choice(ascii_lowercase) + self.myapp.ui.textEditMessage.setText(random_message) + QTest.qWait(1) + QTest.qWait(800) + inbox_length = len(sqlQuery("Select msgid from inbox")) + QTest.mouseClick(self.myapp.ui.pushButtonSend, Qt.LeftButton) + QTest.qWait(600) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + print(" .......................... waiting for message .......................... ") + for x in range(5): + QTest.qWait(5000) + print(" waiting " + x * ".") + self.assertEqual(sqlQuery("Select toaddress,subject from inbox")[-1], (rand_address, random_subject)) + if len(sqlQuery("Select msgid from inbox")) == inbox_length + 1: + QTest.qWait(100) + print("\n Test Pass :--> Message Received Successfully \n") + self.assertTrue(True, " Test Pass :--> Message Received Successfully") + return 1 + else: + QTest.qWait(100) + print("\n Test Fail :--> Doesn't Receive Any Message!! \n") + self.assertTrue(False, " \n Test Fail :--> Doesn't Receive Any Message!!") + return 0 + else: + QTest.qWait(100) + print("\n Test Fail :--> No Address Found!! \n") + self.assertTrue(False, " \n Test Fail :--> No Address Found!!") + return 0 + except: + QTest.qWait(100) + print("\n Test Fail :--> Message Sending Test Fail!! \n") + self.assertTrue(False, " \n Test Fail :--> Message Sending Test Fail!!") + return 0 diff --git a/src/graphicaltesting/test_networkstatus.py b/src/graphicaltesting/test_networkstatus.py new file mode 100644 index 00000000..fe15f578 --- /dev/null +++ b/src/graphicaltesting/test_networkstatus.py @@ -0,0 +1,13 @@ +from PyQt4.QtTest import QTest + +from testloader import BitmessageTestCase + + +class BitmessageTest_NetworkTest(BitmessageTestCase): + def test_network(self): + """Switch to network window and test""" + QTest.qWait(1000) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus) + QTest.qWait(1200) + print("\n Test Pass :--> Network Functionality Working Well! \n") + return 1 diff --git a/src/graphicaltesting/test_settingwindow.py b/src/graphicaltesting/test_settingwindow.py new file mode 100644 index 00000000..4b8c0974 --- /dev/null +++ b/src/graphicaltesting/test_settingwindow.py @@ -0,0 +1,158 @@ +import random +from random import choice +from string import ascii_lowercase + +from PyQt4 import QtGui +from PyQt4.QtCore import Qt +from PyQt4.QtTest import QTest + +from bitmessageqt import dialogs +from testloader import BitmessageTestCase + + +class BitmessageTest_SettingWindowTest(BitmessageTestCase): + def test_settingwindow(self): + """Triggers the setting window""" + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(1700) + dialog = dialogs.SettingsDialog(self.myapp, firstrun=self.myapp._firstrun) + self.language_change(dialog) + QTest.qWait(300) + self.eng_convert(dialog) + QTest.qWait(300) + self.network_setting_window(dialog) + QTest.qWait(300) + self.tabresendsexpire_window(dialog) + QTest.qWait(300) + + def language_change(self, dialog): + """Function that changes the language of the application""" + try: + """Change language""" + dialog.show() + dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) + QTest.qWait(800) + dialog.languageComboBox.setStyleSheet("QComboBox {background-color: #FF5733; color: white;}") + QTest.qWait(50) + dialog.languageComboBox.setStyleSheet("") + dialog.languageComboBox.setCurrentIndex(random.randint(1, 17)) + QTest.qWait(1000) + ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) + QTest.mouseClick(ok_btn, Qt.LeftButton) + print("\n Test Pass :--> Language Changed Successfully \n") + self.assertTrue(True, " \n Test Pass :--> Language Changed Successfully ") + return 1 + except: + print("\n Test Fail :--> Error while changing Language! \n") + self.assertTrue(False, " \n Test Fail :--> Error while changing Language!") + return 0 + + def eng_convert(self, dialog): + """Convert any language to english, testing just for good readability""" + try: + dialog.show() + dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) + QTest.qWait(800) + dialog.languageComboBox.setStyleSheet("QComboBox {background-color: #FF5733; color: white;}") + QTest.qWait(50) + dialog.languageComboBox.setStyleSheet("") + dialog.languageComboBox.setCurrentIndex(6) + QTest.qWait(1000) + ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) + QTest.mouseClick(ok_btn, Qt.LeftButton) + print("\n Test Pass :--> language changed to English Again \n") + self.assertTrue(True, " \n Test Pass :--> language changed to English Again ") + return 1 + except: + print("\n Test Fail :--> Not able to change the language to English Again! Error! \n") + self.assertTrue(False, " \n Test Fail :--> Not able to change the language to English Again! Error!") + return 0 + + def network_setting_window(self, dialog): + """Test for Network setting window""" + try: + dialog.show() + QTest.qWait(300) + dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabNetworkSettings)) + QTest.qWait(500) + + dialog.lineEditSocksHostname.setText("") + dialog.lineEditSocksPort.setText("") + dialog.lineEditSocksUsername.setText("") + dialog.lineEditSocksPassword.setText("") + if dialog.checkBoxAuthentication.isChecked(): + dialog.checkBoxAuthentication.click() + if dialog.checkBoxSocksListen.isChecked(): + dialog.checkBoxSocksListen.click() + if dialog.checkBoxOnionOnly.isChecked(): + dialog.checkBoxOnionOnly.click() + + QTest.qWait(500) + dialog.comboBoxProxyType.setCurrentIndex(random.randint(1, 3)) + QTest.qWait(800) + + random_val = "" + for _ in range(10): + random_val += choice(ascii_lowercase) + dialog.lineEditSocksHostname.setText(random_val) + QTest.qWait(5) + QTest.qWait(500) + dialog.lineEditSocksPort.setText(str(random.randint(1000, 9999))) + QTest.qWait(800) + + if dialog.checkBoxAuthentication.isChecked(): + pass + else: + dialog.checkBoxAuthentication.click() + QTest.qWait(500) + + dialog.lineEditSocksUsername.setText("".join(choice(ascii_lowercase) for i in range(10))) + QTest.qWait(500) + dialog.lineEditSocksPassword.setText("".join(choice(ascii_lowercase) for i in range(10))) + QTest.qWait(500) + + if dialog.checkBoxSocksListen.isChecked(): + pass + else: + dialog.checkBoxSocksListen.click() + QTest.qWait(1200) + + if dialog.checkBoxOnionOnly.isChecked(): + pass + else: + dialog.checkBoxOnionOnly.click() + QTest.qWait(1200) + ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) + QTest.mouseClick(ok_btn, Qt.LeftButton) + print("\n Test Pass :--> Successfully tested Network setting window \n") + self.assertTrue(True, " \n Test Pass :--> Successfully tested Network setting window ") + return 1 + except: + print("\n Test Fail :--> Error while testing Network setting window! \n") + self.assertTrue(False, " \n Test Fail :--> Error while testing Network setting window!") + return 0 + + def tabresendsexpire_window(self, dialog): + """Testing for resend expire window""" + try: + dialog.lineEditDays.setText("") + dialog.lineEditMonths.setText("") + dialog.show() + QTest.qWait(300) + dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabResendsExpire)) + QTest.qWait(500) + + QTest.qWait(500) + dialog.lineEditDays.setText(str(random.randint(0, 30))) + QTest.qWait(800) + dialog.lineEditMonths.setText(str(random.randint(0, 12))) + QTest.qWait(800) + ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) + QTest.mouseClick(ok_btn, Qt.LeftButton) + print("\n Test Pass :--> Test successfull. \n") + self.assertTrue(True, " \n Test Pass :--> Test successfull. ") + return 1 + except: + print("\n Test Fail :--> Tab Resend Exprire! \n") + self.assertTrue(False, " \n Test Fail :--> Tab Resend Exprire! ") + return 0 diff --git a/src/graphicaltesting/testinitialization.py b/src/graphicaltesting/testinitialization.py new file mode 100644 index 00000000..0e1f3523 --- /dev/null +++ b/src/graphicaltesting/testinitialization.py @@ -0,0 +1,30 @@ +import unittest + +import test_addressgeneration +import test_addsubscription +import test_blackwhitelist +import test_chans +import test_messagesend +import test_networkstatus +import test_settingwindow +from testloader import BitmessageTestCase + + +def test_initialize(myapp): + """Test Loader""" + suite = unittest.TestSuite() + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_messagesend.BitmessageTest_MessageTesting, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_chans.BitmessageTest_ChansTest, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader( + test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp)) + unittest.TextTestRunner().run(suite) diff --git a/src/graphicaltesting/testloader.py b/src/graphicaltesting/testloader.py new file mode 100644 index 00000000..6a9b4f09 --- /dev/null +++ b/src/graphicaltesting/testloader.py @@ -0,0 +1,18 @@ +import unittest + + +class BitmessageTestCase(unittest.TestCase): + """Unit Test Integration""" + + def __init__(self, methodName="runTest", myapp=None): + super(BitmessageTestCase, self).__init__(methodName) + self.myapp = myapp + + @staticmethod + def bitmessage_testloader(testcaseclass, myapp=None): + """Test Loader""" + testnames = unittest.TestLoader().getTestCaseNames(testcaseclass) + suite = unittest.TestSuite() + for name in testnames: + suite.addTest(testcaseclass(name, myapp)) + return suite diff --git a/src/gtesting.py b/src/gtesting.py new file mode 100644 index 00000000..db4b2c11 --- /dev/null +++ b/src/gtesting.py @@ -0,0 +1,7 @@ +import state + +if __name__ == "__main__": + state.qttesting = True + print(" --------------------------------- Graphical Qt Testing --------------------------------- ") + from bitmessagemain import main + main() diff --git a/src/state.py b/src/state.py index 58e1106a..6fb18d72 100644 --- a/src/state.py +++ b/src/state.py @@ -55,3 +55,5 @@ testmode = False kivy = False association = '' + +qttesting = False -- 2.45.1 From ea2e11ced83ce77129520bb4e0955476a107435a Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Thu, 27 Feb 2020 20:16:43 +0530 Subject: [PATCH 2/6] Add quit function and code fixes --- .../test_addressgeneration.py | 4 +- src/graphicaltesting/test_addsubscription.py | 6 +- src/graphicaltesting/test_appstart.py | 1 + src/graphicaltesting/test_blackwhitelist.py | 11 +- src/graphicaltesting/test_chans.py | 3 + src/graphicaltesting/test_messagesend.py | 3 +- src/graphicaltesting/test_networkstatus.py | 5 +- src/graphicaltesting/test_quit.py | 101 ++++++++++++++++++ src/graphicaltesting/test_settingwindow.py | 5 +- src/graphicaltesting/testinitialization.py | 34 +++--- src/graphicaltesting/testloader.py | 1 + src/gtesting.py | 9 +- 12 files changed, 160 insertions(+), 23 deletions(-) create mode 100644 src/graphicaltesting/test_quit.py diff --git a/src/graphicaltesting/test_addressgeneration.py b/src/graphicaltesting/test_addressgeneration.py index 322b9e32..720eafc4 100644 --- a/src/graphicaltesting/test_addressgeneration.py +++ b/src/graphicaltesting/test_addressgeneration.py @@ -1,3 +1,4 @@ +"""Generate Address for tests""" from random import choice from string import ascii_lowercase @@ -83,6 +84,7 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): QTest.qWait(100) print( "\n Test Fail :--> Address Generatation Failed with passphrase" - " or Taking too much time to generate address \n") + " or Taking too much time to generate address \n" + ) self.assertTrue(False, " \n Test Fail :--> Address Generatation Failed with passphrase") return 0 diff --git a/src/graphicaltesting/test_addsubscription.py b/src/graphicaltesting/test_addsubscription.py index 1760db94..0901818b 100644 --- a/src/graphicaltesting/test_addsubscription.py +++ b/src/graphicaltesting/test_addsubscription.py @@ -1,3 +1,4 @@ +"""Add address in the subscription list""" from random import choice from string import ascii_lowercase @@ -12,6 +13,8 @@ from testloader import BitmessageTestCase class BitmessageTest_AddSubscription(BitmessageTestCase): + """Add address to list""" + def test_subscription(self): """Test for subscription functionality""" QTest.qWait(500) @@ -46,7 +49,8 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): if shared.isAddressInMySubscriptionsList(address): print( "\n Test Fail :--> You cannot add the same address to your subscriptions twice." - " Perhaps rename the existing one if you want. \n") + " Perhaps rename the existing one if you want. \n" + ) QTest.qWait(500) return 0 self.myapp.addSubscription(address, label) diff --git a/src/graphicaltesting/test_appstart.py b/src/graphicaltesting/test_appstart.py index bcd023e5..fbb5f742 100644 --- a/src/graphicaltesting/test_appstart.py +++ b/src/graphicaltesting/test_appstart.py @@ -1,3 +1,4 @@ +"""Trigger dialog""" from PyQt4 import QtCore, QtGui from PyQt4.QtTest import QTest diff --git a/src/graphicaltesting/test_blackwhitelist.py b/src/graphicaltesting/test_blackwhitelist.py index 2750a36f..d08881be 100644 --- a/src/graphicaltesting/test_blackwhitelist.py +++ b/src/graphicaltesting/test_blackwhitelist.py @@ -1,3 +1,4 @@ +"""Tests for blackwhitelist""" from random import choice from string import ascii_lowercase @@ -39,6 +40,7 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): pass def checkblacklist(self, myapp): + """fill blacklist and whitelist fields""" # pylint: disable=too-many-statements QTest.qWait(1000) self.dialog.lineEditLabel.setText("") @@ -96,10 +98,13 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): QTest.qWait(100) print( "\n Test Fail :--> You cannot add the same address to your list twice." - " Perhaps rename the existing one if you want. \n") + " Perhaps rename the existing one if you want. \n" + ) self.assertTrue( - False, "\n Test Fail :--> You cannot add the same address to your list twice." - " Perhaps rename the existing one if you want.") + False, + "\n Test Fail :--> You cannot add the same address to your list twice." + " Perhaps rename the existing one if you want.", + ) return 0 else: QTest.qWait(100) diff --git a/src/graphicaltesting/test_chans.py b/src/graphicaltesting/test_chans.py index 6ccbe346..959dc530 100644 --- a/src/graphicaltesting/test_chans.py +++ b/src/graphicaltesting/test_chans.py @@ -1,9 +1,12 @@ +"""Tests for changs Tab""" from PyQt4.QtTest import QTest from testloader import BitmessageTestCase class BitmessageTest_ChansTest(BitmessageTestCase): + """Switch to chans and test""" + def test_chans(self): """Switch to chans window and test""" QTest.qWait(1200) diff --git a/src/graphicaltesting/test_messagesend.py b/src/graphicaltesting/test_messagesend.py index f5471dc8..b9a0b6d7 100644 --- a/src/graphicaltesting/test_messagesend.py +++ b/src/graphicaltesting/test_messagesend.py @@ -1,3 +1,4 @@ +"""Test for message send""" import random from random import choice from string import ascii_lowercase @@ -23,7 +24,7 @@ class BitmessageTest_MessageTesting(BitmessageTestCase): self.myapp.ui.comboBoxSendFrom.setCurrentIndex( random.randrange(1, len(BMConfigParser().addresses()) + 1) ) - QTest.qWait(800) + QTest.qWait(1000) rand_address = choice(BMConfigParser().addresses()) random_address = "" for x in range(len(rand_address)): diff --git a/src/graphicaltesting/test_networkstatus.py b/src/graphicaltesting/test_networkstatus.py index fe15f578..d3dbb35a 100644 --- a/src/graphicaltesting/test_networkstatus.py +++ b/src/graphicaltesting/test_networkstatus.py @@ -1,11 +1,14 @@ +"""Test for network window""" from PyQt4.QtTest import QTest from testloader import BitmessageTestCase class BitmessageTest_NetworkTest(BitmessageTestCase): + """Switch to network tab and test""" + def test_network(self): - """Switch to network window and test""" + """Switch to network window""" QTest.qWait(1000) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus) QTest.qWait(1200) diff --git a/src/graphicaltesting/test_quit.py b/src/graphicaltesting/test_quit.py new file mode 100644 index 00000000..329149e8 --- /dev/null +++ b/src/graphicaltesting/test_quit.py @@ -0,0 +1,101 @@ +"""Quits the application""" +import time + +from PyQt4 import QtCore, QtGui + +import bitmessageqt.sound +import shared +import shutdown +from bitmessageqt import settingsmixin +from bmconfigparser import BMConfigParser +from debug import logger +from network.stats import pendingDownload, pendingUpload +from proofofwork import getPowType +from testloader import BitmessageTestCase +from tr import _translate + + +class BitmessageTest_QuitTest(BitmessageTestCase): + """Quit the bitmessage qt application""" + + def test_quitapplication(self): + """wait for pow and shutdown the application""" + if self.myapp.quitAccepted and not self.myapp.wait: + return + + self.myapp.show() + self.myapp.raise_() + self.myapp.activateWindow() + + waitForPow = True + waitForConnection = False + waitForSync = False + if getPowType() == "python" and (bitmessageqt.powQueueSize() > 0 or pendingUpload() > 0): + waitForPow = False + if pendingDownload() > 0: + self.myapp.wait = waitForSync = True + if shared.statusIconColor == "red" and not BMConfigParser().safeGetBoolean( + "bitmessagesettings", "dontconnect" + ): + waitForConnection = True + self.myapp.wait = waitForSync = True + self.myapp.quitAccepted = True + self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down PyBitmessage... %1%").arg(0)) + if waitForConnection: + self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for network connection...")) + while shared.statusIconColor == "red": + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + if waitForSync: + self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for finishing synchronisation...")) + while pendingDownload() > 0: + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + if waitForPow: + maxWorkerQueue = 0 + curWorkerQueue = bitmessageqt.powQueueSize() + while curWorkerQueue > 0: + curWorkerQueue = bitmessageqt.powQueueSize() + if curWorkerQueue > maxWorkerQueue: + maxWorkerQueue = curWorkerQueue + if curWorkerQueue > 0: + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for PoW to finish... %1%").arg( + 50 * (maxWorkerQueue - curWorkerQueue) / maxWorkerQueue + ) + ) + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down Pybitmessage... %1%").arg(50)) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + if maxWorkerQueue > 0: + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for objects to be sent... %1%").arg(50)) + maxPendingUpload = max(1, pendingUpload()) + while pendingUpload() > 1: + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for objects to be sent... %1%").arg( + int(50 + 20 * (pendingUpload() / maxPendingUpload)) + ) + ) + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.updateStatusBar(_translate("MainWindow", "Saving settings... %1%").arg(70)) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.saveSettings() + for attr, obj in self.myapp.ui.__dict__.iteritems(): + if hasattr(obj, "__class__") and isinstance(obj, settingsmixin.SettingsMixin): + saveMethod = getattr(obj, "saveSettings", None) + if callable(saveMethod): + obj.saveSettings() + self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down core... %1%").arg(80)) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + shutdown.doCleanShutdown() + self.myapp.updateStatusBar(_translate("MainWindow", "Stopping notifications... %1%").arg(90)) + self.myapp.tray.hide() + self.myapp.updateStatusBar(_translate("MainWindow", "Shutdown imminent... %1%").arg(100)) + logger.info("Shutdown complete") + QtGui.qApp.closeAllWindows() diff --git a/src/graphicaltesting/test_settingwindow.py b/src/graphicaltesting/test_settingwindow.py index 4b8c0974..cd2ed89a 100644 --- a/src/graphicaltesting/test_settingwindow.py +++ b/src/graphicaltesting/test_settingwindow.py @@ -1,3 +1,4 @@ +"""Tests for setting window""" import random from random import choice from string import ascii_lowercase @@ -11,6 +12,8 @@ from testloader import BitmessageTestCase class BitmessageTest_SettingWindowTest(BitmessageTestCase): + """Switch to setting tab and test""" + def test_settingwindow(self): """Triggers the setting window""" self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) @@ -56,7 +59,7 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): dialog.languageComboBox.setStyleSheet("QComboBox {background-color: #FF5733; color: white;}") QTest.qWait(50) dialog.languageComboBox.setStyleSheet("") - dialog.languageComboBox.setCurrentIndex(6) + dialog.languageComboBox.setCurrentIndex(5) QTest.qWait(1000) ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) QTest.mouseClick(ok_btn, Qt.LeftButton) diff --git a/src/graphicaltesting/testinitialization.py b/src/graphicaltesting/testinitialization.py index 0e1f3523..02cef716 100644 --- a/src/graphicaltesting/testinitialization.py +++ b/src/graphicaltesting/testinitialization.py @@ -1,3 +1,4 @@ +"""Trigger Test""" import unittest import test_addressgeneration @@ -7,24 +8,29 @@ import test_chans import test_messagesend import test_networkstatus import test_settingwindow +import test_quit from testloader import BitmessageTestCase def test_initialize(myapp): """Test Loader""" suite = unittest.TestSuite() - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_messagesend.BitmessageTest_MessageTesting, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_chans.BitmessageTest_ChansTest, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader( - test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp)) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp) + ) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp) + ) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp) + ) + suite.addTest(BitmessageTestCase.bitmessage_testloader(test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp)) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp) + ) + suite.addTest(BitmessageTestCase.bitmessage_testloader(test_chans.BitmessageTest_ChansTest, myapp=myapp)) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp) + ) + suite.addTest(BitmessageTestCase.bitmessage_testloader(test_quit.BitmessageTest_QuitTest, myapp=myapp)) unittest.TextTestRunner().run(suite) diff --git a/src/graphicaltesting/testloader.py b/src/graphicaltesting/testloader.py index 6a9b4f09..8d21dd6b 100644 --- a/src/graphicaltesting/testloader.py +++ b/src/graphicaltesting/testloader.py @@ -1,3 +1,4 @@ +"""Load Test""" import unittest diff --git a/src/gtesting.py b/src/gtesting.py index db4b2c11..56099b97 100644 --- a/src/gtesting.py +++ b/src/gtesting.py @@ -1,6 +1,13 @@ -import state +import os +import shutil if __name__ == "__main__": + APPNAME = "PyBitmessage" + if os.path.isdir(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))): + shutil.rmtree(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))) + else: + pass + import state state.qttesting = True print(" --------------------------------- Graphical Qt Testing --------------------------------- ") from bitmessagemain import main -- 2.45.1 From 380de9d1d9d43088c8101bdf1cbdde9ccc6663ca Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Wed, 4 Mar 2020 14:58:48 +0530 Subject: [PATCH 3/6] Inbox PopMenu functionality --- src/bitmessageqt/__init__.py | 30 ++-- .../test_addressgeneration.py | 50 ++++--- src/graphicaltesting/test_addsubscription.py | 29 ++-- src/graphicaltesting/test_blackwhitelist.py | 12 +- src/graphicaltesting/test_chans.py | 2 - src/graphicaltesting/test_inbox_popmenu.py | 134 ++++++++++++++++++ src/graphicaltesting/test_messagesend.py | 10 +- src/graphicaltesting/test_networkstatus.py | 13 +- src/graphicaltesting/test_settingwindow.py | 2 +- src/graphicaltesting/testinitialization.py | 21 ++- src/graphicaltesting/testloader.py | 2 +- 11 files changed, 236 insertions(+), 69 deletions(-) create mode 100644 src/graphicaltesting/test_inbox_popmenu.py diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 9c964dde..33291ece 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2514,15 +2514,19 @@ class MyForm(settingsmixin.SMainWindow): self.ui.textEditMessage.setFocus() def on_action_MarkAllRead(self): - if QtGui.QMessageBox.question( - self, "Marking all messages as read?", - _translate( - "MainWindow", - "Are you sure you would like to mark all messages read?" - ), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No - ) != QtGui.QMessageBox.Yes: - return - tableWidget = self.getCurrentMessagelist() + import state + if state.qttesting: + tableWidget = self.getCurrentMessagelist() + else: + if QtGui.QMessageBox.question( + self, "Marking all messages as read?", + _translate( + "MainWindow", + "Are you sure you would like to mark all messages read?" + ), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No + ) != QtGui.QMessageBox.Yes: + return + tableWidget = self.getCurrentMessagelist() idCount = tableWidget.rowCount() if idCount == 0: @@ -3778,8 +3782,12 @@ class MyForm(settingsmixin.SMainWindow): self.popMenuYourIdentities.addAction(self.actionMarkAllRead) if self.popMenuYourIdentities.isEmpty(): return - self.popMenuYourIdentities.exec_( - self.ui.treeWidgetYourIdentities.mapToGlobal(point)) + if state.qttesting: + self.popMenuYourIdentities.move(point.x(), point.y()) + self.popMenuYourIdentities.show() + else: + self.popMenuYourIdentities.exec_( + self.ui.treeWidgetYourIdentities.mapToGlobal(point)) # TODO make one popMenu def on_context_menuChan(self, point): diff --git a/src/graphicaltesting/test_addressgeneration.py b/src/graphicaltesting/test_addressgeneration.py index 720eafc4..849217f2 100644 --- a/src/graphicaltesting/test_addressgeneration.py +++ b/src/graphicaltesting/test_addressgeneration.py @@ -14,25 +14,29 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): def test_generateaddress(self): """Method clicks on new label pushbutton and create new address with random label""" - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) - QTest.qWait(500) try: - random_label = "" + address_count = len(BMConfigParser().addresses()) + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(500) + self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonNewAddress.setStyleSheet("") + label_gen_obj = address_dialogs.NewAddressDialog() - QTest.qWait(500) - address_count = len(BMConfigParser().addresses()) - QTest.qWait(400) + QTest.qWait(1000) + + random_label = "" for _ in range(12): - random_label = random_label + choice(ascii_lowercase) + random_label += choice(ascii_lowercase) label_gen_obj.newaddresslabel.setText(random_label) - QTest.qWait(5) - QTest.qWait(500) + QTest.qWait(2) + + QTest.qWait(600) label_gen_obj.accept() QTest.qWait(800) + self.assertEqual(len(BMConfigParser().addresses()), address_count + 1) self.assertEqual(str(BMConfigParser().get(BMConfigParser().addresses()[-1], "label")), random_label) print("\n Test Pass :--> Address Generated Successfully \n") @@ -45,36 +49,40 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): def test_generateaddresswithpassphrase(self): """Clicks on the create new label with passphrase pushbutton and generates 8 address""" - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) - QTest.qWait(500) try: - random_password1, random_password2 = "", "" + address_count = len(BMConfigParser().addresses()) + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(500) + self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonNewAddress.setStyleSheet("") + label_gen_obj = address_dialogs.NewAddressDialog() QTest.qWait(500) - address_count = len(BMConfigParser().addresses()) - QTest.qWait(400) label_gen_obj.radioButtonDeterministicAddress.click() QTest.qWait(400) + + random_password1, random_password2 = "", "" for i in range(15): random_password1 += choice(ascii_lowercase) label_gen_obj.lineEditPassphrase.setText(random_password1) - QTest.qWait(5) + QTest.qWait(2) QTest.qWait(500) + for i in random_password1: random_password2 += i label_gen_obj.lineEditPassphraseAgain.setText(random_password2) - QTest.qWait(5) - QTest.qWait(800) + QTest.qWait(2) + + QTest.qWait(850) label_gen_obj.accept() self.assertEqual(random_password1, random_password2) print(" Creating Address ......") - QTest.qWait(3000) + QTest.qWait(2500) print(" Please Wait.! Creating 8 Address ......") - QTest.qWait(3000) + QTest.qWait(2500) self.assertEqual(len(BMConfigParser().addresses()), address_count + 8) QTest.qWait(100) print("\n Test Pass :--> Address Generated Successfully with passphrase \n") diff --git a/src/graphicaltesting/test_addsubscription.py b/src/graphicaltesting/test_addsubscription.py index 0901818b..8c0723de 100644 --- a/src/graphicaltesting/test_addsubscription.py +++ b/src/graphicaltesting/test_addsubscription.py @@ -17,20 +17,23 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): def test_subscription(self): """Test for subscription functionality""" - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) - QTest.qWait(500) - if BMConfigParser().addresses(): - try: + try: + if BMConfigParser().addresses(): + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + QTest.qWait(500) + self.dialog = dialogs.NewSubscriptionDialog(self.myapp) self.dialog.show() QTest.qWait(800) + random_label = "" for _ in range(30): random_label += choice(ascii_lowercase) self.dialog.lineEditLabel.setText(random_label) QTest.qWait(5) QTest.qWait(500) + rand_address = choice(BMConfigParser().addresses()) random_address = "" for x in range(len(rand_address)): @@ -38,7 +41,9 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): self.dialog.lineEditAddress.setText(random_address) QTest.qWait(5) QTest.qWait(500) + QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + try: QTest.qWait(800) address, label = self.dialog.data @@ -46,6 +51,7 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): QTest.qWait(500) print("\n Test Fail :--> Error, While Creating subscription list. \n") return 0 + if shared.isAddressInMySubscriptionsList(address): print( "\n Test Fail :--> You cannot add the same address to your subscriptions twice." @@ -53,6 +59,7 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): ) QTest.qWait(500) return 0 + self.myapp.addSubscription(address, label) sub_add = sqlQuery("select address from subscriptions where label='" + random_label + "'")[0] self.assertEqual(random_address, sub_add[0]) @@ -60,13 +67,13 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): QTest.qWait(100) self.assertTrue(True, " \n Test Pass :--> Subscription Done Successfully!") return 1 - except: + else: QTest.qWait(100) - print("\n Test Fail :--> Error Occured while adding address to subscription list! \n") - self.assertTrue(False, " \n Test Fail :--> Error Occured while adding address to subscription list! ") + print("\n Test Fail :--> No Address Found! \n") + self.assertTrue(False, " \n Test Fail :--> No Address Found!") return 0 - else: + except: QTest.qWait(100) - print("\n Test Fail :--> No Address Found! \n") - self.assertTrue(False, " \n Test Fail :--> No Address Found!") + print("\n Test Fail :--> Error Occured while adding address to subscription list! \n") + self.assertTrue(False, " \n Test Fail :--> Error Occured while adding address to subscription list! ") return 0 diff --git a/src/graphicaltesting/test_blackwhitelist.py b/src/graphicaltesting/test_blackwhitelist.py index d08881be..697302ef 100644 --- a/src/graphicaltesting/test_blackwhitelist.py +++ b/src/graphicaltesting/test_blackwhitelist.py @@ -20,24 +20,28 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): def test_blackwhitelist(self): """Tab switch to blacklist and add the address on blacklist and whitelist""" - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) - QTest.qWait(500) try: + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + QTest.qWait(500) + self.blacklist_obj = blacklist.Blacklist() self.dialog = AddAddressDialog(self.myapp) blacklistcount = len(sqlQuery("Select * from blacklist")) + self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() self.checkblacklist(self.myapp) QTest.qWait(500) self.assertEqual(blacklistcount + 1, len(sqlQuery("Select * from blacklist"))) whitelistcount = len(sqlQuery("Select * from whitelist")) + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() self.checkblacklist(self.myapp) QTest.qWait(500) self.assertEqual(whitelistcount + 1, len(sqlQuery("Select * from whitelist"))) + self.assertTrue(True, " \n Test Pass :--> Black/WhiteList Functionality Tested Successfully!") except: - pass + self.assertTrue(False, " \n Test Fail :--> Black/WhiteList Functionality Failed!.") def checkblacklist(self, myapp): """fill blacklist and whitelist fields""" diff --git a/src/graphicaltesting/test_chans.py b/src/graphicaltesting/test_chans.py index 959dc530..3b037b18 100644 --- a/src/graphicaltesting/test_chans.py +++ b/src/graphicaltesting/test_chans.py @@ -11,7 +11,5 @@ class BitmessageTest_ChansTest(BitmessageTestCase): """Switch to chans window and test""" QTest.qWait(1200) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.chans) - # QTest.mouseClick(self.myapp.ui.pushButtonAddChan, Qt.LeftButton) - # self.assertEqual('foo'.upper(), 'F00') print("\n Test Pass :--> Chans Test Passed! \n") return 1 diff --git a/src/graphicaltesting/test_inbox_popmenu.py b/src/graphicaltesting/test_inbox_popmenu.py new file mode 100644 index 00000000..039b7379 --- /dev/null +++ b/src/graphicaltesting/test_inbox_popmenu.py @@ -0,0 +1,134 @@ +"""Inbox TabWidget QTreeWidget Testing""" +import random +from random import choice +from string import ascii_lowercase + +from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import Qt +from PyQt4.QtTest import QTest + +from bitmessageqt import dialogs +from bmconfigparser import BMConfigParser +from testloader import BitmessageTestCase + + +class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): + """Inbox TabWidget QTreeWidget popMenu Fucntionality testing""" + + def test_sider(self): + """Show QTreeWidget popmenu""" + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(500) + treeWidget = self.myapp.ui.treeWidgetYourIdentities + self.levelitem = treeWidget.topLevelItem(random.randint(1, len(BMConfigParser().addresses()))) + self.myapp.ui.treeWidgetYourIdentities.setCurrentItem(self.levelitem) + rect = self.myapp.ui.treeWidgetYourIdentities.visualItemRect(self.levelitem) + self.currentItem = self.myapp.getCurrentItem() + self.myapp.on_context_menuYourIdentities(QtCore.QPoint(rect.x() + 200, rect.y() + 200)) + QTest.qWait(500) + self.myapp.popMenuYourIdentities.hide() + QTest.qWait(100) + self.copy_clipboard() + QTest.qWait(100) + self.enable_disable() + QTest.qWait(100) + self.special_address_behavior() + QTest.qWait(100) + self.email_gateway() + QTest.qWait(100) + self.mark_all_as_read() + + def copy_clipboard(self): + """Copy address to clipboard and test""" + try: + text_selected = self.levelitem.text(0) + QTest.qWait(250) + self.myapp.popMenuYourIdentities.actions()[2].trigger() + QTest.qWait(750) + if str(QtGui.QApplication.clipboard().text()) in str(text_selected): + self.assertTrue(True, " Test Pass :--> Copy functionality working fine \n") + print(" Test Pass :--> Copy functionality working fine \n") + else: + print(" Test Fail :--> Copy functionality failed \n") + self.assertTrue(False, " Test Fail :--> Copy functionality failed \n") + except: + print(" Test Fail :--> Copy functionality failed \n") + self.assertTrue(False, " Test Fail :--> Copy functionality failed \n") + + def enable_disable(self): + """Enable address and disable address""" + QTest.qWait(500) + try: + if self.currentItem.isEnabled: + QTest.qWait(300) + self.myapp.popMenuYourIdentities.actions()[4].trigger() + print("Address is Disabled \n") + QTest.qWait(1000) + self.myapp.on_action_Enable() + print("Address is Enabled \n") + QTest.qWait(1000) + else: + QTest.qWait(300) + self.myapp.popMenuYourIdentities.actions()[4].trigger() + print("Address is Enabled \n") + QTest.qWait(1000) + self.myapp.on_action_Disable() + print("Address is Disabled \n") + QTest.qWait(1000) + except: + self.assertTrue(False, " Test Fail :--> Enable Disable failed \n") + + def special_address_behavior(self): + """Tests for special address""" + try: + special_add = dialogs.SpecialAddressBehaviorDialog(self.myapp, BMConfigParser()) + special_add.lineEditMailingListName.setText("") + QTest.qWait(1000) + special_add.radioButtonBehaviorMailingList.click() + QTest.qWait(500) + special_add.lineEditMailingListName.setText("".join(choice(ascii_lowercase) for x in range(15))) + QTest.qWait(1000) + QTest.mouseClick(special_add.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) + self.assertTrue(True, " Test Pass :--> Special Address Behavior Functionality Passed \n") + print(" Test Pass :--> Special Address Behavior Functionality Passed \n") + except: + print(" Test Fail :--> Special Address Behavior Functionality failed \n") + self.assertTrue(False, " Test Fail :--> Special Address Behavior Functionality failed \n") + + def email_gateway(self): + """Test email gateway functionality""" + try: + QTest.qWait(200) + email_gateway = dialogs.EmailGatewayDialog(self.myapp, config=BMConfigParser()) + QTest.qWait(300) + email_gateway.show() + QTest.qWait(1000) + email_gateway.radioButtonRegister.click() + QTest.qWait(500) + email = ( + ("".join(choice(ascii_lowercase) for x in range(10))) + + "@" + + ("".join(choice(ascii_lowercase) for x in range(7))) + + ".com" + ) + email_gateway.lineEditEmail.setText(email) + QTest.qWait(1000) + QTest.mouseClick(email_gateway.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) + self.assertTrue(True, " Test Pass :--> Email-Gateway Functionality Passed \n") + print(" Test Pass :--> Email-Gateway Functionality Passed \n") + except: + print(" Test Fail :--> Email-Gateway Functionality failed \n") + self.assertTrue(False, " Test Fail :--> Email-Gateway Functionality failed \n") + + def mark_all_as_read(self): + """Mark all messages as read""" + try: + QTest.qWait(1000) + self.myapp.popMenuYourIdentities.actions()[11].trigger() + QTest.qWait(200) + self.assertTrue(True, " Test Pass :--> Mark All as Read Functionality Passed \n") + print(" Test Pass :--> Mark All as Read Functionality Passed \n") + except: + print(" Test Fail :--> Mark All as Read Functionality failed \n") + self.assertTrue(False, " Test Fail :--> Mark All as Read Functionality failed \n") diff --git a/src/graphicaltesting/test_messagesend.py b/src/graphicaltesting/test_messagesend.py index b9a0b6d7..5c2ddcdb 100644 --- a/src/graphicaltesting/test_messagesend.py +++ b/src/graphicaltesting/test_messagesend.py @@ -20,11 +20,13 @@ class BitmessageTest_MessageTesting(BitmessageTestCase): if BMConfigParser().addresses(): QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) - QTest.qWait(800) + QTest.qWait(500) + self.myapp.ui.comboBoxSendFrom.setCurrentIndex( random.randrange(1, len(BMConfigParser().addresses()) + 1) ) QTest.qWait(1000) + rand_address = choice(BMConfigParser().addresses()) random_address = "" for x in range(len(rand_address)): @@ -32,27 +34,33 @@ class BitmessageTest_MessageTesting(BitmessageTestCase): self.myapp.ui.lineEditTo.setText(random_address) QTest.qWait(1) QTest.qWait(800) + random_subject = "" for x in range(40): random_subject += choice(ascii_lowercase) self.myapp.ui.lineEditSubject.setText(random_subject) QTest.qWait(1) QTest.qWait(800) + random_message = "" for x in range(200): random_message += choice(ascii_lowercase) self.myapp.ui.textEditMessage.setText(random_message) QTest.qWait(1) QTest.qWait(800) + inbox_length = len(sqlQuery("Select msgid from inbox")) QTest.mouseClick(self.myapp.ui.pushButtonSend, Qt.LeftButton) QTest.qWait(600) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) print(" .......................... waiting for message .......................... ") + for x in range(5): QTest.qWait(5000) print(" waiting " + x * ".") self.assertEqual(sqlQuery("Select toaddress,subject from inbox")[-1], (rand_address, random_subject)) + if len(sqlQuery("Select msgid from inbox")) == inbox_length + 1: QTest.qWait(100) print("\n Test Pass :--> Message Received Successfully \n") diff --git a/src/graphicaltesting/test_networkstatus.py b/src/graphicaltesting/test_networkstatus.py index d3dbb35a..3b252594 100644 --- a/src/graphicaltesting/test_networkstatus.py +++ b/src/graphicaltesting/test_networkstatus.py @@ -9,8 +9,11 @@ class BitmessageTest_NetworkTest(BitmessageTestCase): def test_network(self): """Switch to network window""" - QTest.qWait(1000) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus) - QTest.qWait(1200) - print("\n Test Pass :--> Network Functionality Working Well! \n") - return 1 + try: + QTest.qWait(1000) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus) + QTest.qWait(1200) + print("\n Test Pass :--> Network Functionality Working Well! \n") + return 1 + except: + print("\n Test Fail :--> Network Functionality Failed! \n") diff --git a/src/graphicaltesting/test_settingwindow.py b/src/graphicaltesting/test_settingwindow.py index cd2ed89a..efc68afd 100644 --- a/src/graphicaltesting/test_settingwindow.py +++ b/src/graphicaltesting/test_settingwindow.py @@ -17,7 +17,7 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): def test_settingwindow(self): """Triggers the setting window""" self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) - QTest.qWait(1700) + QTest.qWait(1500) dialog = dialogs.SettingsDialog(self.myapp, firstrun=self.myapp._firstrun) self.language_change(dialog) QTest.qWait(300) diff --git a/src/graphicaltesting/testinitialization.py b/src/graphicaltesting/testinitialization.py index 02cef716..720ffc6f 100644 --- a/src/graphicaltesting/testinitialization.py +++ b/src/graphicaltesting/testinitialization.py @@ -7,30 +7,27 @@ import test_blackwhitelist import test_chans import test_messagesend import test_networkstatus -import test_settingwindow import test_quit +import test_settingwindow +import test_inbox_popmenu from testloader import BitmessageTestCase def test_initialize(myapp): - """Test Loader""" + """Inititalizing the test cases""" suite = unittest.TestSuite() suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_chans.BitmessageTest_ChansTest, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader(test_inbox_popmenu.BitmessageTest_Inbox_PopMenu, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_quit.BitmessageTest_QuitTest, myapp=myapp)) unittest.TextTestRunner().run(suite) diff --git a/src/graphicaltesting/testloader.py b/src/graphicaltesting/testloader.py index 8d21dd6b..580811f2 100644 --- a/src/graphicaltesting/testloader.py +++ b/src/graphicaltesting/testloader.py @@ -11,7 +11,7 @@ class BitmessageTestCase(unittest.TestCase): @staticmethod def bitmessage_testloader(testcaseclass, myapp=None): - """Test Loader""" + """Method responsible for loading test""" testnames = unittest.TestLoader().getTestCaseNames(testcaseclass) suite = unittest.TestSuite() for name in testnames: -- 2.45.1 From 5e92603fccf077a9a079d955877ae163535e45ba Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Fri, 13 Mar 2020 20:10:20 +0530 Subject: [PATCH 4/6] Graphical Qt Test popupmenu automation --- src/bitmessageqt/__init__.py | 17 +- .../test_addressgeneration.py | 67 +- src/graphicaltesting/test_addsubscription.py | 58 +- src/graphicaltesting/test_blackwhitelist.py | 72 ++- src/graphicaltesting/test_chans.py | 3 +- src/graphicaltesting/test_inbox_popmenu.py | 134 ---- src/graphicaltesting/test_messagesend.py | 62 +- src/graphicaltesting/test_networkstatus.py | 6 +- src/graphicaltesting/test_popupmenu.py | 607 ++++++++++++++++++ src/graphicaltesting/test_quit.py | 1 + src/graphicaltesting/test_settingwindow.py | 57 +- src/graphicaltesting/testinitialization.py | 28 +- src/{gtesting.py => test_qt.py} | 10 +- 13 files changed, 798 insertions(+), 324 deletions(-) delete mode 100644 src/graphicaltesting/test_inbox_popmenu.py create mode 100644 src/graphicaltesting/test_popupmenu.py rename src/{gtesting.py => test_qt.py} (50%) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 33291ece..733265f6 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2514,7 +2514,6 @@ class MyForm(settingsmixin.SMainWindow): self.ui.textEditMessage.setFocus() def on_action_MarkAllRead(self): - import state if state.qttesting: tableWidget = self.getCurrentMessagelist() else: @@ -3287,8 +3286,12 @@ class MyForm(settingsmixin.SMainWindow): self.popMenuAddressBook.addSeparator() for plugin in self.menu_plugins['address']: self.popMenuAddressBook.addAction(plugin) - self.popMenuAddressBook.exec_( - self.ui.tableWidgetAddressBook.mapToGlobal(point)) + if state.qttesting: + self.popMenuAddressBook.move(point.x(), point.y()) + self.popMenuAddressBook.show() + else: + self.popMenuAddressBook.exec_( + self.ui.tableWidgetAddressBook.mapToGlobal(point)) # Group of functions for the Subscriptions dialog box def on_action_SubscriptionsNew(self): @@ -3368,8 +3371,12 @@ class MyForm(settingsmixin.SMainWindow): self.popMenuSubscriptions.addAction(self.actionMarkAllRead) if self.popMenuSubscriptions.isEmpty(): return - self.popMenuSubscriptions.exec_( - self.ui.treeWidgetSubscriptions.mapToGlobal(point)) + if state.qttesting: + self.popMenuSubscriptions.move(point.x(), point.y()) + self.popMenuSubscriptions.show() + else: + self.popMenuSubscriptions.exec_( + self.ui.treeWidgetSubscriptions.mapToGlobal(point)) def widgetConvert(self, widget): if widget == self.ui.tableWidgetInbox: diff --git a/src/graphicaltesting/test_addressgeneration.py b/src/graphicaltesting/test_addressgeneration.py index 849217f2..e049efe3 100644 --- a/src/graphicaltesting/test_addressgeneration.py +++ b/src/graphicaltesting/test_addressgeneration.py @@ -14,85 +14,74 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): def test_generateaddress(self): """Method clicks on new label pushbutton and create new address with random label""" + print("=====================Test - Generating Address=====================") try: - address_count = len(BMConfigParser().addresses()) QTest.qWait(500) + bm_addresses = BMConfigParser().addresses() self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) QTest.qWait(500) - self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonNewAddress.setStyleSheet("") - label_gen_obj = address_dialogs.NewAddressDialog() - QTest.qWait(1000) - + QTest.qWait(750) random_label = "" - for _ in range(12): + for _ in range(15): random_label += choice(ascii_lowercase) label_gen_obj.newaddresslabel.setText(random_label) - QTest.qWait(2) - - QTest.qWait(600) + QTest.qWait(4) + QTest.qWait(500) label_gen_obj.accept() - QTest.qWait(800) - - self.assertEqual(len(BMConfigParser().addresses()), address_count + 1) - self.assertEqual(str(BMConfigParser().get(BMConfigParser().addresses()[-1], "label")), random_label) - print("\n Test Pass :--> Address Generated Successfully \n") - self.assertTrue(True, " \n Test Pass :--> Address Generated Successfully") + QTest.qWait(750) + new_bm_addresses = BMConfigParser().addresses() + self.assertEqual(len(new_bm_addresses), len(bm_addresses) + 1) + self.assertEqual(str(BMConfigParser().get(new_bm_addresses[-1], "label")), random_label) + print("Test Pass:--> Address Generated Successfully") return 1 # if every thing is ok except: - print("\n Test Fail :--> Address Generatation Failed or Taking too much time to generate address \n") - self.assertTrue(False, " \n Test Fail :--> Address Generation Failed!") + print("Test Fail:--> Address Generatation Failed or Taking too much time to generate address") return 0 # if test fail def test_generateaddresswithpassphrase(self): """Clicks on the create new label with passphrase pushbutton and generates 8 address""" + print("=====================Test - Generating Address with passphrase=====================") try: - address_count = len(BMConfigParser().addresses()) QTest.qWait(500) + bm_addresses = BMConfigParser().addresses() self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) QTest.qWait(500) - self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonNewAddress.setStyleSheet("") - label_gen_obj = address_dialogs.NewAddressDialog() - QTest.qWait(500) + QTest.qWait(750) label_gen_obj.radioButtonDeterministicAddress.click() - QTest.qWait(400) - - random_password1, random_password2 = "", "" - for i in range(15): + QTest.qWait(250) + random_password1 = "" + for _ in range(15): random_password1 += choice(ascii_lowercase) label_gen_obj.lineEditPassphrase.setText(random_password1) - QTest.qWait(2) + QTest.qWait(4) QTest.qWait(500) - + random_password2 = "" for i in random_password1: random_password2 += i label_gen_obj.lineEditPassphraseAgain.setText(random_password2) QTest.qWait(2) - - QTest.qWait(850) + QTest.qWait(500) label_gen_obj.accept() + QTest.qWait(750) self.assertEqual(random_password1, random_password2) - print(" Creating Address ......") + print(" Creating 8 Addresses. Please Wait! ......") QTest.qWait(2500) - print(" Please Wait.! Creating 8 Address ......") + print(" Generating ......... ") QTest.qWait(2500) - self.assertEqual(len(BMConfigParser().addresses()), address_count + 8) - QTest.qWait(100) - print("\n Test Pass :--> Address Generated Successfully with passphrase \n") - self.assertTrue(True, " \n Test Pass :--> Address Generated Successfully with passphrase") + self.assertEqual(len(BMConfigParser().addresses()), len(bm_addresses) + 8) + print("Test Pass:--> Address Generated Successfully with passphrase") return 1 except: - QTest.qWait(100) print( - "\n Test Fail :--> Address Generatation Failed with passphrase" - " or Taking too much time to generate address \n" + "Test Fail:--> Address Generatation Failed" + " with passphrase or Taking too much time to generate address" ) - self.assertTrue(False, " \n Test Fail :--> Address Generatation Failed with passphrase") return 0 diff --git a/src/graphicaltesting/test_addsubscription.py b/src/graphicaltesting/test_addsubscription.py index 8c0723de..b4b8bc18 100644 --- a/src/graphicaltesting/test_addsubscription.py +++ b/src/graphicaltesting/test_addsubscription.py @@ -2,7 +2,8 @@ from random import choice from string import ascii_lowercase -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui +from PyQt4.QtCore import QTimer from PyQt4.QtTest import QTest import shared @@ -17,63 +18,56 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): def test_subscription(self): """Test for subscription functionality""" + print("=====================Test - Subscribe Address=====================") try: if BMConfigParser().addresses(): QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) QTest.qWait(500) - - self.dialog = dialogs.NewSubscriptionDialog(self.myapp) - self.dialog.show() - QTest.qWait(800) - + self.myapp.ui.pushButtonAddSubscription.setStyleSheet( + "QPushButton {background-color: #FF5733; color: white;}" + ) + QTest.qWait(50) + self.myapp.ui.pushButtonAddSubscription.setStyleSheet("") + dialog = dialogs.NewSubscriptionDialog(self.myapp) + dialog.show() + QTest.qWait(750) random_label = "" for _ in range(30): random_label += choice(ascii_lowercase) - self.dialog.lineEditLabel.setText(random_label) - QTest.qWait(5) + dialog.lineEditLabel.setText(random_label) + QTest.qWait(4) QTest.qWait(500) - rand_address = choice(BMConfigParser().addresses()) random_address = "" - for x in range(len(rand_address)): - random_address += rand_address[x] - self.dialog.lineEditAddress.setText(random_address) - QTest.qWait(5) + for i, _ in enumerate(rand_address): + random_address += rand_address[i] + dialog.lineEditAddress.setText(random_address) + QTest.qWait(4) QTest.qWait(500) - - QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) - + QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) try: QTest.qWait(800) - address, label = self.dialog.data - except AttributeError: + address, label = dialog.data + except: + print("Test Fail:--> Error, While Creating subscription list") QTest.qWait(500) - print("\n Test Fail :--> Error, While Creating subscription list. \n") return 0 - if shared.isAddressInMySubscriptionsList(address): print( - "\n Test Fail :--> You cannot add the same address to your subscriptions twice." - " Perhaps rename the existing one if you want. \n" + "Test Fail:--> You cannot add the same address to your subscriptions twice." + " Perhaps rename the existing one if you want" ) QTest.qWait(500) return 0 - self.myapp.addSubscription(address, label) sub_add = sqlQuery("select address from subscriptions where label='" + random_label + "'")[0] self.assertEqual(random_address, sub_add[0]) - print("\n Test Pass :--> Subscription Done Successfully! \n") - QTest.qWait(100) - self.assertTrue(True, " \n Test Pass :--> Subscription Done Successfully!") + print("Test Pass:--> Subscription Done Successfully") return 1 else: - QTest.qWait(100) - print("\n Test Fail :--> No Address Found! \n") - self.assertTrue(False, " \n Test Fail :--> No Address Found!") + print("Test Fail:--> No Address Found") return 0 except: - QTest.qWait(100) - print("\n Test Fail :--> Error Occured while adding address to subscription list! \n") - self.assertTrue(False, " \n Test Fail :--> Error Occured while adding address to subscription list! ") + print("Test Fail:--> Error Occured while adding address to subscription list") return 0 diff --git a/src/graphicaltesting/test_blackwhitelist.py b/src/graphicaltesting/test_blackwhitelist.py index 697302ef..37836c90 100644 --- a/src/graphicaltesting/test_blackwhitelist.py +++ b/src/graphicaltesting/test_blackwhitelist.py @@ -20,49 +20,62 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): def test_blackwhitelist(self): """Tab switch to blacklist and add the address on blacklist and whitelist""" + print("=====================Test - Adding Address to Black/WhiteList=====================") + self.blacklist_obj = blacklist.Blacklist() try: QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) QTest.qWait(500) - - self.blacklist_obj = blacklist.Blacklist() self.dialog = AddAddressDialog(self.myapp) blacklistcount = len(sqlQuery("Select * from blacklist")) - self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() - self.checkblacklist(self.myapp) + self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet( + "QPushButton {background-color: #FF5733; color: white;}" + ) + QTest.qWait(50) + self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("") + self.checkblacklist() + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() + self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() + QTest.qWait(500) + whitelistcount = len(sqlQuery("Select * from whitelist")) + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() + self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet( + "QPushButton {background-color: #FF5733; color: white;}" + ) + QTest.qWait(50) + self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("") + self.checkblacklist() + self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() QTest.qWait(500) self.assertEqual(blacklistcount + 1, len(sqlQuery("Select * from blacklist"))) - whitelistcount = len(sqlQuery("Select * from whitelist")) - - self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() - self.checkblacklist(self.myapp) - QTest.qWait(500) self.assertEqual(whitelistcount + 1, len(sqlQuery("Select * from whitelist"))) - self.assertTrue(True, " \n Test Pass :--> Black/WhiteList Functionality Tested Successfully!") + print("Black/WhiteList Functionality Tested Successfully") + return 1 except: - self.assertTrue(False, " \n Test Fail :--> Black/WhiteList Functionality Failed!.") + print("Black/WhiteList Functionality Failed") + return 0 - def checkblacklist(self, myapp): + def checkblacklist(self): # pylint: disable=too-many-statements """fill blacklist and whitelist fields""" - # pylint: disable=too-many-statements - QTest.qWait(1000) self.dialog.lineEditLabel.setText("") self.dialog.lineEditAddress.setText("") + QTest.qWait(350) self.dialog.show() - QTest.qWait(800) + QTest.qWait(750) random_label = "" for _ in range(30): random_label += choice(ascii_lowercase) self.dialog.lineEditLabel.setText(random_label) - QTest.qWait(5) + QTest.qWait(4) QTest.qWait(500) rand_address = choice(BMConfigParser().addresses()) random_address = "" - for x in range(len(rand_address)): - random_address += rand_address[x] + for i, _ in enumerate(rand_address): + random_address += rand_address[i] self.dialog.lineEditAddress.setText(random_address) - QTest.qWait(5) + QTest.qWait(4) QTest.qWait(500) QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) if self.dialog.labelAddressCheck.text() == _translate("MainWindow", "Address is valid."): @@ -88,30 +101,23 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): sql = """INSERT INTO blacklist VALUES (?,?,?)""" sqlExecute(sql, *t) black_list_value = sqlQuery("Select address from blacklist where label='" + random_label + "'")[0] - print("\n Test Pass :--> Address Added to the blacklist! \n") self.assertEqual(black_list_value[0], random_address) - return + print("Test Pass:--> Address Added to the blacklist") + return 1 else: sql = """INSERT INTO whitelist VALUES (?,?,?)""" sqlExecute(sql, *t) white_list_value = sqlQuery("Select address from whitelist where label='" + random_label + "'")[0] - print("\n Test Pass :--> Address Added to the whitelist! \n") self.assertEqual(white_list_value[0], random_address) - return + print("Test Pass:--> Address Added to the whitelist") + return 1 else: - QTest.qWait(100) print( - "\n Test Fail :--> You cannot add the same address to your list twice." - " Perhaps rename the existing one if you want. \n" - ) - self.assertTrue( - False, - "\n Test Fail :--> You cannot add the same address to your list twice." - " Perhaps rename the existing one if you want.", + "Test Fail:--> You cannot add the same address to your list twice." + "Perhaps rename the existing one if you want" ) return 0 else: QTest.qWait(100) - print("\n Test Fail :--> The address you entered was invalid. Ignoring it. \n") - self.assertTrue(False, " \n Test Fail :--> The address you entered was invalid. Ignoring it.") + print("Test Fail:--> The address you entered was invalid. Ignoring it") return 0 diff --git a/src/graphicaltesting/test_chans.py b/src/graphicaltesting/test_chans.py index 3b037b18..1a7105b1 100644 --- a/src/graphicaltesting/test_chans.py +++ b/src/graphicaltesting/test_chans.py @@ -9,7 +9,8 @@ class BitmessageTest_ChansTest(BitmessageTestCase): def test_chans(self): """Switch to chans window and test""" + print("=====================Test - Chans Functionality=====================") QTest.qWait(1200) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.chans) - print("\n Test Pass :--> Chans Test Passed! \n") + print("Test Pass :--> Chans Test Passed") return 1 diff --git a/src/graphicaltesting/test_inbox_popmenu.py b/src/graphicaltesting/test_inbox_popmenu.py deleted file mode 100644 index 039b7379..00000000 --- a/src/graphicaltesting/test_inbox_popmenu.py +++ /dev/null @@ -1,134 +0,0 @@ -"""Inbox TabWidget QTreeWidget Testing""" -import random -from random import choice -from string import ascii_lowercase - -from PyQt4 import QtCore, QtGui -from PyQt4.QtCore import Qt -from PyQt4.QtTest import QTest - -from bitmessageqt import dialogs -from bmconfigparser import BMConfigParser -from testloader import BitmessageTestCase - - -class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): - """Inbox TabWidget QTreeWidget popMenu Fucntionality testing""" - - def test_sider(self): - """Show QTreeWidget popmenu""" - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) - QTest.qWait(500) - treeWidget = self.myapp.ui.treeWidgetYourIdentities - self.levelitem = treeWidget.topLevelItem(random.randint(1, len(BMConfigParser().addresses()))) - self.myapp.ui.treeWidgetYourIdentities.setCurrentItem(self.levelitem) - rect = self.myapp.ui.treeWidgetYourIdentities.visualItemRect(self.levelitem) - self.currentItem = self.myapp.getCurrentItem() - self.myapp.on_context_menuYourIdentities(QtCore.QPoint(rect.x() + 200, rect.y() + 200)) - QTest.qWait(500) - self.myapp.popMenuYourIdentities.hide() - QTest.qWait(100) - self.copy_clipboard() - QTest.qWait(100) - self.enable_disable() - QTest.qWait(100) - self.special_address_behavior() - QTest.qWait(100) - self.email_gateway() - QTest.qWait(100) - self.mark_all_as_read() - - def copy_clipboard(self): - """Copy address to clipboard and test""" - try: - text_selected = self.levelitem.text(0) - QTest.qWait(250) - self.myapp.popMenuYourIdentities.actions()[2].trigger() - QTest.qWait(750) - if str(QtGui.QApplication.clipboard().text()) in str(text_selected): - self.assertTrue(True, " Test Pass :--> Copy functionality working fine \n") - print(" Test Pass :--> Copy functionality working fine \n") - else: - print(" Test Fail :--> Copy functionality failed \n") - self.assertTrue(False, " Test Fail :--> Copy functionality failed \n") - except: - print(" Test Fail :--> Copy functionality failed \n") - self.assertTrue(False, " Test Fail :--> Copy functionality failed \n") - - def enable_disable(self): - """Enable address and disable address""" - QTest.qWait(500) - try: - if self.currentItem.isEnabled: - QTest.qWait(300) - self.myapp.popMenuYourIdentities.actions()[4].trigger() - print("Address is Disabled \n") - QTest.qWait(1000) - self.myapp.on_action_Enable() - print("Address is Enabled \n") - QTest.qWait(1000) - else: - QTest.qWait(300) - self.myapp.popMenuYourIdentities.actions()[4].trigger() - print("Address is Enabled \n") - QTest.qWait(1000) - self.myapp.on_action_Disable() - print("Address is Disabled \n") - QTest.qWait(1000) - except: - self.assertTrue(False, " Test Fail :--> Enable Disable failed \n") - - def special_address_behavior(self): - """Tests for special address""" - try: - special_add = dialogs.SpecialAddressBehaviorDialog(self.myapp, BMConfigParser()) - special_add.lineEditMailingListName.setText("") - QTest.qWait(1000) - special_add.radioButtonBehaviorMailingList.click() - QTest.qWait(500) - special_add.lineEditMailingListName.setText("".join(choice(ascii_lowercase) for x in range(15))) - QTest.qWait(1000) - QTest.mouseClick(special_add.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) - self.assertTrue(True, " Test Pass :--> Special Address Behavior Functionality Passed \n") - print(" Test Pass :--> Special Address Behavior Functionality Passed \n") - except: - print(" Test Fail :--> Special Address Behavior Functionality failed \n") - self.assertTrue(False, " Test Fail :--> Special Address Behavior Functionality failed \n") - - def email_gateway(self): - """Test email gateway functionality""" - try: - QTest.qWait(200) - email_gateway = dialogs.EmailGatewayDialog(self.myapp, config=BMConfigParser()) - QTest.qWait(300) - email_gateway.show() - QTest.qWait(1000) - email_gateway.radioButtonRegister.click() - QTest.qWait(500) - email = ( - ("".join(choice(ascii_lowercase) for x in range(10))) - + "@" - + ("".join(choice(ascii_lowercase) for x in range(7))) - + ".com" - ) - email_gateway.lineEditEmail.setText(email) - QTest.qWait(1000) - QTest.mouseClick(email_gateway.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) - self.assertTrue(True, " Test Pass :--> Email-Gateway Functionality Passed \n") - print(" Test Pass :--> Email-Gateway Functionality Passed \n") - except: - print(" Test Fail :--> Email-Gateway Functionality failed \n") - self.assertTrue(False, " Test Fail :--> Email-Gateway Functionality failed \n") - - def mark_all_as_read(self): - """Mark all messages as read""" - try: - QTest.qWait(1000) - self.myapp.popMenuYourIdentities.actions()[11].trigger() - QTest.qWait(200) - self.assertTrue(True, " Test Pass :--> Mark All as Read Functionality Passed \n") - print(" Test Pass :--> Mark All as Read Functionality Passed \n") - except: - print(" Test Fail :--> Mark All as Read Functionality failed \n") - self.assertTrue(False, " Test Fail :--> Mark All as Read Functionality failed \n") diff --git a/src/graphicaltesting/test_messagesend.py b/src/graphicaltesting/test_messagesend.py index 5c2ddcdb..41833ea4 100644 --- a/src/graphicaltesting/test_messagesend.py +++ b/src/graphicaltesting/test_messagesend.py @@ -16,68 +16,54 @@ class BitmessageTest_MessageTesting(BitmessageTestCase): def test_msgsend(self): """Auto-fill senders address, receivers address, subject and message and sends the message""" + print("=====================Test - Message Send/Receive Functionality=====================") try: if BMConfigParser().addresses(): + inbox_length = len(sqlQuery("Select msgid from inbox")) QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) QTest.qWait(500) - - self.myapp.ui.comboBoxSendFrom.setCurrentIndex( - random.randrange(1, len(BMConfigParser().addresses()) + 1) - ) - QTest.qWait(1000) - rand_address = choice(BMConfigParser().addresses()) random_address = "" - for x in range(len(rand_address)): - random_address += rand_address[x] + for i, _ in enumerate(rand_address): + random_address += rand_address[i] self.myapp.ui.lineEditTo.setText(random_address) - QTest.qWait(1) - QTest.qWait(800) - + QTest.qWait(4) + QTest.qWait(500) random_subject = "" - for x in range(40): + for x in range(30): random_subject += choice(ascii_lowercase) self.myapp.ui.lineEditSubject.setText(random_subject) - QTest.qWait(1) - QTest.qWait(800) - + QTest.qWait(4) + QTest.qWait(500) random_message = "" - for x in range(200): + for x in range(150): random_message += choice(ascii_lowercase) self.myapp.ui.textEditMessage.setText(random_message) QTest.qWait(1) - QTest.qWait(800) - - inbox_length = len(sqlQuery("Select msgid from inbox")) + QTest.qWait(400) + randinteger = random.randrange(1, len(BMConfigParser().addresses()) + 1) + self.myapp.ui.comboBoxSendFrom.setCurrentIndex(randinteger) + QTest.qWait(1000) QTest.mouseClick(self.myapp.ui.pushButtonSend, Qt.LeftButton) - QTest.qWait(600) - + QTest.qWait(350) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) - print(" .......................... waiting for message .......................... ") - + print(" Waiting For Message .......................... ") for x in range(5): - QTest.qWait(5000) + QTest.qWait(4000) print(" waiting " + x * ".") - self.assertEqual(sqlQuery("Select toaddress,subject from inbox")[-1], (rand_address, random_subject)) - + new_inbox = sqlQuery("Select msgid,toaddress,subject from inbox") + self.assertEqual(new_inbox[-1][1], rand_address) + self.assertEqual(new_inbox[-1][2], random_subject) if len(sqlQuery("Select msgid from inbox")) == inbox_length + 1: - QTest.qWait(100) - print("\n Test Pass :--> Message Received Successfully \n") - self.assertTrue(True, " Test Pass :--> Message Received Successfully") + print("Test Pass:--> Message Received Successfully") return 1 else: - QTest.qWait(100) - print("\n Test Fail :--> Doesn't Receive Any Message!! \n") - self.assertTrue(False, " \n Test Fail :--> Doesn't Receive Any Message!!") + print("Test Fail:--> Doesn't Receive Any Message") return 0 else: - QTest.qWait(100) - print("\n Test Fail :--> No Address Found!! \n") - self.assertTrue(False, " \n Test Fail :--> No Address Found!!") + print("Test Fail:--> No Address Found") return 0 except: - QTest.qWait(100) - print("\n Test Fail :--> Message Sending Test Fail!! \n") - self.assertTrue(False, " \n Test Fail :--> Message Sending Test Fail!!") + print("Test Fail:--> Message Sending Test Fail") return 0 diff --git a/src/graphicaltesting/test_networkstatus.py b/src/graphicaltesting/test_networkstatus.py index 3b252594..4a427d2b 100644 --- a/src/graphicaltesting/test_networkstatus.py +++ b/src/graphicaltesting/test_networkstatus.py @@ -10,10 +10,12 @@ class BitmessageTest_NetworkTest(BitmessageTestCase): def test_network(self): """Switch to network window""" try: + print("=====================Test - Network Functionality=====================") QTest.qWait(1000) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus) QTest.qWait(1200) - print("\n Test Pass :--> Network Functionality Working Well! \n") + print("Test Pass:--> Network Functionality Working Well") return 1 except: - print("\n Test Fail :--> Network Functionality Failed! \n") + print("Test Fail:--> Network Functionality Failed") + return 0 diff --git a/src/graphicaltesting/test_popupmenu.py b/src/graphicaltesting/test_popupmenu.py new file mode 100644 index 00000000..1fd242bd --- /dev/null +++ b/src/graphicaltesting/test_popupmenu.py @@ -0,0 +1,607 @@ +"""Inbox TabWidget QTreeWidget Testing""" +import random +from random import choice +from string import ascii_lowercase + +from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import Qt +from PyQt4.QtTest import QTest + +import queues +import shared +from bitmessageqt import blacklist, dialogs +from bmconfigparser import BMConfigParser +from helper_sql import sqlExecute, sqlQuery +from testloader import BitmessageTestCase +from tr import _translate + + +class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): + """Inbox TabWidget QTreeWidget popMenu Fucntionality testing""" + + def test_sider(self): + """Show QTreeWidget popmenu""" + try: + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(500) + self.treeWidget = self.myapp.ui.treeWidgetYourIdentities + self.levelitem = self.treeWidget.topLevelItem(random.randint(1, len(BMConfigParser().addresses()) + 1)) + self.treeWidget.setCurrentItem(self.levelitem) + self.currentItem = self.myapp.getCurrentItem() + self.rect = self.treeWidget.visualItemRect(self.levelitem) + self.myapp.on_context_menuYourIdentities(QtCore.QPoint(self.rect.x() + 160, self.rect.y() + 200)) + self.myapp.popMenuYourIdentities.hide() + self.copy_clipboard() + self.enable_disable() + self.special_address_behavior() + self.email_gateway() + self.mark_all_as_read() + return 1 + except: + print("Test Fail:--> QTreeWidget popmenu functionality failed") + return 0 + + def copy_clipboard(self): + """Copy Address to the ClipBoard and test whether the copied test is same or not?""" + print("=====================Test - Copy Address to the ClipBoard=====================") + try: + self.popup_menu(2) + text_selected = self.currentItem.text(0) + QTest.qWait(500) + self.myapp.popMenuYourIdentities.actions()[2].trigger() + QTest.qWait(750) + if str(QtGui.QApplication.clipboard().text()) in str(text_selected): + print("Test Pass:--> Copy functionality working fine") + return 1 + else: + print("Test Fail:--> Copy functionality failed") + return 0 + except: + print("Test Fail:--> Copy functionality failed") + return 0 + + def enable_disable(self): + """Enable address and disable address""" + print("=====================Test - Address Enable-Disable Functionality=====================") + try: + self.popup_menu(4) + if self.currentItem.isEnabled: + QTest.qWait(500) + self.myapp.popMenuYourIdentities.actions()[4].trigger() + QTest.qWait(1000) + self.myapp.on_action_Enable() + QTest.qWait(500) + print("Test Pass:--> Enable-Disable working fine") + return 1 + else: + QTest.qWait(500) + self.myapp.popMenuYourIdentities.actions()[4].trigger() + QTest.qWait(1000) + self.myapp.on_action_Disable() + QTest.qWait(500) + print("Test Pass:--> Enable-Disable working fine") + return 1 + except: + print("Test Fail:--> Could not able to do Enable-Disable") + return 0 + + def special_address_behavior(self): + """Tests for special address""" + print("=====================Test - Address Special Behavior=====================") + try: + self.popup_menu(6) + special_add = dialogs.SpecialAddressBehaviorDialog(self.myapp, BMConfigParser()) + special_add.lineEditMailingListName.setText("") + QTest.qWait(500) + special_add.radioButtonBehaviorMailingList.click() + QTest.qWait(1000) + special_add.lineEditMailingListName.setText("".join(choice(ascii_lowercase) for x in range(15))) + QTest.qWait(500) + QTest.mouseClick(special_add.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) + print("Test Pass:--> Special Address Behavior Functionality Passed") + return 1 + except: + print("Test Fail:--> Special Address Behavior Functionality failed") + return 0 + + def email_gateway(self): + """Test email gateway functionality""" + print("=====================Test - Email Gateway=====================") + try: + self.popup_menu(7) + QTest.qWait(200) + email_gateway = dialogs.EmailGatewayDialog(self.myapp, BMConfigParser()) + email_gateway.show() + QTest.qWait(500) + email_gateway.radioButtonRegister.click() + QTest.qWait(450) + email = ( + ("".join(choice(ascii_lowercase) for x in range(10))) + + "@" + + ("".join(choice(ascii_lowercase) for x in range(7))) + + ".com" + ) + email_gateway.lineEditEmail.setText(email) + QTest.qWait(500) + QTest.mouseClick(email_gateway.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) + print("Test Pass:--> Email-Gateway Functionality Passed") + return 1 + except: + print("Test Fail:--> Email-Gateway Functionality failed") + return 0 + + def mark_all_as_read(self): + """Mark all messages as read""" + print("=====================Test - Mark All as Read Functionality=====================") + try: + self.popup_menu(11) + QTest.qWait(500) + self.myapp.popMenuYourIdentities.actions()[11].trigger() + QTest.qWait(500) + print("Test Pass:--> Mark All as Read Functionality Passed") + return 1 + except: + print("Test Fail:--> Mark All as Read Functionality failed") + return 0 + + def popup_menu(self, intval): + QTest.qWait(5) + self.myapp.popMenuYourIdentities.setActiveAction(self.myapp.popMenuYourIdentities.actions()[intval]) + self.myapp.popMenuYourIdentities.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.myapp.popMenuYourIdentities.show() + QTest.qWait(400) + self.myapp.popMenuYourIdentities.hide() + QTest.qWait(50) + + +class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): + """AddressBox TabWidget QTreeWidget popMenu Fucntionality testing""" + + def test_sider(self): + try: + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.treeWidget = self.myapp.ui.tableWidgetAddressBook + total_sub = sqlQuery("Select address from addressbook") + QTest.qWait(500) + self.rand_value = random.randint(0, len(total_sub) - 1) + self.current_address = str(self.treeWidget.item(self.rand_value, 1).text()) + self.treeWidget.setCurrentCell(self.rand_value, 1) + self.treeWidget.item(self.rand_value, 1).setSelected(True) + rect = self.treeWidget.visualItemRect(self.treeWidget.item(self.rand_value, 1)) + QTest.qWait(500) + self.myapp.on_context_menuAddressBook(QtCore.QPoint(rect.x() + 160, rect.y() + 200)) + QTest.qWait(500) + if len(total_sub) > 0: + self.treeWidget.item(random.randint(0, self.rand_value), 1) + else: + print("No Address Found.") + self.add_new_address() + self.myapp.popMenuAddressBook.hide() + self.send_message_to_this_add() + self.copy_clipboard() + self.subscribe_to_this_address() + self.delete_addressbook() + return 1 + except: + print("Test Fail:--> PopUpMenu Send Tab Functionality failed") + return 0 + + def add_new_address(self): + """Adding New Address to Address Book""" + print("=====================Test - Adding New Address to Address Book=====================") + try: + self.popup_menu(6) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.dialog = dialogs.AddAddressDialog(self.myapp) + self.dialog.show() + QTest.qWait(500) + self.dialog.lineEditLabel.setText("".join(choice(ascii_lowercase) for _ in range(15))) + QTest.qWait(500) + self.dialog.lineEditAddress.setText(choice(BMConfigParser().addresses())) + QTest.qWait(500) + QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + QTest.qWait(500) + try: + address, label = self.dialog.data + except: + print("Test Fail:--> Could Not able to add new address") + return 0 + if shared.isAddressInMyAddressBook(address): + print( + " Test :--> You cannot add the same address to your address book twice." + " Try renaming the existing one if you want. \n" + ) + self.myapp.updateStatusBar( + _translate( + "MainWindow", + "Error: You cannot add the same address to your adrress book twice." + " Try renaming the existing one if you want.", + ) + ) + return 0 + self.myapp.addEntryToAddressBook(address, label) + print("Test Pass:--> Address Added to the Address Book!") + return 1 + except: + print("Test Fail:--> Could Not able to add new address") + return 0 + + def send_message_to_this_add(self): + """Test - Send Message to this Address""" + print("=====================Test - Send Message to this Address=====================") + try: + self.popup_menu(0) + if BMConfigParser().addresses(): + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + inbox_length = len(sqlQuery("Select msgid from inbox")) + QTest.qWait(500) + self.myapp.popMenuAddressBook.actions()[0].trigger() + QTest.qWait(500) + random_subject = "" + for x in range(30): + random_subject += choice(ascii_lowercase) + self.myapp.ui.lineEditSubject.setText(random_subject) + QTest.qWait(4) + QTest.qWait(500) + random_message = "" + for x in range(150): + random_message += choice(ascii_lowercase) + self.myapp.ui.textEditMessage.setText(random_message) + QTest.qWait(1) + QTest.qWait(500) + randinteger = random.randrange(1, len(BMConfigParser().addresses()) + 1) + self.myapp.ui.comboBoxSendFrom.setCurrentIndex(randinteger) + QTest.qWait(500) + QTest.mouseClick(self.myapp.ui.pushButtonSend, Qt.LeftButton) + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + print(" Waiting For Message .......................... ") + for x in range(5): + QTest.qWait(4000) + print(" waiting " + x * ".") + new_inbox = sqlQuery("Select msgid,toaddress,subject from inbox") + self.assertEqual(new_inbox[-1][2], random_subject) + if len(sqlQuery("Select msgid from inbox")) == inbox_length + 1: + print("Test Pass:--> Message Received Successfully") + return 1 + else: + print("Test Fail:--> Doesn't Receive Any Message") + return 0 + else: + print("Test Fail:--> No Address Found") + return 0 + except: + print("Test Fail:--> Message Sending Test Fail") + return 0 + + def copy_clipboard(self): + """Test - Copy Address Book Address to Clipboard""" + print("=====================Test - Copy Address Book Address to Clipboard=====================") + try: + self.popup_menu(1) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.current_address = str(self.treeWidget.item(random.randint(0, self.rand_value), 1).text()) + QTest.qWait(500) + self.myapp.popMenuAddressBook.actions()[1].trigger() + QTest.qWait(1000) + if str(QtGui.QApplication.clipboard().text()) in self.current_address: + print("Test Pass:--> Copy functionality working fine") + return 1 + else: + print("Test Fail:--> Copy functionality failed") + return 0 + except: + print("Test Fail:--> Copy functionality failed") + return 0 + + def subscribe_to_this_address(self): + """Subscribe to This Address""" + print("=====================Test - Subscribe to This Address=====================") + try: + self.popup_menu(2) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.treeWidget.setCurrentCell(self.rand_value, 1) + QTest.qWait(500) + self.myapp.popMenuAddressBook.actions()[2].trigger() + QTest.qWait(750) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + subscription_list = sqlQuery("SELECT address FROM subscriptions") + if self.current_address in subscription_list: + print( + "Test Fail:-->" + "Subscribe to this functionality failed" + " because address is alreay added in the subscription list\n" + ) + return 0 + else: + print("Test Pass:--> Subscribe to this functionality working fine") + return 1 + except: + print("Test Fail:--> Subscribe to this Address failed") + return 0 + + def delete_addressbook(self): + """Delete Address from the Address Book""" + print("=====================Test - Delete Address from the Address Book=====================") + try: + self.popup_menu(7) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.treeWidget.setCurrentCell(self.rand_value, 1) + self.myapp.on_action_AddressBookDelete() + QTest.qWait(500) + addressbook_list = sqlQuery("SELECT address FROM addressbook") + if self.current_address not in addressbook_list: + print("Test Pass:--> Address is Deleted from the AddressBook") + return 1 + else: + print("Test Fail:--> Could not able to Delete this address") + return 0 + except: + print("Test Fail:--> Could Not Able to Delete this Address from the AddressBook") + return 0 + + def popup_menu(self, intval): + QTest.qWait(5) + self.myapp.popMenuAddressBook.setActiveAction(self.myapp.popMenuAddressBook.actions()[intval]) + self.myapp.popMenuAddressBook.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.myapp.popMenuAddressBook.show() + QTest.qWait(400) + self.myapp.popMenuAddressBook.hide() + QTest.qWait(50) + + +class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): + """Subscription TabWidget QTreeWidget popMenu Fucntionality testing""" + + def test_sider(self): + try: + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + QTest.qWait(500) + self.treeWidget = self.myapp.ui.treeWidgetSubscriptions + total_sub = sqlQuery("Select address from subscriptions") + self.levelitem = self.treeWidget.topLevelItem(random.randint(0, len(total_sub) - 1)) + self.treeWidget.setCurrentItem(self.levelitem) + rect = self.treeWidget.visualItemRect(self.levelitem) + self.currentItem = self.myapp.getCurrentItem() + self.myapp.on_context_menuSubscriptions(QtCore.QPoint(rect.x() + 160, rect.y() + 200)) + QTest.qWait(500) + self.myapp.popMenuSubscriptions.hide() + self.new_subscribe() + self.enable_disable() + self.copy_clipboard() + self.send_message_to_this_add() + self.mark_all_as_read() + self.del_address_from_sub() + return 1 + except: + print("Test Fail:--> Subscription Tab PopUpMenu Functionality failed") + return 0 + + def new_subscribe(self): + print("=====================Test - Subscribe to New Address=====================") + try: + if BMConfigParser().addresses(): + self.popup_menu(0) + dialog = dialogs.NewSubscriptionDialog(self.myapp) + QTest.qWait(500) + dialog.lineEditLabel.setText("") + dialog.lineEditAddress.setText("") + dialog.show() + QTest.qWait(500) + random_label = "" + for _ in range(30): + random_label += choice(ascii_lowercase) + dialog.lineEditLabel.setText(random_label) + QTest.qWait(5) + QTest.qWait(500) + rand_address = choice(BMConfigParser().addresses()) + random_address = "" + for x in range(len(rand_address)): + random_address += rand_address[x] + dialog.lineEditAddress.setText(random_address) + QTest.qWait(5) + QtCore.QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + QTest.qWait(500) + try: + address, label = dialog.data + except AttributeError: + print("Test Fail:--> Could Not able to add new address to subscription list") + return 0 + if shared.isAddressInMySubscriptionsList(address): + print( + "MainWindow", + "Error: You cannot add the same address to your subscriptions twice." + " Perhaps rename the existing one if you want.", + ) + self.myapp.updateStatusBar( + _translate( + "MainWindow", + "Error: You cannot add the same address to your subscriptions twice." + " Perhaps rename the existing one if you want.", + ) + ) + return 0 + self.myapp.addSubscription(address, label) + print("Test Pass:--> Address Added to subscription list") + if dialog.checkBoxDisplayMessagesAlreadyInInventory.isChecked(): + for value in dialog.recent: + queues.objectProcessorQueue.put((value.type, value.payload)) + return 1 + else: + print("Test Fail:--> No address found") + return 0 + except: + print("Test Fail:--> New Subscription Functionality Failed") + return 0 + + def enable_disable(self): + """Enable address and disable address""" + print("=====================Test - Address Enable-Disable Functionality=====================") + QTest.qWait(500) + try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + self.treeWidget.setCurrentItem(self.levelitem) + self.popup_menu(3) + if self.currentItem.isEnabled: + QTest.qWait(500) + self.myapp.popMenuSubscriptions.actions()[3].trigger() + QTest.qWait(1000) + self.myapp.on_action_Enable() + QTest.qWait(500) + else: + QTest.qWait(500) + self.myapp.popMenuSubscriptions.actions()[3].trigger() + QTest.qWait(1000) + self.myapp.on_action_Disable() + QTest.qWait(500) + print("Test Pass:--> Enable Disable Working well") + return 0 + except: + print("Test Fail:--> Enable Disable failed") + return 1 + + def copy_clipboard(self): + """Test - Copy Address Book Address to Clipboard""" + print("=====================Test - Copy Address Book Address to Clipboard=====================") + try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + self.treeWidget.setCurrentItem(self.levelitem) + self.popup_menu(6) + QTest.qWait(500) + self.myapp.popMenuSubscriptions.actions()[6].trigger() + QTest.qWait(1000) + if str(QtGui.QApplication.clipboard().text()) in str(self.currentItem.text(0)): + print("Test Pass:--> Copy functionality working fine") + return 1 + else: + print("Test Fail:--> Copy functionality failed") + return 0 + except: + print("Test Fail:--> Copy functionality failed") + return 0 + + def send_message_to_this_add(self): + """Test - Send Message to this Address""" + print("=====================Test - Send Message to this Address=====================") + try: + self.popup_menu(7) + if BMConfigParser().addresses(): + inbox_length = len(sqlQuery("Select msgid from inbox")) + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + self.treeWidget.setCurrentItem(self.levelitem) + self.myapp.popMenuSubscriptions.actions()[7].trigger() + QTest.qWait(500) + random_subject = "" + for x in range(30): + random_subject += choice(ascii_lowercase) + self.myapp.ui.lineEditSubject.setText(random_subject) + QTest.qWait(4) + QTest.qWait(500) + random_message = "" + for x in range(150): + random_message += choice(ascii_lowercase) + self.myapp.ui.textEditMessage.setText(random_message) + QTest.qWait(1) + QTest.qWait(500) + randinteger = random.randrange(1, len(BMConfigParser().addresses()) + 1) + self.myapp.ui.comboBoxSendFrom.setCurrentIndex(randinteger) + QTest.qWait(500) + QTest.mouseClick(self.myapp.ui.pushButtonSend, Qt.LeftButton) + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + print(" Waiting For Message .......................... ") + for x in range(5): + QTest.qWait(4000) + print(" waiting " + x * ".") + new_inbox = sqlQuery("Select msgid,toaddress,subject from inbox") + self.assertEqual(new_inbox[-1][2], random_subject) + if len(sqlQuery("Select msgid from inbox")) == inbox_length + 1: + print("Test Pass:--> Message Received Successfully") + return 1 + else: + print("Test Fail:--> Doesn't Receive Any Message") + return 0 + else: + print("Test Fail:--> No Address Found") + return 0 + except: + print("Test Fail:--> Message Sending Test Fail") + return 0 + + def mark_all_as_read(self): + """Mark all messages as read""" + print("=====================Test - Mark All as Read Functionality=====================") + try: + self.popup_menu(8) + QTest.qWait(550) + self.myapp.popMenuSubscriptions.actions()[8].trigger() + QTest.qWait(750) + print("Test Pass:--> Mark All as Read Functionality Passed") + return 1 + except: + print("Test Fail:--> Mark All as Read Functionality failed") + return 0 + + def del_address_from_sub(self): + print("=====================Test - Delete Address from the subscription Field=====================") + try: + self.popup_menu(1) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + self.treeWidget.setCurrentItem(self.levelitem) + address = self.myapp.getCurrentAccount() + QTest.qWait(750) + sqlExecute("""DELETE FROM subscriptions WHERE address=?""", address) + self.myapp.rerenderTabTreeSubscriptions() + self.myapp.rerenderMessagelistFromLabels() + self.myapp.rerenderAddressBook() + shared.reloadBroadcastSendersForWhichImWatching() + addressbook_list = sqlQuery("SELECT address FROM subscriptions") + if address not in addressbook_list: + print("Test Pass:--> Address is Deleted from the AddressBook") + return 1 + else: + print("Test Fail:--> Could not able to Delete this address") + return 0 + except: + print("Test Fail:--> Could Not Able to Delete this Address from the AddressBook") + return 0 + + def popup_menu(self, intval): + QTest.qWait(5) + self.myapp.popMenuSubscriptions.setActiveAction(self.myapp.popMenuSubscriptions.actions()[intval]) + self.myapp.popMenuSubscriptions.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.myapp.popMenuSubscriptions.show() + QTest.qWait(400) + self.myapp.popMenuSubscriptions.hide() + QTest.qWait(50) + + +class BitmessageTest_BlackWhiteList_PopMenu(BitmessageTestCase): + """Subscription TabWidget QTreeWidget popMenu Fucntionality testing""" + + def test_sider(self): + total_bl = sqlQuery("Select address from blacklist") + if total_bl > 0: + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist + QTest.qWait(500) + self.rand_value = random.randint(0, len(total_bl) - 1) + self.current_address = str(self.tableWidget.item(self.rand_value, 1).text()) + self.tableWidget.setCurrentCell(self.rand_value, 1) + self.tableWidget.item(self.rand_value, 1).setSelected(True) + rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) + QTest.qWait(500) + self.blacklist_obj = blacklist.Blacklist() + self.blacklist_obj.init_blacklist_popup_menu() + self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) + self.blacklist_obj.popMenuBlacklist.show() + QTest.qWait(300) + self.blacklist_obj.popMenuBlacklist.hide() + self.add_delete() + else: + print("Test Fail:--> No black list Found") + return 0 diff --git a/src/graphicaltesting/test_quit.py b/src/graphicaltesting/test_quit.py index 329149e8..d8dd980d 100644 --- a/src/graphicaltesting/test_quit.py +++ b/src/graphicaltesting/test_quit.py @@ -20,6 +20,7 @@ class BitmessageTest_QuitTest(BitmessageTestCase): def test_quitapplication(self): """wait for pow and shutdown the application""" + print("=====================Test - Quitting Application=====================") if self.myapp.quitAccepted and not self.myapp.wait: return diff --git a/src/graphicaltesting/test_settingwindow.py b/src/graphicaltesting/test_settingwindow.py index efc68afd..9e840781 100644 --- a/src/graphicaltesting/test_settingwindow.py +++ b/src/graphicaltesting/test_settingwindow.py @@ -16,22 +16,25 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): def test_settingwindow(self): """Triggers the setting window""" - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) - QTest.qWait(1500) - dialog = dialogs.SettingsDialog(self.myapp, firstrun=self.myapp._firstrun) - self.language_change(dialog) - QTest.qWait(300) - self.eng_convert(dialog) - QTest.qWait(300) - self.network_setting_window(dialog) - QTest.qWait(300) - self.tabresendsexpire_window(dialog) - QTest.qWait(300) + print("=====================Test - Setting Window=====================") + try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) + QTest.qWait(1500) + dialog = dialogs.SettingsDialog(self.myapp, firstrun=self.myapp._firstrun) + self.language_change(dialog) + self.eng_convert(dialog) + self.network_setting_window(dialog) + self.tabresendsexpire_window(dialog) + return 1 + except: + print("Test Fail:-->Setting Window functionality failed") + return 0 def language_change(self, dialog): """Function that changes the language of the application""" + print("=====================Test - Language Change=====================") try: - """Change language""" + QTest.qWait(500) dialog.show() dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) QTest.qWait(800) @@ -42,17 +45,17 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): QTest.qWait(1000) ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) QTest.mouseClick(ok_btn, Qt.LeftButton) - print("\n Test Pass :--> Language Changed Successfully \n") - self.assertTrue(True, " \n Test Pass :--> Language Changed Successfully ") + print("Test Pass:--> Language Changed Successfully") return 1 except: - print("\n Test Fail :--> Error while changing Language! \n") - self.assertTrue(False, " \n Test Fail :--> Error while changing Language!") + print("Test Fail:--> Error while changing Language") return 0 def eng_convert(self, dialog): """Convert any language to english, testing just for good readability""" + print("=====================Test - Converting Language Back to English=====================") try: + QTest.qWait(500) dialog.show() dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) QTest.qWait(800) @@ -63,17 +66,17 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): QTest.qWait(1000) ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) QTest.mouseClick(ok_btn, Qt.LeftButton) - print("\n Test Pass :--> language changed to English Again \n") - self.assertTrue(True, " \n Test Pass :--> language changed to English Again ") + print("Test Pass:--> language changed to English Again") return 1 except: - print("\n Test Fail :--> Not able to change the language to English Again! Error! \n") - self.assertTrue(False, " \n Test Fail :--> Not able to change the language to English Again! Error!") + print("Test Fail:--> Not able to change the language to English Again! Error") return 0 def network_setting_window(self, dialog): """Test for Network setting window""" + print("=====================Test - Network Setting Window=====================") try: + QTest.qWait(500) dialog.show() QTest.qWait(300) dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabNetworkSettings)) @@ -127,17 +130,17 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): QTest.qWait(1200) ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) QTest.mouseClick(ok_btn, Qt.LeftButton) - print("\n Test Pass :--> Successfully tested Network setting window \n") - self.assertTrue(True, " \n Test Pass :--> Successfully tested Network setting window ") + print("Test Pass:--> Successfully tested Network setting window") return 1 except: - print("\n Test Fail :--> Error while testing Network setting window! \n") - self.assertTrue(False, " \n Test Fail :--> Error while testing Network setting window!") + print("Test Fail:--> Error while testing Network setting window") return 0 def tabresendsexpire_window(self, dialog): """Testing for resend expire window""" + print("=====================Test - Tab Resend Expire Window=====================") try: + QTest.qWait(500) dialog.lineEditDays.setText("") dialog.lineEditMonths.setText("") dialog.show() @@ -152,10 +155,8 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): QTest.qWait(800) ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok) QTest.mouseClick(ok_btn, Qt.LeftButton) - print("\n Test Pass :--> Test successfull. \n") - self.assertTrue(True, " \n Test Pass :--> Test successfull. ") + print("Test Pass:--> Test successfull") return 1 except: - print("\n Test Fail :--> Tab Resend Exprire! \n") - self.assertTrue(False, " \n Test Fail :--> Tab Resend Exprire! ") + print("Test Fail:--> Tab Resend Exprire") return 0 diff --git a/src/graphicaltesting/testinitialization.py b/src/graphicaltesting/testinitialization.py index 720ffc6f..b738160e 100644 --- a/src/graphicaltesting/testinitialization.py +++ b/src/graphicaltesting/testinitialization.py @@ -7,9 +7,9 @@ import test_blackwhitelist import test_chans import test_messagesend import test_networkstatus +import test_popupmenu import test_quit import test_settingwindow -import test_inbox_popmenu from testloader import BitmessageTestCase @@ -17,17 +17,31 @@ def test_initialize(myapp): """Inititalizing the test cases""" suite = unittest.TestSuite() suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp)) + BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp) + ) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp)) + BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp) + ) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp)) + BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp) + ) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp)) + BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp) + ) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_chans.BitmessageTest_ChansTest, myapp=myapp)) + suite.addTest(BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_Inbox_PopMenu, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp)) - suite.addTest(BitmessageTestCase.bitmessage_testloader(test_inbox_popmenu.BitmessageTest_Inbox_PopMenu, myapp=myapp)) + BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_AddressBox_PopMenu, myapp=myapp) + ) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_Subscription_PopMenu, myapp=myapp) + ) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_BlackWhiteList_PopMenu, myapp=myapp) + ) + suite.addTest( + BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp) + ) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_quit.BitmessageTest_QuitTest, myapp=myapp)) unittest.TextTestRunner().run(suite) diff --git a/src/gtesting.py b/src/test_qt.py similarity index 50% rename from src/gtesting.py rename to src/test_qt.py index 56099b97..b4a599c2 100644 --- a/src/gtesting.py +++ b/src/test_qt.py @@ -2,11 +2,11 @@ import os import shutil if __name__ == "__main__": - APPNAME = "PyBitmessage" - if os.path.isdir(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))): - shutil.rmtree(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))) - else: - pass + # APPNAME = "PyBitmessage" + # if os.path.isdir(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))): + # shutil.rmtree(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))) + # else: + # pass import state state.qttesting = True print(" --------------------------------- Graphical Qt Testing --------------------------------- ") -- 2.45.1 From 48c9cd73d022e68a75b93e7ea7fe6a01865e3094 Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Mon, 16 Mar 2020 20:13:18 +0530 Subject: [PATCH 5/6] BlackWhitelist popupmenu test added --- .../test_addressgeneration.py | 7 +- src/graphicaltesting/test_addsubscription.py | 6 +- src/graphicaltesting/test_appstart.py | 1 + src/graphicaltesting/test_blackwhitelist.py | 126 ++++----- src/graphicaltesting/test_popupmenu.py | 246 ++++++++++++++---- src/graphicaltesting/test_quit.py | 10 +- src/graphicaltesting/testinitialization.py | 24 +- src/test_qt.py | 10 +- 8 files changed, 285 insertions(+), 145 deletions(-) diff --git a/src/graphicaltesting/test_addressgeneration.py b/src/graphicaltesting/test_addressgeneration.py index e049efe3..e0cd59f8 100644 --- a/src/graphicaltesting/test_addressgeneration.py +++ b/src/graphicaltesting/test_addressgeneration.py @@ -73,15 +73,14 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): QTest.qWait(750) self.assertEqual(random_password1, random_password2) print(" Creating 8 Addresses. Please Wait! ......") - QTest.qWait(2500) + QTest.qWait(3000) print(" Generating ......... ") - QTest.qWait(2500) + QTest.qWait(3000) self.assertEqual(len(BMConfigParser().addresses()), len(bm_addresses) + 8) print("Test Pass:--> Address Generated Successfully with passphrase") return 1 except: print( "Test Fail:--> Address Generatation Failed" - " with passphrase or Taking too much time to generate address" - ) + " with passphrase or Taking too much time to generate address") return 0 diff --git a/src/graphicaltesting/test_addsubscription.py b/src/graphicaltesting/test_addsubscription.py index b4b8bc18..80218728 100644 --- a/src/graphicaltesting/test_addsubscription.py +++ b/src/graphicaltesting/test_addsubscription.py @@ -25,8 +25,7 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) QTest.qWait(500) self.myapp.ui.pushButtonAddSubscription.setStyleSheet( - "QPushButton {background-color: #FF5733; color: white;}" - ) + "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonAddSubscription.setStyleSheet("") dialog = dialogs.NewSubscriptionDialog(self.myapp) @@ -56,8 +55,7 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): if shared.isAddressInMySubscriptionsList(address): print( "Test Fail:--> You cannot add the same address to your subscriptions twice." - " Perhaps rename the existing one if you want" - ) + " Perhaps rename the existing one if you want") QTest.qWait(500) return 0 self.myapp.addSubscription(address, label) diff --git a/src/graphicaltesting/test_appstart.py b/src/graphicaltesting/test_appstart.py index fbb5f742..9b9ba0d9 100644 --- a/src/graphicaltesting/test_appstart.py +++ b/src/graphicaltesting/test_appstart.py @@ -8,3 +8,4 @@ def connectme(dialog): dialog.show() QTest.qWait(1200) QtCore.QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + return 1 diff --git a/src/graphicaltesting/test_blackwhitelist.py b/src/graphicaltesting/test_blackwhitelist.py index 37836c90..f0e728e9 100644 --- a/src/graphicaltesting/test_blackwhitelist.py +++ b/src/graphicaltesting/test_blackwhitelist.py @@ -30,8 +30,7 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): blacklistcount = len(sqlQuery("Select * from blacklist")) self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet( - "QPushButton {background-color: #FF5733; color: white;}" - ) + "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("") self.checkblacklist() @@ -41,8 +40,7 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): whitelistcount = len(sqlQuery("Select * from whitelist")) self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet( - "QPushButton {background-color: #FF5733; color: white;}" - ) + "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("") self.checkblacklist() @@ -59,65 +57,69 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): def checkblacklist(self): # pylint: disable=too-many-statements """fill blacklist and whitelist fields""" - self.dialog.lineEditLabel.setText("") - self.dialog.lineEditAddress.setText("") - QTest.qWait(350) - self.dialog.show() - QTest.qWait(750) - random_label = "" - for _ in range(30): - random_label += choice(ascii_lowercase) - self.dialog.lineEditLabel.setText(random_label) - QTest.qWait(4) - QTest.qWait(500) - rand_address = choice(BMConfigParser().addresses()) - random_address = "" - for i, _ in enumerate(rand_address): - random_address += rand_address[i] - self.dialog.lineEditAddress.setText(random_address) - QTest.qWait(4) - QTest.qWait(500) - QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) - if self.dialog.labelAddressCheck.text() == _translate("MainWindow", "Address is valid."): - address = addBMIfNotPresent(str(self.dialog.lineEditAddress.text())) - t = (address,) - if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": - sql = """select * from blacklist where address=?""" - else: - sql = """select * from whitelist where address=?""" - queryreturn = sqlQuery(sql, *t) - if queryreturn == []: - self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(False) - self.blacklist_obj.tableWidgetBlacklist.insertRow(0) - newItem = QtGui.QTableWidgetItem(unicode(self.dialog.lineEditLabel.text().toUtf8(), "utf-8")) - newItem.setIcon(avatarize(address)) - self.blacklist_obj.tableWidgetBlacklist.setItem(0, 0, newItem) - newItem = QtGui.QTableWidgetItem(address) - newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - self.blacklist_obj.tableWidgetBlacklist.setItem(0, 1, newItem) - self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(True) - t = (str(self.dialog.lineEditLabel.text().toUtf8()), address, True) + try: + self.dialog.lineEditLabel.setText("") + self.dialog.lineEditAddress.setText("") + QTest.qWait(350) + self.dialog.show() + QTest.qWait(750) + random_label = "" + for _ in range(30): + random_label += choice(ascii_lowercase) + self.dialog.lineEditLabel.setText(random_label) + QTest.qWait(4) + QTest.qWait(500) + rand_address = choice(BMConfigParser().addresses()) + random_address = "" + for i, _ in enumerate(rand_address): + random_address += rand_address[i] + self.dialog.lineEditAddress.setText(random_address) + QTest.qWait(4) + QTest.qWait(500) + QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + if self.dialog.labelAddressCheck.text() == _translate("MainWindow", "Address is valid."): + address = addBMIfNotPresent(str(self.dialog.lineEditAddress.text())) + t = (address,) if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": - sql = """INSERT INTO blacklist VALUES (?,?,?)""" - sqlExecute(sql, *t) - black_list_value = sqlQuery("Select address from blacklist where label='" + random_label + "'")[0] - self.assertEqual(black_list_value[0], random_address) - print("Test Pass:--> Address Added to the blacklist") - return 1 + sql = """select * from blacklist where address=?""" else: - sql = """INSERT INTO whitelist VALUES (?,?,?)""" - sqlExecute(sql, *t) - white_list_value = sqlQuery("Select address from whitelist where label='" + random_label + "'")[0] - self.assertEqual(white_list_value[0], random_address) - print("Test Pass:--> Address Added to the whitelist") - return 1 + sql = """select * from whitelist where address=?""" + queryreturn = sqlQuery(sql, *t) + if queryreturn == []: + self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(False) + self.blacklist_obj.tableWidgetBlacklist.insertRow(0) + newItem = QtGui.QTableWidgetItem(unicode(self.dialog.lineEditLabel.text().toUtf8(), "utf-8")) + newItem.setIcon(avatarize(address)) + self.blacklist_obj.tableWidgetBlacklist.setItem(0, 0, newItem) + newItem = QtGui.QTableWidgetItem(address) + newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + self.blacklist_obj.tableWidgetBlacklist.setItem(0, 1, newItem) + self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(True) + t = (str(self.dialog.lineEditLabel.text().toUtf8()), address, True) + if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": + sql = """INSERT INTO blacklist VALUES (?,?,?)""" + sqlExecute(sql, *t) + black_list_value = sqlQuery( + "Select address from blacklist where label='" + random_label + "'")[0] + self.assertEqual(black_list_value[0], random_address) + print("Test Pass:--> Address Added to the blacklist") + return 1 + else: + sql = """INSERT INTO whitelist VALUES (?,?,?)""" + sqlExecute(sql, *t) + white_list_value = sqlQuery( + "Select address from whitelist where label='" + random_label + "'")[0] + self.assertEqual(white_list_value[0], random_address) + print("Test Pass:--> Address Added to the whitelist") + return 1 + else: + print( + "Test Fail:--> You cannot add the same address to your list twice." + "Perhaps rename the existing one if you want") + return 0 else: - print( - "Test Fail:--> You cannot add the same address to your list twice." - "Perhaps rename the existing one if you want" - ) + QTest.qWait(100) + print("Test Fail:--> The address you entered was invalid. Ignoring it") return 0 - else: - QTest.qWait(100) - print("Test Fail:--> The address you entered was invalid. Ignoring it") - return 0 + except: + pass diff --git a/src/graphicaltesting/test_popupmenu.py b/src/graphicaltesting/test_popupmenu.py index 1fd242bd..c4632aea 100644 --- a/src/graphicaltesting/test_popupmenu.py +++ b/src/graphicaltesting/test_popupmenu.py @@ -21,6 +21,7 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): def test_sider(self): """Show QTreeWidget popmenu""" + print("-----------------------------------------------------------1") try: QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) @@ -120,8 +121,7 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): ("".join(choice(ascii_lowercase) for x in range(10))) + "@" + ("".join(choice(ascii_lowercase) for x in range(7))) - + ".com" - ) + + ".com") email_gateway.lineEditEmail.setText(email) QTest.qWait(500) QTest.mouseClick(email_gateway.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) @@ -146,6 +146,7 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): return 0 def popup_menu(self, intval): + """Display popupmenu and clicking action UI""" QTest.qWait(5) self.myapp.popMenuYourIdentities.setActiveAction(self.myapp.popMenuYourIdentities.actions()[intval]) self.myapp.popMenuYourIdentities.setStyleSheet("QMenu:selected {background-color:#FF5733}") @@ -159,13 +160,15 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): """AddressBox TabWidget QTreeWidget popMenu Fucntionality testing""" def test_sider(self): + """Show QTreeWidget popmenu""" + print("-----------------------------------------------------------2") try: QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) self.treeWidget = self.myapp.ui.tableWidgetAddressBook total_sub = sqlQuery("Select address from addressbook") QTest.qWait(500) - self.rand_value = random.randint(0, len(total_sub) - 1) + self.rand_value = random.randint(0, len(total_sub)) self.current_address = str(self.treeWidget.item(self.rand_value, 1).text()) self.treeWidget.setCurrentCell(self.rand_value, 1) self.treeWidget.item(self.rand_value, 1).setSelected(True) @@ -211,15 +214,12 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): if shared.isAddressInMyAddressBook(address): print( " Test :--> You cannot add the same address to your address book twice." - " Try renaming the existing one if you want. \n" - ) + " Try renaming the existing one if you want. \n") self.myapp.updateStatusBar( _translate( "MainWindow", "Error: You cannot add the same address to your adrress book twice." - " Try renaming the existing one if you want.", - ) - ) + " Try renaming the existing one if you want.")) return 0 self.myapp.addEntryToAddressBook(address, label) print("Test Pass:--> Address Added to the Address Book!") @@ -277,12 +277,12 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): return 0 def copy_clipboard(self): - """Test - Copy Address Book Address to Clipboard""" + """Copy Address to the ClipBoard and test whether the copied test is same or not?""" print("=====================Test - Copy Address Book Address to Clipboard=====================") try: self.popup_menu(1) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) - self.current_address = str(self.treeWidget.item(random.randint(0, self.rand_value), 1).text()) + # self.current_address = str(self.treeWidget.item(random.randint(0, self.rand_value), 1).text()) QTest.qWait(500) self.myapp.popMenuAddressBook.actions()[1].trigger() QTest.qWait(1000) @@ -311,20 +311,23 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): if self.current_address in subscription_list: print( "Test Fail:-->" + "Subscribe to this functionality failed" - " because address is alreay added in the subscription list\n" - ) + " because address is alreay added in the subscription list\n") + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) return 0 else: print("Test Pass:--> Subscribe to this functionality working fine") + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) return 1 except: print("Test Fail:--> Subscribe to this Address failed") + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) return 0 def delete_addressbook(self): """Delete Address from the Address Book""" print("=====================Test - Delete Address from the Address Book=====================") try: + QTest.qWait(100) self.popup_menu(7) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) self.treeWidget.setCurrentCell(self.rand_value, 1) @@ -342,6 +345,7 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): return 0 def popup_menu(self, intval): + """Display popupmenu and clicking action UI""" QTest.qWait(5) self.myapp.popMenuAddressBook.setActiveAction(self.myapp.popMenuAddressBook.actions()[intval]) self.myapp.popMenuAddressBook.setStyleSheet("QMenu:selected {background-color:#FF5733}") @@ -355,6 +359,8 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): """Subscription TabWidget QTreeWidget popMenu Fucntionality testing""" def test_sider(self): + """Show QTreeWidget Popup Menu""" + print("-----------------------------------------------------------3") try: QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) @@ -380,8 +386,10 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): return 0 def new_subscribe(self): + """Subscribe to new address""" print("=====================Test - Subscribe to New Address=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) if BMConfigParser().addresses(): self.popup_menu(0) dialog = dialogs.NewSubscriptionDialog(self.myapp) @@ -398,10 +406,10 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): QTest.qWait(500) rand_address = choice(BMConfigParser().addresses()) random_address = "" - for x in range(len(rand_address)): - random_address += rand_address[x] + for i, _ in enumerate(rand_address): + random_address += rand_address[i] dialog.lineEditAddress.setText(random_address) - QTest.qWait(5) + QTest.qWait(4) QtCore.QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) QTest.qWait(500) try: @@ -413,15 +421,12 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): print( "MainWindow", "Error: You cannot add the same address to your subscriptions twice." - " Perhaps rename the existing one if you want.", - ) + " Perhaps rename the existing one if you want.") self.myapp.updateStatusBar( _translate( "MainWindow", "Error: You cannot add the same address to your subscriptions twice." - " Perhaps rename the existing one if you want.", - ) - ) + " Perhaps rename the existing one if you want.")) return 0 self.myapp.addSubscription(address, label) print("Test Pass:--> Address Added to subscription list") @@ -457,13 +462,13 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): self.myapp.on_action_Disable() QTest.qWait(500) print("Test Pass:--> Enable Disable Working well") - return 0 + return 1 except: print("Test Fail:--> Enable Disable failed") - return 1 + return 0 def copy_clipboard(self): - """Test - Copy Address Book Address to Clipboard""" + """Copy Address to the ClipBoard and test whether the copied test is same or not?""" print("=====================Test - Copy Address Book Address to Clipboard=====================") try: self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) @@ -546,6 +551,7 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): return 0 def del_address_from_sub(self): + """Method deletes the address from the subscription""" print("=====================Test - Delete Address from the subscription Field=====================") try: self.popup_menu(1) @@ -570,6 +576,7 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): return 0 def popup_menu(self, intval): + """Display popupmenu and clicking action UI""" QTest.qWait(5) self.myapp.popMenuSubscriptions.setActiveAction(self.myapp.popMenuSubscriptions.actions()[intval]) self.myapp.popMenuSubscriptions.setStyleSheet("QMenu:selected {background-color:#FF5733}") @@ -583,25 +590,176 @@ class BitmessageTest_BlackWhiteList_PopMenu(BitmessageTestCase): """Subscription TabWidget QTreeWidget popMenu Fucntionality testing""" def test_sider(self): - total_bl = sqlQuery("Select address from blacklist") - if total_bl > 0: - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) - self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist - QTest.qWait(500) - self.rand_value = random.randint(0, len(total_bl) - 1) - self.current_address = str(self.tableWidget.item(self.rand_value, 1).text()) - self.tableWidget.setCurrentCell(self.rand_value, 1) - self.tableWidget.item(self.rand_value, 1).setSelected(True) - rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) - QTest.qWait(500) - self.blacklist_obj = blacklist.Blacklist() - self.blacklist_obj.init_blacklist_popup_menu() - self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) - self.blacklist_obj.popMenuBlacklist.show() - QTest.qWait(300) - self.blacklist_obj.popMenuBlacklist.hide() - self.add_delete() - else: - print("Test Fail:--> No black list Found") + """Show QTableWidget Popupmenu""" + print("-----------------------------------------------------------4") + try: + total_bl = sqlQuery("Select address from blacklist") + total_wl = sqlQuery("Select address from whitelist") + if len(total_bl) > 0: + self.blacklist_obj = blacklist.Blacklist() + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() + self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist + QTest.qWait(500) + + self.rand_value = random.randint(0, len(total_bl) - 1) + self.tableWidget.setCurrentCell(self.rand_value, 1) + self.tableWidget.item(self.rand_value, 1).setSelected(True) + rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) + QTest.qWait(500) + + self.blacklist_obj.init_blacklist_popup_menu() + self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) + self.blacklist_obj.popMenuBlacklist.show() + QTest.qWait(300) + self.blacklist_obj.popMenuBlacklist.hide() + self.copy_clipboard() + self.enable_blackwhitelist() + self.disble_blackwhitelist() + self.address_delete() + return 1 + else: + print("Test Fail:--> No White list Found") + return 0 + if len(total_wl) > 0: + self.blacklist_obj = blacklist.Blacklist() + + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() + self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist + QTest.qWait(500) + + self.rand_value = random.randint(0, len(total_wl) - 1) + self.tableWidget.setCurrentCell(self.rand_value, 1) + self.tableWidget.item(self.rand_value, 1).setSelected(True) + rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) + QTest.qWait(500) + + self.blacklist_obj.init_blacklist_popup_menu() + self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) + self.blacklist_obj.popMenuBlacklist.show() + QTest.qWait(300) + self.blacklist_obj.popMenuBlacklist.hide() + + self.copy_clipboard() + self.enable_blackwhitelist() + self.disble_blackwhitelist() + self.address_delete() + return 1 + else: + print("Test Fail:--> No White list Found") + return 0 + except: + print("Test Fail:--> Getting Error while testing on Black/WhiteList Addresses") return 0 + + def address_delete(self): + """Delte address from the Black/WhiteList""" + try: + QTest.qWait(250) + self.popup_menu(0) + self.tableWidget.selectRow(self.rand_value) + currentRow = self.tableWidget.currentRow() + labelAtCurrentRow = self.tableWidget.item(currentRow, 0).text().toUtf8() + addressAtCurrentRow = self.tableWidget.item(currentRow, 1).text() + QTest.qWait(100) + if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": + sqlExecute( + """DELETE FROM blacklist WHERE label=? AND address=?""", + str(labelAtCurrentRow), + str(addressAtCurrentRow)) + print("Test Pass:--> Address deleted from the BlackList") + else: + sqlExecute( + """DELETE FROM whitelist WHERE label=? AND address=?""", + str(labelAtCurrentRow), + str(addressAtCurrentRow)) + print("Test Pass:--> Address deleted from the WhiteList") + self.tableWidget.removeRow(currentRow) + return 1 + except: + print("Test Fail:--> Getting Error while testing on Address Deletion Functionality") + return 0 + + def copy_clipboard(self): + """Copy Address to the ClipBoard and test whether the copied test is same or not?""" + try: + QTest.qWait(250) + self.popup_menu(2) + text_selected = self.tableWidget.item(self.tableWidget.currentRow(), 1).text().toUtf8() + QTest.qWait(500) + currentRow = self.tableWidget.currentRow() + addressAtCurrentRow = self.tableWidget.item(currentRow, 1).text() + clipboard = QtGui.QApplication.clipboard() + clipboard.setText(str(addressAtCurrentRow)) + QTest.qWait(500) + if str(QtGui.QApplication.clipboard().text()) in str(text_selected): + print("Test Pass:--> Copy functionality working fine") + return 1 + else: + print("Test Fail:--> Copy functionality failed") + return 0 + except: + print("Test Fail:--> Getting Error while testing Copy functionality") + return 0 + + def enable_blackwhitelist(self): + """Enables the Black/WhiteList""" + try: + QTest.qWait(250) + self.popup_menu(4) + currentRow = self.tableWidget.currentRow() + addressAtCurrentRow = self.tableWidget.item(currentRow, 1).text() + self.tableWidget.item(currentRow, 0).setTextColor(QtGui.QApplication.palette().text().color()) + self.tableWidget.item(currentRow, 1).setTextColor(QtGui.QApplication.palette().text().color()) + QTest.qWait(500) + if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": + QTest.qWait(500) + sqlExecute("""UPDATE blacklist SET enabled=1 WHERE address=?""", str(addressAtCurrentRow)) + print("Test Pass:--> Enabled the Blacklist address") + else: + QTest.qWait(500) + sqlExecute("""UPDATE whitelist SET enabled=1 WHERE address=?""", str(addressAtCurrentRow)) + print("Test Pass:--> Enabled the Whitelist address") + return 1 + except: + print("Test Fail:--> Getting Error while testing Enable Functionality") + return 0 + + def disble_blackwhitelist(self): + """Disables the Black/WhiteList""" + try: + QTest.qWait(250) + self.popup_menu(5) + currentRow = self.tableWidget.currentRow() + addressAtCurrentRow = self.tableWidget.item(currentRow, 1).text() + self.tableWidget.item(currentRow, 0).setTextColor(QtGui.QColor(128, 128, 128)) + self.tableWidget.item(currentRow, 1).setTextColor(QtGui.QColor(128, 128, 128)) + QTest.qWait(500) + if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": + QTest.qWait(500) + sqlExecute("""UPDATE blacklist SET enabled=0 WHERE address=?""", str(addressAtCurrentRow)) + print("Test Pass:--> Disabled the Blacklist address") + else: + QTest.qWait(500) + sqlExecute("""UPDATE whitelist SET enabled=0 WHERE address=?""", str(addressAtCurrentRow)) + print("Test Pass:--> Disabled the Blacklist address") + return 1 + except: + print("Test Fail:--> Getting Error while testing Disable Functionality") + return 0 + + def popup_menu(self, intval): + """Display popupmenu and clicking action UI""" + try: + QTest.qWait(5) + self.blacklist_obj.popMenuBlacklist.setActiveAction(self.blacklist_obj.popMenuBlacklist.actions()[intval]) + self.blacklist_obj.popMenuBlacklist.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.blacklist_obj.popMenuBlacklist.show() + QTest.qWait(400) + self.blacklist_obj.popMenuBlacklist.hide() + QTest.qWait(50) + except: + pass diff --git a/src/graphicaltesting/test_quit.py b/src/graphicaltesting/test_quit.py index d8dd980d..5ca24b33 100644 --- a/src/graphicaltesting/test_quit.py +++ b/src/graphicaltesting/test_quit.py @@ -62,9 +62,7 @@ class BitmessageTest_QuitTest(BitmessageTestCase): if curWorkerQueue > 0: self.myapp.updateStatusBar( _translate("MainWindow", "Waiting for PoW to finish... %1%").arg( - 50 * (maxWorkerQueue - curWorkerQueue) / maxWorkerQueue - ) - ) + 50 * (maxWorkerQueue - curWorkerQueue) / maxWorkerQueue)) time.sleep(0.5) QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down Pybitmessage... %1%").arg(50)) @@ -77,9 +75,7 @@ class BitmessageTest_QuitTest(BitmessageTestCase): while pendingUpload() > 1: self.myapp.updateStatusBar( _translate("MainWindow", "Waiting for objects to be sent... %1%").arg( - int(50 + 20 * (pendingUpload() / maxPendingUpload)) - ) - ) + int(50 + 20 * (pendingUpload() / maxPendingUpload)))) time.sleep(0.5) QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) @@ -87,7 +83,7 @@ class BitmessageTest_QuitTest(BitmessageTestCase): self.myapp.updateStatusBar(_translate("MainWindow", "Saving settings... %1%").arg(70)) QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) self.myapp.saveSettings() - for attr, obj in self.myapp.ui.__dict__.iteritems(): + for _, obj in self.myapp.ui.__dict__.iteritems(): if hasattr(obj, "__class__") and isinstance(obj, settingsmixin.SettingsMixin): saveMethod = getattr(obj, "saveSettings", None) if callable(saveMethod): diff --git a/src/graphicaltesting/testinitialization.py b/src/graphicaltesting/testinitialization.py index b738160e..6f01adc4 100644 --- a/src/graphicaltesting/testinitialization.py +++ b/src/graphicaltesting/testinitialization.py @@ -17,31 +17,23 @@ def test_initialize(myapp): """Inititalizing the test cases""" suite = unittest.TestSuite() suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_addressgeneration.BitmessageTest_AddressGeneration, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_messagesend.BitmessageTest_MessageTesting, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_addsubscription.BitmessageTest_AddSubscription, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_networkstatus.BitmessageTest_NetworkTest, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_blackwhitelist.BitmessageTest_BlackandWhiteList, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_chans.BitmessageTest_ChansTest, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_Inbox_PopMenu, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_AddressBox_PopMenu, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_AddressBox_PopMenu, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_Subscription_PopMenu, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_Subscription_PopMenu, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_BlackWhiteList_PopMenu, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_popupmenu.BitmessageTest_BlackWhiteList_PopMenu, myapp=myapp)) suite.addTest( - BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp) - ) + BitmessageTestCase.bitmessage_testloader(test_settingwindow.BitmessageTest_SettingWindowTest, myapp=myapp)) suite.addTest(BitmessageTestCase.bitmessage_testloader(test_quit.BitmessageTest_QuitTest, myapp=myapp)) unittest.TextTestRunner().run(suite) diff --git a/src/test_qt.py b/src/test_qt.py index b4a599c2..e3292c5d 100644 --- a/src/test_qt.py +++ b/src/test_qt.py @@ -1,14 +1,8 @@ -import os -import shutil +import state if __name__ == "__main__": - # APPNAME = "PyBitmessage" - # if os.path.isdir(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))): - # shutil.rmtree(os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))) - # else: - # pass - import state state.qttesting = True print(" --------------------------------- Graphical Qt Testing --------------------------------- ") from bitmessagemain import main + main() -- 2.45.1 From 288fb35c470c1f709cd8b46cc3e59b3c97a4a5c1 Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Tue, 17 Mar 2020 21:18:05 +0530 Subject: [PATCH 6/6] code fixes --- .../test_addressgeneration.py | 28 ++- src/graphicaltesting/test_addsubscription.py | 5 +- src/graphicaltesting/test_blackwhitelist.py | 47 ++-- src/graphicaltesting/test_messagesend.py | 4 +- src/graphicaltesting/test_popupmenu.py | 235 +++++++++++------- src/graphicaltesting/test_quit.py | 107 ++++---- src/graphicaltesting/test_settingwindow.py | 57 +++-- 7 files changed, 292 insertions(+), 191 deletions(-) diff --git a/src/graphicaltesting/test_addressgeneration.py b/src/graphicaltesting/test_addressgeneration.py index e0cd59f8..e0d0089f 100644 --- a/src/graphicaltesting/test_addressgeneration.py +++ b/src/graphicaltesting/test_addressgeneration.py @@ -13,50 +13,60 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): """Testing Environment""" def test_generateaddress(self): - """Method clicks on new label pushbutton and create new address with random label""" + """Method clicks on pushbutton and create new address with random label""" print("=====================Test - Generating Address=====================") try: QTest.qWait(500) bm_addresses = BMConfigParser().addresses() self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) QTest.qWait(500) - self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") + + self.myapp.ui.pushButtonNewAddress.setStyleSheet( + "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonNewAddress.setStyleSheet("") label_gen_obj = address_dialogs.NewAddressDialog() QTest.qWait(750) + random_label = "" for _ in range(15): random_label += choice(ascii_lowercase) label_gen_obj.newaddresslabel.setText(random_label) QTest.qWait(4) + QTest.qWait(500) label_gen_obj.accept() QTest.qWait(750) new_bm_addresses = BMConfigParser().addresses() self.assertEqual(len(new_bm_addresses), len(bm_addresses) + 1) - self.assertEqual(str(BMConfigParser().get(new_bm_addresses[-1], "label")), random_label) + self.assertEqual( + str(BMConfigParser().get(new_bm_addresses[-1], "label")), random_label) print("Test Pass:--> Address Generated Successfully") return 1 # if every thing is ok except: - print("Test Fail:--> Address Generatation Failed or Taking too much time to generate address") + print( + "Test Fail:--> Address Generatation Failed or Taking too much time to generate address") return 0 # if test fail def test_generateaddresswithpassphrase(self): """Clicks on the create new label with passphrase pushbutton and generates 8 address""" - print("=====================Test - Generating Address with passphrase=====================") + print( + "=====================Test - Generating Address with passphrase=====================") try: QTest.qWait(500) bm_addresses = BMConfigParser().addresses() self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) QTest.qWait(500) - self.myapp.ui.pushButtonNewAddress.setStyleSheet("QPushButton {background-color: #FF5733; color: white;}") + + self.myapp.ui.pushButtonNewAddress.setStyleSheet( + "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.pushButtonNewAddress.setStyleSheet("") label_gen_obj = address_dialogs.NewAddressDialog() QTest.qWait(750) label_gen_obj.radioButtonDeterministicAddress.click() QTest.qWait(250) + random_password1 = "" for _ in range(15): random_password1 += choice(ascii_lowercase) @@ -68,10 +78,12 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): random_password2 += i label_gen_obj.lineEditPassphraseAgain.setText(random_password2) QTest.qWait(2) + QTest.qWait(500) label_gen_obj.accept() QTest.qWait(750) self.assertEqual(random_password1, random_password2) + print(" Creating 8 Addresses. Please Wait! ......") QTest.qWait(3000) print(" Generating ......... ") @@ -81,6 +93,6 @@ class BitmessageTest_AddressGeneration(BitmessageTestCase): return 1 except: print( - "Test Fail:--> Address Generatation Failed" - " with passphrase or Taking too much time to generate address") + "Test Fail:--> Address Generatation Failed with passphrase" + " or Taking too much time to generate address") return 0 diff --git a/src/graphicaltesting/test_addsubscription.py b/src/graphicaltesting/test_addsubscription.py index 80218728..2828055b 100644 --- a/src/graphicaltesting/test_addsubscription.py +++ b/src/graphicaltesting/test_addsubscription.py @@ -31,6 +31,7 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): dialog = dialogs.NewSubscriptionDialog(self.myapp) dialog.show() QTest.qWait(750) + random_label = "" for _ in range(30): random_label += choice(ascii_lowercase) @@ -45,6 +46,7 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): QTest.qWait(4) QTest.qWait(500) QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + try: QTest.qWait(800) address, label = dialog.data @@ -59,7 +61,8 @@ class BitmessageTest_AddSubscription(BitmessageTestCase): QTest.qWait(500) return 0 self.myapp.addSubscription(address, label) - sub_add = sqlQuery("select address from subscriptions where label='" + random_label + "'")[0] + sub_add = sqlQuery( + "select address from subscriptions where label='" + random_label + "'")[0] self.assertEqual(random_address, sub_add[0]) print("Test Pass:--> Subscription Done Successfully") return 1 diff --git a/src/graphicaltesting/test_blackwhitelist.py b/src/graphicaltesting/test_blackwhitelist.py index f0e728e9..dc3ea25a 100644 --- a/src/graphicaltesting/test_blackwhitelist.py +++ b/src/graphicaltesting/test_blackwhitelist.py @@ -17,6 +17,7 @@ from tr import _translate class BitmessageTest_BlackandWhiteList(BitmessageTestCase): """Blacklist and Whitelist address add functionality tests""" + # pylint: disable=attribute-defined-outside-init def test_blackwhitelist(self): """Tab switch to blacklist and add the address on blacklist and whitelist""" @@ -26,6 +27,7 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) QTest.qWait(500) + self.dialog = AddAddressDialog(self.myapp) blacklistcount = len(sqlQuery("Select * from blacklist")) self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() @@ -33,7 +35,7 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("") - self.checkblacklist() + self.blackwhitelist_autofill() self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() QTest.qWait(500) @@ -43,40 +45,46 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): "QPushButton {background-color: #FF5733; color: white;}") QTest.qWait(50) self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("") - self.checkblacklist() + self.blackwhitelist_autofill() self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() QTest.qWait(500) self.assertEqual(blacklistcount + 1, len(sqlQuery("Select * from blacklist"))) self.assertEqual(whitelistcount + 1, len(sqlQuery("Select * from whitelist"))) - print("Black/WhiteList Functionality Tested Successfully") - return 1 except: - print("Black/WhiteList Functionality Failed") return 0 - def checkblacklist(self): # pylint: disable=too-many-statements - """fill blacklist and whitelist fields""" + def blackwhitelist_autofill(self): + """Auto fills the blackwhitelist fields""" try: self.dialog.lineEditLabel.setText("") self.dialog.lineEditAddress.setText("") QTest.qWait(350) self.dialog.show() QTest.qWait(750) - random_label = "" + self.random_label = "" for _ in range(30): - random_label += choice(ascii_lowercase) - self.dialog.lineEditLabel.setText(random_label) + self.random_label += choice(ascii_lowercase) + self.dialog.lineEditLabel.setText(self.random_label) QTest.qWait(4) QTest.qWait(500) rand_address = choice(BMConfigParser().addresses()) - random_address = "" + self.random_address = "" for i, _ in enumerate(rand_address): - random_address += rand_address[i] - self.dialog.lineEditAddress.setText(random_address) + self.random_address += rand_address[i] + self.dialog.lineEditAddress.setText(self.random_address) QTest.qWait(4) QTest.qWait(500) - QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + QtCore.QTimer.singleShot( + 0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + self.blacklist_test() + except: + pass + + def blacklist_test(self): + """fill blacklist and whitelist fields""" + # pylint: disable=no-else-return + try: if self.dialog.labelAddressCheck.text() == _translate("MainWindow", "Address is valid."): address = addBMIfNotPresent(str(self.dialog.lineEditAddress.text())) t = (address,) @@ -88,7 +96,8 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): if queryreturn == []: self.blacklist_obj.tableWidgetBlacklist.setSortingEnabled(False) self.blacklist_obj.tableWidgetBlacklist.insertRow(0) - newItem = QtGui.QTableWidgetItem(unicode(self.dialog.lineEditLabel.text().toUtf8(), "utf-8")) + newItem = QtGui.QTableWidgetItem( + unicode(self.dialog.lineEditLabel.text().toUtf8(), "utf-8")) newItem.setIcon(avatarize(address)) self.blacklist_obj.tableWidgetBlacklist.setItem(0, 0, newItem) newItem = QtGui.QTableWidgetItem(address) @@ -100,16 +109,16 @@ class BitmessageTest_BlackandWhiteList(BitmessageTestCase): sql = """INSERT INTO blacklist VALUES (?,?,?)""" sqlExecute(sql, *t) black_list_value = sqlQuery( - "Select address from blacklist where label='" + random_label + "'")[0] - self.assertEqual(black_list_value[0], random_address) + "Select address from blacklist where label='" + self.random_label + "'")[0] + self.assertEqual(black_list_value[0], self.random_address) print("Test Pass:--> Address Added to the blacklist") return 1 else: sql = """INSERT INTO whitelist VALUES (?,?,?)""" sqlExecute(sql, *t) white_list_value = sqlQuery( - "Select address from whitelist where label='" + random_label + "'")[0] - self.assertEqual(white_list_value[0], random_address) + "Select address from whitelist where label='" + self.random_label + "'")[0] + self.assertEqual(white_list_value[0], self.random_address) print("Test Pass:--> Address Added to the whitelist") return 1 else: diff --git a/src/graphicaltesting/test_messagesend.py b/src/graphicaltesting/test_messagesend.py index 41833ea4..479f5767 100644 --- a/src/graphicaltesting/test_messagesend.py +++ b/src/graphicaltesting/test_messagesend.py @@ -13,10 +13,12 @@ from testloader import BitmessageTestCase class BitmessageTest_MessageTesting(BitmessageTestCase): """Test Message Sending functionality""" + # pylint: disable= no-else-return def test_msgsend(self): """Auto-fill senders address, receivers address, subject and message and sends the message""" - print("=====================Test - Message Send/Receive Functionality=====================") + print( + "=====================Test - Message Send/Receive Functionality=====================") try: if BMConfigParser().addresses(): inbox_length = len(sqlQuery("Select msgid from inbox")) diff --git a/src/graphicaltesting/test_popupmenu.py b/src/graphicaltesting/test_popupmenu.py index c4632aea..c9a83015 100644 --- a/src/graphicaltesting/test_popupmenu.py +++ b/src/graphicaltesting/test_popupmenu.py @@ -15,6 +15,8 @@ from helper_sql import sqlExecute, sqlQuery from testloader import BitmessageTestCase from tr import _translate +# pylint: disable=no-else-return, inconsistent-return-statements, attribute-defined-outside-init + class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): """Inbox TabWidget QTreeWidget popMenu Fucntionality testing""" @@ -27,11 +29,13 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) QTest.qWait(500) self.treeWidget = self.myapp.ui.treeWidgetYourIdentities - self.levelitem = self.treeWidget.topLevelItem(random.randint(1, len(BMConfigParser().addresses()) + 1)) + self.levelitem = self.treeWidget.topLevelItem( + random.randint(1, len(BMConfigParser().addresses()) + 1)) self.treeWidget.setCurrentItem(self.levelitem) self.currentItem = self.myapp.getCurrentItem() self.rect = self.treeWidget.visualItemRect(self.levelitem) - self.myapp.on_context_menuYourIdentities(QtCore.QPoint(self.rect.x() + 160, self.rect.y() + 200)) + self.myapp.on_context_menuYourIdentities( + QtCore.QPoint(self.rect.x() + 160, self.rect.y() + 200)) self.myapp.popMenuYourIdentities.hide() self.copy_clipboard() self.enable_disable() @@ -47,6 +51,7 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): """Copy Address to the ClipBoard and test whether the copied test is same or not?""" print("=====================Test - Copy Address to the ClipBoard=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) self.popup_menu(2) text_selected = self.currentItem.text(0) QTest.qWait(500) @@ -64,8 +69,10 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): def enable_disable(self): """Enable address and disable address""" - print("=====================Test - Address Enable-Disable Functionality=====================") + print( + "=====================Test - Address Enable-Disable Functionality=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) self.popup_menu(4) if self.currentItem.isEnabled: QTest.qWait(500) @@ -91,15 +98,18 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): """Tests for special address""" print("=====================Test - Address Special Behavior=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) self.popup_menu(6) special_add = dialogs.SpecialAddressBehaviorDialog(self.myapp, BMConfigParser()) special_add.lineEditMailingListName.setText("") QTest.qWait(500) special_add.radioButtonBehaviorMailingList.click() QTest.qWait(1000) - special_add.lineEditMailingListName.setText("".join(choice(ascii_lowercase) for x in range(15))) + special_add.lineEditMailingListName.setText( + "".join(choice(ascii_lowercase) for x in range(15))) QTest.qWait(500) - QTest.mouseClick(special_add.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) + QTest.mouseClick( + special_add.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) print("Test Pass:--> Special Address Behavior Functionality Passed") return 1 except: @@ -110,6 +120,7 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): """Test email gateway functionality""" print("=====================Test - Email Gateway=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) self.popup_menu(7) QTest.qWait(200) email_gateway = dialogs.EmailGatewayDialog(self.myapp, BMConfigParser()) @@ -124,7 +135,8 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): + ".com") email_gateway.lineEditEmail.setText(email) QTest.qWait(500) - QTest.mouseClick(email_gateway.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) + QTest.mouseClick( + email_gateway.buttonBox.button(QtGui.QDialogButtonBox.Ok), Qt.LeftButton) print("Test Pass:--> Email-Gateway Functionality Passed") return 1 except: @@ -135,6 +147,7 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): """Mark all messages as read""" print("=====================Test - Mark All as Read Functionality=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) self.popup_menu(11) QTest.qWait(500) self.myapp.popMenuYourIdentities.actions()[11].trigger() @@ -148,8 +161,10 @@ class BitmessageTest_Inbox_PopMenu(BitmessageTestCase): def popup_menu(self, intval): """Display popupmenu and clicking action UI""" QTest.qWait(5) - self.myapp.popMenuYourIdentities.setActiveAction(self.myapp.popMenuYourIdentities.actions()[intval]) - self.myapp.popMenuYourIdentities.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.myapp.popMenuYourIdentities.setActiveAction( + self.myapp.popMenuYourIdentities.actions()[intval]) + self.myapp.popMenuYourIdentities.setStyleSheet( + "QMenu:selected {background-color: #FF5733; color: white;}") self.myapp.popMenuYourIdentities.show() QTest.qWait(400) self.myapp.popMenuYourIdentities.hide() @@ -163,8 +178,8 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): """Show QTreeWidget popmenu""" print("-----------------------------------------------------------2") try: - QTest.qWait(500) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + QTest.qWait(500) self.treeWidget = self.myapp.ui.tableWidgetAddressBook total_sub = sqlQuery("Select address from addressbook") QTest.qWait(500) @@ -176,7 +191,7 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): QTest.qWait(500) self.myapp.on_context_menuAddressBook(QtCore.QPoint(rect.x() + 160, rect.y() + 200)) QTest.qWait(500) - if len(total_sub) > 0: + if total_sub: self.treeWidget.item(random.randint(0, self.rand_value), 1) else: print("No Address Found.") @@ -193,10 +208,11 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): def add_new_address(self): """Adding New Address to Address Book""" - print("=====================Test - Adding New Address to Address Book=====================") + print( + "=====================Test - Adding New Address to Address Book=====================") try: - self.popup_menu(6) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.popup_menu(6) self.dialog = dialogs.AddAddressDialog(self.myapp) self.dialog.show() QTest.qWait(500) @@ -204,7 +220,8 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): QTest.qWait(500) self.dialog.lineEditAddress.setText(choice(BMConfigParser().addresses())) QTest.qWait(500) - QtCore.QTimer.singleShot(0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + QtCore.QTimer.singleShot( + 0, self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) QTest.qWait(500) try: address, label = self.dialog.data @@ -232,6 +249,7 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): """Test - Send Message to this Address""" print("=====================Test - Send Message to this Address=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) self.popup_menu(0) if BMConfigParser().addresses(): self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) @@ -278,10 +296,11 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): def copy_clipboard(self): """Copy Address to the ClipBoard and test whether the copied test is same or not?""" - print("=====================Test - Copy Address Book Address to Clipboard=====================") + print( + "=====================Test - Copy Address Book Address to Clipboard=====================") try: - self.popup_menu(1) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.popup_menu(1) # self.current_address = str(self.treeWidget.item(random.randint(0, self.rand_value), 1).text()) QTest.qWait(500) self.myapp.popMenuAddressBook.actions()[1].trigger() @@ -300,8 +319,8 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): """Subscribe to This Address""" print("=====================Test - Subscribe to This Address=====================") try: - self.popup_menu(2) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.popup_menu(2) self.treeWidget.setCurrentCell(self.rand_value, 1) QTest.qWait(500) self.myapp.popMenuAddressBook.actions()[2].trigger() @@ -325,11 +344,12 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): def delete_addressbook(self): """Delete Address from the Address Book""" - print("=====================Test - Delete Address from the Address Book=====================") + print( + "=====================Test - Delete Address from the Address Book=====================") try: QTest.qWait(100) - self.popup_menu(7) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send) + self.popup_menu(7) self.treeWidget.setCurrentCell(self.rand_value, 1) self.myapp.on_action_AddressBookDelete() QTest.qWait(500) @@ -347,8 +367,10 @@ class BitmessageTest_AddressBox_PopMenu(BitmessageTestCase): def popup_menu(self, intval): """Display popupmenu and clicking action UI""" QTest.qWait(5) - self.myapp.popMenuAddressBook.setActiveAction(self.myapp.popMenuAddressBook.actions()[intval]) - self.myapp.popMenuAddressBook.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.myapp.popMenuAddressBook.setActiveAction( + self.myapp.popMenuAddressBook.actions()[intval]) + self.myapp.popMenuAddressBook.setStyleSheet( + "QMenu:selected {background-color: #FF5733; color: white;}") self.myapp.popMenuAddressBook.show() QTest.qWait(400) self.myapp.popMenuAddressBook.hide() @@ -410,7 +432,8 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): random_address += rand_address[i] dialog.lineEditAddress.setText(random_address) QTest.qWait(4) - QtCore.QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) + QtCore.QTimer.singleShot( + 0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked) QTest.qWait(500) try: address, label = dialog.data @@ -421,7 +444,7 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): print( "MainWindow", "Error: You cannot add the same address to your subscriptions twice." - " Perhaps rename the existing one if you want.") + " Perhaps rename the existing one if you want.",) self.myapp.updateStatusBar( _translate( "MainWindow", @@ -443,7 +466,8 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): def enable_disable(self): """Enable address and disable address""" - print("=====================Test - Address Enable-Disable Functionality=====================") + print( + "=====================Test - Address Enable-Disable Functionality=====================") QTest.qWait(500) try: self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) @@ -469,7 +493,8 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): def copy_clipboard(self): """Copy Address to the ClipBoard and test whether the copied test is same or not?""" - print("=====================Test - Copy Address Book Address to Clipboard=====================") + print( + "=====================Test - Copy Address Book Address to Clipboard=====================") try: self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) self.treeWidget.setCurrentItem(self.levelitem) @@ -491,6 +516,7 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): """Test - Send Message to this Address""" print("=====================Test - Send Message to this Address=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) self.popup_menu(7) if BMConfigParser().addresses(): inbox_length = len(sqlQuery("Select msgid from inbox")) @@ -540,6 +566,7 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): """Mark all messages as read""" print("=====================Test - Mark All as Read Functionality=====================") try: + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) self.popup_menu(8) QTest.qWait(550) self.myapp.popMenuSubscriptions.actions()[8].trigger() @@ -552,10 +579,11 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): def del_address_from_sub(self): """Method deletes the address from the subscription""" - print("=====================Test - Delete Address from the subscription Field=====================") + print( + "=====================Test - Delete Address from the subscription Field=====================") try: - self.popup_menu(1) self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions) + self.popup_menu(1) self.treeWidget.setCurrentItem(self.levelitem) address = self.myapp.getCurrentAccount() QTest.qWait(750) @@ -578,8 +606,10 @@ class BitmessageTest_Subscription_PopMenu(BitmessageTestCase): def popup_menu(self, intval): """Display popupmenu and clicking action UI""" QTest.qWait(5) - self.myapp.popMenuSubscriptions.setActiveAction(self.myapp.popMenuSubscriptions.actions()[intval]) - self.myapp.popMenuSubscriptions.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.myapp.popMenuSubscriptions.setActiveAction( + self.myapp.popMenuSubscriptions.actions()[intval]) + self.myapp.popMenuSubscriptions.setStyleSheet( + "QMenu:selected {background-color: #FF5733; color: white;}") self.myapp.popMenuSubscriptions.show() QTest.qWait(400) self.myapp.popMenuSubscriptions.hide() @@ -593,68 +623,77 @@ class BitmessageTest_BlackWhiteList_PopMenu(BitmessageTestCase): """Show QTableWidget Popupmenu""" print("-----------------------------------------------------------4") try: - total_bl = sqlQuery("Select address from blacklist") - total_wl = sqlQuery("Select address from whitelist") - if len(total_bl) > 0: - self.blacklist_obj = blacklist.Blacklist() - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) - self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() - self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist - QTest.qWait(500) - - self.rand_value = random.randint(0, len(total_bl) - 1) - self.tableWidget.setCurrentCell(self.rand_value, 1) - self.tableWidget.item(self.rand_value, 1).setSelected(True) - rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) - QTest.qWait(500) - - self.blacklist_obj.init_blacklist_popup_menu() - self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) - self.blacklist_obj.popMenuBlacklist.show() - QTest.qWait(300) - self.blacklist_obj.popMenuBlacklist.hide() - self.copy_clipboard() - self.enable_blackwhitelist() - self.disble_blackwhitelist() - self.address_delete() - return 1 - else: - print("Test Fail:--> No White list Found") - return 0 - if len(total_wl) > 0: - self.blacklist_obj = blacklist.Blacklist() - - QTest.qWait(500) - self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) - self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() - self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist - QTest.qWait(500) - - self.rand_value = random.randint(0, len(total_wl) - 1) - self.tableWidget.setCurrentCell(self.rand_value, 1) - self.tableWidget.item(self.rand_value, 1).setSelected(True) - rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) - QTest.qWait(500) - - self.blacklist_obj.init_blacklist_popup_menu() - self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) - self.blacklist_obj.popMenuBlacklist.show() - QTest.qWait(300) - self.blacklist_obj.popMenuBlacklist.hide() - - self.copy_clipboard() - self.enable_blackwhitelist() - self.disble_blackwhitelist() - self.address_delete() - return 1 - else: - print("Test Fail:--> No White list Found") - return 0 + self.total_bl = sqlQuery("Select address from blacklist") + self.total_wl = sqlQuery("Select address from whitelist") + if self.total_bl: + self.trigger_blacklist_test() + if self.total_wl: + self.trigger_whitelist_test() except: print("Test Fail:--> Getting Error while testing on Black/WhiteList Addresses") return 0 + def trigger_blacklist_test(self): + """Triggers blacklist test cases""" + try: + self.blacklist_obj = blacklist.Blacklist() + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + self.myapp.ui.blackwhitelist.radioButtonBlacklist.click() + self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist + QTest.qWait(500) + + self.rand_value = random.randint(0, len(self.total_bl) - 1) + self.tableWidget.setCurrentCell(self.rand_value, 1) + self.tableWidget.item(self.rand_value, 1).setSelected(True) + rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) + QTest.qWait(500) + + self.blacklist_obj.init_blacklist_popup_menu() + self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) + self.blacklist_obj.popMenuBlacklist.show() + QTest.qWait(300) + self.blacklist_obj.popMenuBlacklist.hide() + self.copy_clipboard() + self.enable_blackwhitelist() + self.disble_blackwhitelist() + self.address_delete() + return 1 + except: + print("Test Fail:--> Getting Error While Testing Blacklist") + return 0 + + def trigger_whitelist_test(self): + """Triggers whitelist test cases""" + try: + self.blacklist_obj = blacklist.Blacklist() + QTest.qWait(500) + self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.blackwhitelist) + self.myapp.ui.blackwhitelist.radioButtonWhitelist.click() + self.tableWidget = self.myapp.ui.blackwhitelist.tableWidgetBlacklist + QTest.qWait(500) + + self.rand_value = random.randint(0, len(self.total_wl) - 1) + self.tableWidget.setCurrentCell(self.rand_value, 1) + self.tableWidget.item(self.rand_value, 1).setSelected(True) + rect = self.tableWidget.visualItemRect(self.tableWidget.item(self.rand_value, 1)) + QTest.qWait(500) + + self.blacklist_obj.init_blacklist_popup_menu() + self.blacklist_obj.popMenuBlacklist.move(QtCore.QPoint(rect.x(), rect.y() + 290)) + self.blacklist_obj.popMenuBlacklist.show() + QTest.qWait(300) + self.blacklist_obj.popMenuBlacklist.hide() + + self.copy_clipboard() + self.enable_blackwhitelist() + self.disble_blackwhitelist() + self.address_delete() + return 1 + except: + print("Test Fail:--> Getting Error While Testing WhiteList") + return 0 + def address_delete(self): """Delte address from the Black/WhiteList""" try: @@ -712,16 +751,20 @@ class BitmessageTest_BlackWhiteList_PopMenu(BitmessageTestCase): self.popup_menu(4) currentRow = self.tableWidget.currentRow() addressAtCurrentRow = self.tableWidget.item(currentRow, 1).text() - self.tableWidget.item(currentRow, 0).setTextColor(QtGui.QApplication.palette().text().color()) - self.tableWidget.item(currentRow, 1).setTextColor(QtGui.QApplication.palette().text().color()) + self.tableWidget.item(currentRow, 0).setTextColor( + QtGui.QApplication.palette().text().color()) + self.tableWidget.item(currentRow, 1).setTextColor( + QtGui.QApplication.palette().text().color()) QTest.qWait(500) if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": QTest.qWait(500) - sqlExecute("""UPDATE blacklist SET enabled=1 WHERE address=?""", str(addressAtCurrentRow)) + sqlExecute( + """UPDATE blacklist SET enabled=1 WHERE address=?""", str(addressAtCurrentRow)) print("Test Pass:--> Enabled the Blacklist address") else: QTest.qWait(500) - sqlExecute("""UPDATE whitelist SET enabled=1 WHERE address=?""", str(addressAtCurrentRow)) + sqlExecute( + """UPDATE whitelist SET enabled=1 WHERE address=?""", str(addressAtCurrentRow)) print("Test Pass:--> Enabled the Whitelist address") return 1 except: @@ -740,11 +783,13 @@ class BitmessageTest_BlackWhiteList_PopMenu(BitmessageTestCase): QTest.qWait(500) if BMConfigParser().get("bitmessagesettings", "blackwhitelist") == "black": QTest.qWait(500) - sqlExecute("""UPDATE blacklist SET enabled=0 WHERE address=?""", str(addressAtCurrentRow)) + sqlExecute( + """UPDATE blacklist SET enabled=0 WHERE address=?""", str(addressAtCurrentRow)) print("Test Pass:--> Disabled the Blacklist address") else: QTest.qWait(500) - sqlExecute("""UPDATE whitelist SET enabled=0 WHERE address=?""", str(addressAtCurrentRow)) + sqlExecute( + """UPDATE whitelist SET enabled=0 WHERE address=?""", str(addressAtCurrentRow)) print("Test Pass:--> Disabled the Blacklist address") return 1 except: @@ -755,8 +800,10 @@ class BitmessageTest_BlackWhiteList_PopMenu(BitmessageTestCase): """Display popupmenu and clicking action UI""" try: QTest.qWait(5) - self.blacklist_obj.popMenuBlacklist.setActiveAction(self.blacklist_obj.popMenuBlacklist.actions()[intval]) - self.blacklist_obj.popMenuBlacklist.setStyleSheet("QMenu:selected {background-color:#FF5733}") + self.blacklist_obj.popMenuBlacklist.setActiveAction( + self.blacklist_obj.popMenuBlacklist.actions()[intval]) + self.blacklist_obj.popMenuBlacklist.setStyleSheet( + "QMenu:selected {background-color: #FF5733; color: white;}") self.blacklist_obj.popMenuBlacklist.show() QTest.qWait(400) self.blacklist_obj.popMenuBlacklist.hide() diff --git a/src/graphicaltesting/test_quit.py b/src/graphicaltesting/test_quit.py index 5ca24b33..3546af4c 100644 --- a/src/graphicaltesting/test_quit.py +++ b/src/graphicaltesting/test_quit.py @@ -17,7 +17,7 @@ from tr import _translate class BitmessageTest_QuitTest(BitmessageTestCase): """Quit the bitmessage qt application""" - + # pylint: disable=attribute-defined-outside-init def test_quitapplication(self): """wait for pow and shutdown the application""" print("=====================Test - Quitting Application=====================") @@ -28,57 +28,21 @@ class BitmessageTest_QuitTest(BitmessageTestCase): self.myapp.raise_() self.myapp.activateWindow() - waitForPow = True - waitForConnection = False - waitForSync = False + self.waitForPow = True + self.waitForConnection = False + self.waitForSync = False if getPowType() == "python" and (bitmessageqt.powQueueSize() > 0 or pendingUpload() > 0): - waitForPow = False + self.waitForPow = False if pendingDownload() > 0: - self.myapp.wait = waitForSync = True + self.myapp.wait = self.waitForSync = True if shared.statusIconColor == "red" and not BMConfigParser().safeGetBoolean( - "bitmessagesettings", "dontconnect" - ): - waitForConnection = True - self.myapp.wait = waitForSync = True + "bitmessagesettings", "dontconnect"): + self.waitForConnection = True + self.myapp.wait = self.waitForSync = True self.myapp.quitAccepted = True - self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down PyBitmessage... %1%").arg(0)) - if waitForConnection: - self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for network connection...")) - while shared.statusIconColor == "red": - time.sleep(0.5) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) - if waitForSync: - self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for finishing synchronisation...")) - while pendingDownload() > 0: - time.sleep(0.5) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) - if waitForPow: - maxWorkerQueue = 0 - curWorkerQueue = bitmessageqt.powQueueSize() - while curWorkerQueue > 0: - curWorkerQueue = bitmessageqt.powQueueSize() - if curWorkerQueue > maxWorkerQueue: - maxWorkerQueue = curWorkerQueue - if curWorkerQueue > 0: - self.myapp.updateStatusBar( - _translate("MainWindow", "Waiting for PoW to finish... %1%").arg( - 50 * (maxWorkerQueue - curWorkerQueue) / maxWorkerQueue)) - time.sleep(0.5) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) - self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down Pybitmessage... %1%").arg(50)) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) - if maxWorkerQueue > 0: - time.sleep(0.5) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) - self.myapp.updateStatusBar(_translate("MainWindow", "Waiting for objects to be sent... %1%").arg(50)) - maxPendingUpload = max(1, pendingUpload()) - while pendingUpload() > 1: - self.myapp.updateStatusBar( - _translate("MainWindow", "Waiting for objects to be sent... %1%").arg( - int(50 + 20 * (pendingUpload() / maxPendingUpload)))) - time.sleep(0.5) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) - QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.updateStatusBar( + _translate("MainWindow", "Shutting down PyBitmessage... %1%").arg(0)) + self.waiting_for_closing() QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) self.myapp.updateStatusBar(_translate("MainWindow", "Saving settings... %1%").arg(70)) QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) @@ -91,8 +55,53 @@ class BitmessageTest_QuitTest(BitmessageTestCase): self.myapp.updateStatusBar(_translate("MainWindow", "Shutting down core... %1%").arg(80)) QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) shutdown.doCleanShutdown() - self.myapp.updateStatusBar(_translate("MainWindow", "Stopping notifications... %1%").arg(90)) + self.myapp.updateStatusBar( + _translate("MainWindow", "Stopping notifications... %1%").arg(90)) self.myapp.tray.hide() self.myapp.updateStatusBar(_translate("MainWindow", "Shutdown imminent... %1%").arg(100)) logger.info("Shutdown complete") QtGui.qApp.closeAllWindows() + + def waiting_for_closing(self): + """Waiting for connections, sync, and Pow""" + if self.waitForConnection: + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for network connection...")) + while shared.statusIconColor == "red": + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + if self.waitForSync: + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for finishing synchronisation...")) + while pendingDownload() > 0: + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + if self.waitForPow: + maxWorkerQueue = 0 + curWorkerQueue = bitmessageqt.powQueueSize() + while curWorkerQueue > 0: + curWorkerQueue = bitmessageqt.powQueueSize() + if curWorkerQueue > maxWorkerQueue: + maxWorkerQueue = curWorkerQueue + if curWorkerQueue > 0: + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for PoW to finish... %1%").arg( + 50 * (maxWorkerQueue - curWorkerQueue) / maxWorkerQueue)) + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.updateStatusBar( + _translate("MainWindow", "Shutting down Pybitmessage... %1%").arg(50)) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + if maxWorkerQueue > 0: + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for objects to be sent... %1%").arg(50)) + maxPendingUpload = max(1, pendingUpload()) + while pendingUpload() > 1: + self.myapp.updateStatusBar( + _translate("MainWindow", "Waiting for objects to be sent... %1%").arg( + int(50 + 20 * (pendingUpload() / maxPendingUpload)))) + time.sleep(0.5) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) + QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 1000) diff --git a/src/graphicaltesting/test_settingwindow.py b/src/graphicaltesting/test_settingwindow.py index 9e840781..7ef9e527 100644 --- a/src/graphicaltesting/test_settingwindow.py +++ b/src/graphicaltesting/test_settingwindow.py @@ -10,12 +10,15 @@ from PyQt4.QtTest import QTest from bitmessageqt import dialogs from testloader import BitmessageTestCase +# pylint: disable=no-self-use + class BitmessageTest_SettingWindowTest(BitmessageTestCase): """Switch to setting tab and test""" def test_settingwindow(self): """Triggers the setting window""" + # pylint: disable=protected-access print("=====================Test - Setting Window=====================") try: self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox) @@ -36,9 +39,11 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): try: QTest.qWait(500) dialog.show() - dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) + dialog.tabWidgetSettings.setCurrentIndex( + dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) QTest.qWait(800) - dialog.languageComboBox.setStyleSheet("QComboBox {background-color: #FF5733; color: white;}") + dialog.languageComboBox.setStyleSheet( + "QComboBox {background-color: #FF5733; color: white;}") QTest.qWait(50) dialog.languageComboBox.setStyleSheet("") dialog.languageComboBox.setCurrentIndex(random.randint(1, 17)) @@ -53,13 +58,16 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): def eng_convert(self, dialog): """Convert any language to english, testing just for good readability""" - print("=====================Test - Converting Language Back to English=====================") + print( + "=====================Test - Converting Language Back to English=====================") try: QTest.qWait(500) dialog.show() - dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) + dialog.tabWidgetSettings.setCurrentIndex( + dialog.tabWidgetSettings.indexOf(dialog.tabUserInterface)) QTest.qWait(800) - dialog.languageComboBox.setStyleSheet("QComboBox {background-color: #FF5733; color: white;}") + dialog.languageComboBox.setStyleSheet( + "QComboBox {background-color: #FF5733; color: white;}") QTest.qWait(50) dialog.languageComboBox.setStyleSheet("") dialog.languageComboBox.setCurrentIndex(5) @@ -79,19 +87,11 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): QTest.qWait(500) dialog.show() QTest.qWait(300) - dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabNetworkSettings)) + dialog.tabWidgetSettings.setCurrentIndex( + dialog.tabWidgetSettings.indexOf(dialog.tabNetworkSettings)) QTest.qWait(500) - dialog.lineEditSocksHostname.setText("") - dialog.lineEditSocksPort.setText("") - dialog.lineEditSocksUsername.setText("") - dialog.lineEditSocksPassword.setText("") - if dialog.checkBoxAuthentication.isChecked(): - dialog.checkBoxAuthentication.click() - if dialog.checkBoxSocksListen.isChecked(): - dialog.checkBoxSocksListen.click() - if dialog.checkBoxOnionOnly.isChecked(): - dialog.checkBoxOnionOnly.click() + self.network_setting_window_preprocess(dialog) QTest.qWait(500) dialog.comboBoxProxyType.setCurrentIndex(random.randint(1, 3)) @@ -112,9 +112,11 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): dialog.checkBoxAuthentication.click() QTest.qWait(500) - dialog.lineEditSocksUsername.setText("".join(choice(ascii_lowercase) for i in range(10))) + dialog.lineEditSocksUsername.setText( + "".join(choice(ascii_lowercase) for i in range(10))) QTest.qWait(500) - dialog.lineEditSocksPassword.setText("".join(choice(ascii_lowercase) for i in range(10))) + dialog.lineEditSocksPassword.setText( + "".join(choice(ascii_lowercase) for i in range(10))) QTest.qWait(500) if dialog.checkBoxSocksListen.isChecked(): @@ -136,6 +138,22 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): print("Test Fail:--> Error while testing Network setting window") return 0 + def network_setting_window_preprocess(self, dialog): + """Setting text to fields""" + try: + dialog.lineEditSocksHostname.setText("") + dialog.lineEditSocksPort.setText("") + dialog.lineEditSocksUsername.setText("") + dialog.lineEditSocksPassword.setText("") + if dialog.checkBoxAuthentication.isChecked(): + dialog.checkBoxAuthentication.click() + if dialog.checkBoxSocksListen.isChecked(): + dialog.checkBoxSocksListen.click() + if dialog.checkBoxOnionOnly.isChecked(): + dialog.checkBoxOnionOnly.click() + except: + pass + def tabresendsexpire_window(self, dialog): """Testing for resend expire window""" print("=====================Test - Tab Resend Expire Window=====================") @@ -145,7 +163,8 @@ class BitmessageTest_SettingWindowTest(BitmessageTestCase): dialog.lineEditMonths.setText("") dialog.show() QTest.qWait(300) - dialog.tabWidgetSettings.setCurrentIndex(dialog.tabWidgetSettings.indexOf(dialog.tabResendsExpire)) + dialog.tabWidgetSettings.setCurrentIndex( + dialog.tabWidgetSettings.indexOf(dialog.tabResendsExpire)) QTest.qWait(500) QTest.qWait(500) -- 2.45.1