Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphical QT Testing #1603

Open
wants to merge 6 commits into
base: v0.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions src/bitmessageqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,9 @@ def click_actionJoinChan(self):

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(
Expand Down Expand Up @@ -2511,15 +2514,18 @@ def on_action_EmailGatewayDialog(self):
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:
Expand Down Expand Up @@ -3280,8 +3286,12 @@ def on_context_menuAddressBook(self, point):
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):
Expand Down Expand Up @@ -3361,8 +3371,12 @@ def on_context_menuSubscriptions(self, point):
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:
Expand Down Expand Up @@ -3775,8 +3789,12 @@ def on_context_menuYourIdentities(self, point):
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):
Expand Down Expand Up @@ -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_())
27 changes: 17 additions & 10 deletions src/bitmessageqt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,23 @@ def accept(self):
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(
Expand Down
Empty file.
98 changes: 98 additions & 0 deletions src/graphicaltesting/test_addressgeneration.py
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions src/graphicaltesting/test_addsubscription.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions src/graphicaltesting/test_appstart.py
Original file line number Diff line number Diff line change
@@ -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
Loading