Compare commits

...

6 Commits

Author SHA1 Message Date
lakshyacis
288fb35c47
code fixes 2020-03-17 21:18:05 +05:30
lakshyacis
48c9cd73d0
BlackWhitelist popupmenu test added 2020-03-16 20:13:18 +05:30
lakshyacis
5e92603fcc
Graphical Qt Test popupmenu automation 2020-03-13 20:10:20 +05:30
lakshyacis
380de9d1d9
Inbox PopMenu functionality 2020-03-04 14:58:48 +05:30
lakshyacis
ea2e11ced8
Add quit function and code fixes 2020-02-27 20:16:43 +05:30
lakshyacis
6b0ce5d1ae
Graphical Qt Tests 2020-02-26 16:24:49 +05:30
17 changed files with 1647 additions and 25 deletions

View File

@ -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(
@ -2511,15 +2514,18 @@ 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()
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:
@ -3280,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):
@ -3361,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:
@ -3775,8 +3789,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):
@ -4160,4 +4178,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_())

View File

@ -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(

View File

View File

@ -0,0 +1,98 @@
"""Generate Address for tests"""
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 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;}")
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)
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")
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:
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(750)
label_gen_obj.radioButtonDeterministicAddress.click()
QTest.qWait(250)
random_password1 = ""
for _ in range(15):
random_password1 += choice(ascii_lowercase)
label_gen_obj.lineEditPassphrase.setText(random_password1)
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(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 ......... ")
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")
return 0

View File

@ -0,0 +1,74 @@
"""Add address in the subscription list"""
from random import choice
from string import ascii_lowercase
from PyQt4 import QtGui
from PyQt4.QtCore import QTimer
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):
"""Add address to list"""
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.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)
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]
dialog.lineEditAddress.setText(random_address)
QTest.qWait(4)
QTest.qWait(500)
QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked)
try:
QTest.qWait(800)
address, label = dialog.data
except:
print("Test Fail:--> Error, While Creating subscription list")
QTest.qWait(500)
return 0
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")
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("Test Pass:--> Subscription Done Successfully")
return 1
else:
print("Test Fail:--> No Address Found")
return 0
except:
print("Test Fail:--> Error Occured while adding address to subscription list")
return 0

View File

@ -0,0 +1,11 @@
"""Trigger dialog"""
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)
return 1

View File

@ -0,0 +1,134 @@
"""Tests for blackwhitelist"""
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"""
# pylint: disable=attribute-defined-outside-init
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.dialog = AddAddressDialog(self.myapp)
blacklistcount = len(sqlQuery("Select * from blacklist"))
self.myapp.ui.blackwhitelist.radioButtonBlacklist.click()
self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet(
"QPushButton {background-color: #FF5733; color: white;}")
QTest.qWait(50)
self.myapp.ui.blackwhitelist.pushButtonAddBlacklist.setStyleSheet("")
self.blackwhitelist_autofill()
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.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")))
except:
return 0
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)
self.random_label = ""
for _ in range(30):
self.random_label += choice(ascii_lowercase)
self.dialog.lineEditLabel.setText(self.random_label)
QTest.qWait(4)
QTest.qWait(500)
rand_address = choice(BMConfigParser().addresses())
self.random_address = ""
for i, _ in enumerate(rand_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)
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,)
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='" + 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='" + self.random_label + "'")[0]
self.assertEqual(white_list_value[0], self.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:
QTest.qWait(100)
print("Test Fail:--> The address you entered was invalid. Ignoring it")
return 0
except:
pass

View File

@ -0,0 +1,16 @@
"""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"""
print("=====================Test - Chans Functionality=====================")
QTest.qWait(1200)
self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.chans)
print("Test Pass :--> Chans Test Passed")
return 1

View File

@ -0,0 +1,71 @@
"""Test for message send"""
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"""
# 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=====================")
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)
rand_address = choice(BMConfigParser().addresses())
random_address = ""
for i, _ in enumerate(rand_address):
random_address += rand_address[i]
self.myapp.ui.lineEditTo.setText(random_address)
QTest.qWait(4)
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(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(350)
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][1], rand_address)
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

View File

@ -0,0 +1,21 @@
"""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"""
try:
print("=====================Test - Network Functionality=====================")
QTest.qWait(1000)
self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.networkstatus)
QTest.qWait(1200)
print("Test Pass:--> Network Functionality Working Well")
return 1
except:
print("Test Fail:--> Network Functionality Failed")
return 0

