PyBitmessage-2021-04-27/src/graphicaltesting/test_addsubscription.py

72 lines
3.0 KiB
Python
Raw Normal View History

2020-02-27 14:46:43 +00:00
"""Add address in the subscription list"""
2020-02-26 10:54:49 +00:00
from random import choice
from string import ascii_lowercase
2020-03-13 14:40:20 +00:00
from PyQt4 import QtGui
from PyQt4.QtCore import QTimer
2020-02-26 10:54:49 +00:00
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):
2020-02-27 14:46:43 +00:00
"""Add address to list"""
2020-02-26 10:54:49 +00:00
def test_subscription(self):
"""Test for subscription functionality"""
2020-03-13 14:40:20 +00:00
print("=====================Test - Subscribe Address=====================")
2020-03-04 09:28:48 +00:00
try:
if BMConfigParser().addresses():
QTest.qWait(500)
self.myapp.ui.tabWidget.setCurrentWidget(self.myapp.ui.subscriptions)
QTest.qWait(500)
2020-03-13 14:40:20 +00:00
self.myapp.ui.pushButtonAddSubscription.setStyleSheet(
2020-03-16 14:43:18 +00:00
"QPushButton {background-color: #FF5733; color: white;}")
2020-03-13 14:40:20 +00:00
QTest.qWait(50)
self.myapp.ui.pushButtonAddSubscription.setStyleSheet("")
dialog = dialogs.NewSubscriptionDialog(self.myapp)
dialog.show()
QTest.qWait(750)
2020-02-26 10:54:49 +00:00
random_label = ""
for _ in range(30):
random_label += choice(ascii_lowercase)
2020-03-13 14:40:20 +00:00
dialog.lineEditLabel.setText(random_label)
QTest.qWait(4)
2020-02-26 10:54:49 +00:00
QTest.qWait(500)
rand_address = choice(BMConfigParser().addresses())
random_address = ""
2020-03-13 14:40:20 +00:00
for i, _ in enumerate(rand_address):
random_address += rand_address[i]
dialog.lineEditAddress.setText(random_address)
QTest.qWait(4)
2020-02-26 10:54:49 +00:00
QTest.qWait(500)
2020-03-13 14:40:20 +00:00
QTimer.singleShot(0, dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked)
2020-02-26 10:54:49 +00:00
try:
QTest.qWait(800)
2020-03-13 14:40:20 +00:00
address, label = dialog.data
except:
print("Test Fail:--> Error, While Creating subscription list")
2020-02-26 10:54:49 +00:00
QTest.qWait(500)
return 0
if shared.isAddressInMySubscriptionsList(address):
print(
2020-03-13 14:40:20 +00:00
"Test Fail:--> You cannot add the same address to your subscriptions twice."
2020-03-16 14:43:18 +00:00
" Perhaps rename the existing one if you want")
2020-02-26 10:54:49 +00:00
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])
2020-03-13 14:40:20 +00:00
print("Test Pass:--> Subscription Done Successfully")
2020-02-26 10:54:49 +00:00
return 1
2020-03-04 09:28:48 +00:00
else:
2020-03-13 14:40:20 +00:00
print("Test Fail:--> No Address Found")
2020-02-26 10:54:49 +00:00
return 0
2020-03-04 09:28:48 +00:00
except:
2020-03-13 14:40:20 +00:00
print("Test Fail:--> Error Occured while adding address to subscription list")
2020-02-26 10:54:49 +00:00
return 0