updated addressbook table in class_sqlThread module
This commit is contained in:
parent
f146500b58
commit
bfdb78151c
|
@ -47,7 +47,7 @@ class sqlThread(threading.Thread):
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
'''CREATE TABLE addressbook (label text, address text)''')
|
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
|
@ -63,7 +63,7 @@ class sqlThread(threading.Thread):
|
||||||
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
||||||
self.cur.execute('''INSERT INTO settings VALUES('version','10')''')
|
self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
||||||
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
||||||
int(time.time()),))
|
int(time.time()),))
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
|
@ -388,7 +388,27 @@ class sqlThread(threading.Thread):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'In messages.dat database, done adding address field to the pubkeys table'
|
'In messages.dat database, done adding address field to the pubkeys table'
|
||||||
' and removing the hash field.')
|
' and removing the hash field.')
|
||||||
self.cur.execute('''update settings set value=10 WHERE key='version';''')
|
item = '''update settings set value=? WHERE key='version';'''
|
||||||
|
parameters = (10,)
|
||||||
|
self.cur.execute(item, parameters)
|
||||||
|
|
||||||
|
# Update the address colunm to unique in addressbook table
|
||||||
|
item = '''SELECT value FROM settings WHERE key='version';'''
|
||||||
|
parameters = ''
|
||||||
|
self.cur.execute(item, parameters)
|
||||||
|
currentVersion = int(self.cur.fetchall()[0][0])
|
||||||
|
if currentVersion == 10:
|
||||||
|
logger.debug(
|
||||||
|
'In messages.dat database, updating address column to UNIQUE'
|
||||||
|
' in the addressbook table.')
|
||||||
|
self.cur.execute(
|
||||||
|
'''ALTER TABLE addressbook RENAME TO old_addressbook''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''CREATE TABLE addressbook'''
|
||||||
|
''' (label text, address text, UNIQUE(address) ON CONFLICT REPLACE)''')
|
||||||
|
self.cur.execute(
|
||||||
|
'''INSERT INTO addressbook SELECT label, address FROM old_addressbook;''')
|
||||||
|
self.cur.execute('''update settings set value=11 WHERE key='version';''')
|
||||||
|
|
||||||
# Are you hoping to add a new option to the keys.dat file of existing
|
# Are you hoping to add a new option to the keys.dat file of existing
|
||||||
# Bitmessage users or modify the SQLite database? Add it right
|
# Bitmessage users or modify the SQLite database? Add it right
|
||||||
|
|
|
@ -3,14 +3,12 @@ Insert value into addressbook
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from helper_sql import sqlExecute, sqlQuery
|
from helper_sql import sqlExecute
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if address not in BMConfigParser().addresses() and not queryreturn[0][0]:
|
if address not in BMConfigParser().addresses():
|
||||||
return sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address) == 1
|
return sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address) == 1
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -285,22 +285,22 @@ class TestCore(unittest.TestCase):
|
||||||
'createRandomAddress', 4, streamNumberForAddress,
|
'createRandomAddress', 4, streamNumberForAddress,
|
||||||
"test1", 1, "", False))
|
"test1", 1, "", False))
|
||||||
|
|
||||||
def delete_address_from_database(self):
|
def delete_address_from_database(self, address):
|
||||||
"""Deleting random address"""
|
"""Clean up addressbook"""
|
||||||
sqlQuery('''delete from addressbook where address=?''', self.addr)
|
sqlQuery('''delete from addressbook where address=?''', address)
|
||||||
|
|
||||||
def test_add_same_address_twice_in_addressbook(self):
|
def test_add_same_address_twice_in_addressbook(self):
|
||||||
"""checking same address is added twice in addressbook"""
|
"""checking same address is added twice in addressbook"""
|
||||||
self.assertTrue(helper_addressbook.insert(label='test1', address=self.addr))
|
self.assertTrue(helper_addressbook.insert(label='test1', address=self.addr))
|
||||||
self.assertFalse(helper_addressbook.insert(label='test1', address=self.addr))
|
self.assertFalse(helper_addressbook.insert(label='test1', address=self.addr))
|
||||||
self.delete_address_from_database()
|
self.delete_address_from_database(self.addr)
|
||||||
|
|
||||||
def test_is_address_present_in_addressbook(self):
|
def test_is_address_present_in_addressbook(self):
|
||||||
"""checking is address added in addressbook or not"""
|
"""checking is address added in addressbook or not"""
|
||||||
helper_addressbook.insert(label='test1', address=self.addr)
|
helper_addressbook.insert(label='test1', address=self.addr)
|
||||||
queryreturn = sqlQuery('''select count(*) from addressbook where address=?''', self.addr)
|
queryreturn = sqlQuery('''select count(*) from addressbook where address=?''', self.addr)
|
||||||
self.assertTrue(bool(queryreturn[0][0]))
|
self.assertTrue(bool(queryreturn[0][0]))
|
||||||
self.delete_address_from_database()
|
self.delete_address_from_database(self.addr)
|
||||||
|
|
||||||
def test_is_own_address_add_to_addressbook(self):
|
def test_is_own_address_add_to_addressbook(self):
|
||||||
"""Checking own address adding in addressbook"""
|
"""Checking own address adding in addressbook"""
|
||||||
|
@ -312,6 +312,15 @@ class TestCore(unittest.TestCase):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
self.fail("Can't generate addresses")
|
self.fail("Can't generate addresses")
|
||||||
|
|
||||||
|
def test_adding_two_same_case_sensitive_addresses(self):
|
||||||
|
"""Testing same case sensitive address store in addressbook"""
|
||||||
|
address1 = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP'
|
||||||
|
address2 = 'BM-2CvwTDuZpWf7ungdRzFTwUhwIj6XXbPIsp'
|
||||||
|
self.assertTrue(helper_addressbook.insert(label='test1', address=address1))
|
||||||
|
self.assertTrue(helper_addressbook.insert(label='test2', address=address2))
|
||||||
|
self.delete_address_from_database(address1)
|
||||||
|
self.delete_address_from_database(address2)
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""Starts all tests defined in this module"""
|
"""Starts all tests defined in this module"""
|
||||||
|
|
Reference in New Issue
Block a user