View File

@ -0,0 +1,812 @@
"""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
# pylint: disable=no-else-return, inconsistent-return-statements, attribute-defined-outside-init
class BitmessageTest_Inbox_PopMenu(BitmessageTestCase):
"""Inbox TabWidget QTreeWidget popMenu Fucntionality testing"""
def test_sider(self):
"""Show QTreeWidget popmenu"""
print("-----------------------------------------------------------1")
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox)
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox)
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.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)))
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox)
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.inbox)
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):
"""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; color: white;}")
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):
"""Show QTreeWidget popmenu"""
print("-----------------------------------------------------------2")
try:
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)
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)
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 total_sub:
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send)
self.popup_menu(6)
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.send)
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):
"""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.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()
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.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()
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")
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.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)
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):
"""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; color: white;}")
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):
"""Show QTreeWidget Popup Menu"""
print("-----------------------------------------------------------3")
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):
"""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)
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 i, _ in enumerate(rand_address):
random_address += rand_address[i]
dialog.lineEditAddress.setText(random_address)
QTest.qWait(4)
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 1
except:
print("Test Fail:--> Enable Disable 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 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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions)
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.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions)
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):
"""Method deletes the address from the subscription"""
print(
"=====================Test - Delete Address from the subscription Field=====================")
try:
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)
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):
"""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; color: white;}")
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):
"""Show QTableWidget Popupmenu"""
print("-----------------------------------------------------------4")
try:
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:
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; color: white;}")
self.blacklist_obj.popMenuBlacklist.show()
QTest.qWait(400)
self.blacklist_obj.popMenuBlacklist.hide()
QTest.qWait(50)
except:
pass

View File

@ -0,0 +1,107 @@
"""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"""
# pylint: disable=attribute-defined-outside-init
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
self.myapp.show()
self.myapp.raise_()
self.myapp.activateWindow()
self.waitForPow = True
self.waitForConnection = False
self.waitForSync = False
if getPowType() == "python" and (bitmessageqt.powQueueSize() > 0 or pendingUpload() > 0):
self.waitForPow = False
if pendingDownload() > 0:
self.myapp.wait = self.waitForSync = True
if shared.statusIconColor == "red" and not BMConfigParser().safeGetBoolean(
"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))
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)
self.myapp.saveSettings()
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):
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()
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)

View File

@ -0,0 +1,181 @@
"""Tests for setting window"""
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
# 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)
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:
QTest.qWait(500)
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("Test Pass:--> Language Changed Successfully")
return 1
except:
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)
dialog.languageComboBox.setStyleSheet(
"QComboBox {background-color: #FF5733; color: white;}")
QTest.qWait(50)
dialog.languageComboBox.setStyleSheet("")
dialog.languageComboBox.setCurrentIndex(5)
QTest.qWait(1000)
ok_btn = dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok)
QTest.mouseClick(ok_btn, Qt.LeftButton)
print("Test Pass:--> language changed to English Again")
return 1
except:
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))
QTest.qWait(500)
self.network_setting_window_preprocess(dialog)
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("Test Pass:--> Successfully tested Network setting window")
return 1
except:
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=====================")
try:
QTest.qWait(500)
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("Test Pass:--> Test successfull")
return 1
except:
print("Test Fail:--> Tab Resend Exprire")
return 0

View File

@ -0,0 +1,39 @@
"""Trigger Test"""
import unittest
import test_addressgeneration
import test_addsubscription
import test_blackwhitelist
import test_chans
import test_messagesend
import test_networkstatus
import test_popupmenu
import test_quit
import test_settingwindow
from testloader import BitmessageTestCase
def test_initialize(myapp):
"""Inititalizing the test cases"""
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_popupmenu.BitmessageTest_Inbox_PopMenu, myapp=myapp))
suite.addTest(
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)

View File

@ -0,0 +1,19 @@
"""Load Test"""
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):
"""Method responsible for loading test"""
testnames = unittest.TestLoader().getTestCaseNames(testcaseclass)
suite = unittest.TestSuite()
for name in testnames:
suite.addTest(testcaseclass(name, myapp))
return suite

View File

@ -55,3 +55,5 @@ testmode = False
kivy = False
association = ''
qttesting = False

8
src/test_qt.py Normal file
View File

@ -0,0 +1,8 @@
import state
if __name__ == "__main__":
state.qttesting = True
print(" --------------------------------- Graphical Qt Testing --------------------------------- ")
from bitmessagemain import main
main()