written test case for addressbook
This commit is contained in:
parent
42037502ab
commit
f146500b58
|
@ -2436,17 +2436,15 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
))
|
))
|
||||||
return
|
return
|
||||||
|
|
||||||
if address in BMConfigParser().addresses():
|
if helper_addressbook.insert(label=label, address=address):
|
||||||
|
self.rerenderMessagelistFromLabels()
|
||||||
|
self.rerenderMessagelistToLabels()
|
||||||
|
self.rerenderAddressBook()
|
||||||
|
else:
|
||||||
self.updateStatusBar(_translate(
|
self.updateStatusBar(_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Error: You cannot add your own address in the address book."
|
"Error: You cannot add your own address in the address book."
|
||||||
))
|
))
|
||||||
return
|
|
||||||
|
|
||||||
helper_addressbook.insert(label=label, address=address)
|
|
||||||
self.rerenderMessagelistFromLabels()
|
|
||||||
self.rerenderMessagelistToLabels()
|
|
||||||
self.rerenderAddressBook()
|
|
||||||
|
|
||||||
def addSubscription(self, address, label):
|
def addSubscription(self, address, label):
|
||||||
# This should be handled outside of this function, for error displaying
|
# This should be handled outside of this function, for error displaying
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
Insert value into addressbook
|
Insert value into addressbook
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from helper_sql import sqlExecute
|
from bmconfigparser import BMConfigParser
|
||||||
|
from helper_sql import sqlExecute, sqlQuery
|
||||||
|
|
||||||
|
|
||||||
def insert(address, label):
|
def insert(address, label):
|
||||||
"""perform insert into addressbook"""
|
"""perform insert into addressbook"""
|
||||||
|
queryreturn = sqlQuery(
|
||||||
|
'''SELECT count(*) FROM addressbook WHERE address=?''', address)
|
||||||
|
|
||||||
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address)
|
if address not in BMConfigParser().addresses() and not queryreturn[0][0]:
|
||||||
|
return sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address) == 1
|
||||||
|
return False
|
||||||
|
|
|
@ -16,6 +16,7 @@ import unittest
|
||||||
import protocol
|
import protocol
|
||||||
import state
|
import state
|
||||||
import helper_sent
|
import helper_sent
|
||||||
|
import helper_addressbook
|
||||||
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from helper_msgcoding import MsgEncode, MsgDecode
|
from helper_msgcoding import MsgEncode, MsgDecode
|
||||||
|
@ -57,6 +58,7 @@ def pickle_knownnodes():
|
||||||
|
|
||||||
class TestCore(unittest.TestCase):
|
class TestCore(unittest.TestCase):
|
||||||
"""Test case, which runs in main pybitmessage thread"""
|
"""Test case, which runs in main pybitmessage thread"""
|
||||||
|
addr = 'BM-2cVvkzJuQDsQHLqxRXc6HZGPLZnkBLzEZY'
|
||||||
|
|
||||||
def test_msgcoding(self):
|
def test_msgcoding(self):
|
||||||
"""test encoding and decoding (originally from helper_msgcoding)"""
|
"""test encoding and decoding (originally from helper_msgcoding)"""
|
||||||
|
@ -251,7 +253,7 @@ class TestCore(unittest.TestCase):
|
||||||
subject = 'test subject'
|
subject = 'test subject'
|
||||||
result = helper_sent.insert(
|
result = helper_sent.insert(
|
||||||
toAddress=toAddress, fromAddress=fromAddress,
|
toAddress=toAddress, fromAddress=fromAddress,
|
||||||
subject=subject, message=message,
|
subject=subject, message=message
|
||||||
)
|
)
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''select msgid from sent where ackdata=?''', result)
|
'''select msgid from sent where ackdata=?''', result)
|
||||||
|
@ -274,6 +276,42 @@ class TestCore(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
cleanup(files=('knownnodes.dat',))
|
cleanup(files=('knownnodes.dat',))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_random_address():
|
||||||
|
"""Generating random address"""
|
||||||
|
import queues
|
||||||
|
streamNumberForAddress = 1
|
||||||
|
queues.addressGeneratorQueue.put((
|
||||||
|
'createRandomAddress', 4, streamNumberForAddress,
|
||||||
|
"test1", 1, "", False))
|
||||||
|
|
||||||
|
def delete_address_from_database(self):
|
||||||
|
"""Deleting random address"""
|
||||||
|
sqlQuery('''delete from addressbook where address=?''', self.addr)
|
||||||
|
|
||||||
|
def test_add_same_address_twice_in_addressbook(self):
|
||||||
|
"""checking same address is added twice in addressbook"""
|
||||||
|
self.assertTrue(helper_addressbook.insert(label='test1', address=self.addr))
|
||||||
|
self.assertFalse(helper_addressbook.insert(label='test1', address=self.addr))
|
||||||
|
self.delete_address_from_database()
|
||||||
|
|
||||||
|
def test_is_address_present_in_addressbook(self):
|
||||||
|
"""checking is address added in addressbook or not"""
|
||||||
|
helper_addressbook.insert(label='test1', address=self.addr)
|
||||||
|
queryreturn = sqlQuery('''select count(*) from addressbook where address=?''', self.addr)
|
||||||
|
self.assertTrue(bool(queryreturn[0][0]))
|
||||||
|
self.delete_address_from_database()
|
||||||
|
|
||||||
|
def test_is_own_address_add_to_addressbook(self):
|
||||||
|
"""Checking own address adding in addressbook"""
|
||||||
|
self.generate_random_address()
|
||||||
|
time.sleep(.5)
|
||||||
|
try:
|
||||||
|
all_addresses = BMConfigParser().addresses()
|
||||||
|
self.assertFalse(helper_addressbook.insert(label='test', address=all_addresses[0]))
|
||||||
|
except IndexError:
|
||||||
|
self.fail("Can't generate addresses")
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""Starts all tests defined in this module"""
|
"""Starts all tests defined in this module"""
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
"""
|
|
||||||
Tests for addresbook validation
|
|
||||||
"""
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
from pybitmessage.bmconfigparser import BMConfigParser
|
|
||||||
|
|
||||||
|
|
||||||
class TestAddAddressBook(unittest.TestCase):
|
|
||||||
"""this class is used for testting add address feature"""
|
|
||||||
|
|
||||||
def test_is_own_address_add_to_addressbook(self):
|
|
||||||
"""Check the logic of TCPConnection.local"""
|
|
||||||
own_addresses = BMConfigParser().addresses()
|
|
||||||
if own_addresses:
|
|
||||||
address = own_addresses[0]
|
|
||||||
else:
|
|
||||||
address = 'BM-2cWiUsWMo4Po2UyNB3VyQdF3gxGrDX9gNm'
|
|
||||||
|
|
||||||
self.assertTrue(address not in own_addresses)
|
|
Loading…
Reference in New Issue
Block a user