From edc4660c6dba8000e699b6d366c483af358a2c59 Mon Sep 17 00:00:00 2001 From: navjot Date: Wed, 6 Jan 2021 12:27:35 +0530 Subject: [PATCH] imported helper_addressGenerator module --- src/class_sqlThread.py | 9 ++++----- src/tests/core.py | 27 +++++++++------------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 77318473..e3b36ae0 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -47,7 +47,7 @@ class sqlThread(threading.Thread): self.cur.execute( '''CREATE TABLE subscriptions (label text, address text, enabled bool)''') self.cur.execute( - '''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT REPLACE)''') + '''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''') self.cur.execute( '''CREATE TABLE blacklist (label text, address text, enabled bool)''') self.cur.execute( @@ -388,9 +388,7 @@ class sqlThread(threading.Thread): logger.debug( 'In messages.dat database, done adding address field to the pubkeys table' ' and removing the hash field.') - item = '''update settings set value=? WHERE key='version';''' - parameters = (10,) - self.cur.execute(item, parameters) + self.cur.execute('''update settings set value=10 WHERE key='version';''') # Update the address colunm to unique in addressbook table item = '''SELECT value FROM settings WHERE key='version';''' @@ -405,9 +403,10 @@ class sqlThread(threading.Thread): '''ALTER TABLE addressbook RENAME TO old_addressbook''') self.cur.execute( '''CREATE TABLE addressbook''' - ''' (label text, address text, UNIQUE(address) ON CONFLICT REPLACE)''') + ''' (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''') self.cur.execute( '''INSERT INTO addressbook SELECT label, address FROM old_addressbook;''') + self.cur.execute('''DROP TABLE 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 diff --git a/src/tests/core.py b/src/tests/core.py index d3b4da6c..0ff54f91 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -277,15 +277,7 @@ class TestCore(unittest.TestCase): 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, address): + def delete_address_from_addressbook(address): """Clean up addressbook""" sqlQuery('''delete from addressbook where address=?''', address) @@ -293,22 +285,21 @@ class TestCore(unittest.TestCase): """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(self.addr) + self.delete_address_from_addressbook(self.addr) 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(self.addr) + self.assertEqual(queryreturn[0][0], 1) + self.delete_address_from_addressbook(self.addr) def test_is_own_address_add_to_addressbook(self): """Checking own address adding in addressbook""" - self.generate_random_address() - time.sleep(.5) + from helper_addressGenerator import createAddressIfNeeded try: - all_addresses = BMConfigParser().addresses() - self.assertFalse(helper_addressbook.insert(label='test', address=all_addresses[0])) + address = createAddressIfNeeded('test1') + self.assertFalse(helper_addressbook.insert(label='test', address=address)) except IndexError: self.fail("Can't generate addresses") @@ -318,8 +309,8 @@ class TestCore(unittest.TestCase): 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) + self.delete_address_from_addressbook(address1) + self.delete_address_from_addressbook(address2) def run():