diff --git a/src/tests/sql/create_function.sql b/src/tests/sql/create_function.sql deleted file mode 100644 index cc59904b..00000000 --- a/src/tests/sql/create_function.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `testhash` ( - `addressversion` int DEFAULT NULL, - `hash` blob DEFAULT NULL, - `address` text DEFAULT NULL, - UNIQUE(address) ON CONFLICT IGNORE -); - -INSERT INTO testhash (addressversion, hash) VALUES(4, "21122112211221122112"); - diff --git a/src/tests/test_sqlthread.py b/src/tests/test_sqlthread.py index 079aea92..5da4a0ca 100644 --- a/src/tests/test_sqlthread.py +++ b/src/tests/test_sqlthread.py @@ -1,24 +1,19 @@ -""" - Test for sqlThread -""" +"""Tests for SQL thread""" import os -import unittest -from ..helper_sql import sqlStoredProcedure, sql_ready, sqlExecute, SqlBulkExecute, sqlQuery, sqlExecuteScript -from ..class_sqlThread import (sqlThread) -from ..addresses import encodeAddress - +import tempfile import threading +import unittest + +os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir() # noqa:E402 + +from pybitmessage.helper_sql import sqlQuery, sql_ready, sqlStoredProcedure +from pybitmessage.class_sqlThread import sqlThread +from pybitmessage.addresses import encodeAddress + class TestSqlThread(unittest.TestCase): - """ - Test case for SQLThread - """ - - # query file path - root_path = os.path.dirname(os.path.dirname(__file__)) - - + """Test case for SQL thread""" @classmethod def setUpClass(cls): @@ -28,18 +23,6 @@ class TestSqlThread(unittest.TestCase): sqlLookup.start() sql_ready.wait() - - @classmethod - def setUp(cls): - tables = list(sqlQuery("select name from sqlite_master where type is 'table'")) - with SqlBulkExecute() as sql: - for q in tables: - sql.execute("drop table if exists %s" % q) - - @classmethod - def tearDown(cls): - pass - @classmethod def tearDownClass(cls): sqlStoredProcedure('exit') @@ -47,29 +30,10 @@ class TestSqlThread(unittest.TestCase): if thread.name == "SQL": thread.join() - def initialise_database(self, file): - """ - Initialise DB - """ - with open(os.path.join(self.root_path, "tests/sql/{}.sql".format(file)), 'r') as sql_as_string: - # sql_as_string = open(os.path.join(self.root_path, "tests/sql/{}.sql".format(file))).read() - sql_as_string = sql_as_string.read() - sqlExecuteScript(sql_as_string) - def test_create_function(self): - # call create function + """Check the result of enaddr function""" encoded_str = encodeAddress(4, 1, "21122112211221122112") - # Initialise Database - self.initialise_database("create_function") - - sqlExecute('''INSERT INTO testhash (addressversion, hash) VALUES(4, "21122112211221122112")''') - # call function in query - - # sqlExecute('''UPDATE testhash SET address=(enaddr(testhash.addressversion, 1, hash)) WHERE hash=testhash.hash''') - sqlExecute('''UPDATE testhash SET address=(enaddr(testhash.addressversion, 1, hash));''') - - # Assertion - query = sqlQuery('''select * from testhash;''') - self.assertEqual(query[0][-1], encoded_str, "test case fail for create_function") - sqlExecute('''DROP TABLE testhash''') + query = sqlQuery('SELECT enaddr(4, 1, "21122112211221122112")') + self.assertEqual( + query[0][-1], encoded_str, "test case fail for create_function")