From a00c898f46dfc313096e622086321836907c677a Mon Sep 17 00:00:00 2001 From: Muzahid Date: Tue, 29 Jun 2021 13:24:10 +0530 Subject: [PATCH] rebase and merge conflicts --- src/class_sqlThread.py | 17 +------- ...{init_version_1.sql => init_version_3.sql} | 0 ...{init_version_1.sql => init_version_3.sql} | 0 src/tests/test_sqlthread.py | 40 +++++++++---------- 4 files changed, 22 insertions(+), 35 deletions(-) rename src/sql/{init_version_1.sql => init_version_3.sql} (100%) rename src/tests/sql/{init_version_1.sql => init_version_3.sql} (100%) diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 5b3352cd..b499c364 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -64,19 +64,6 @@ class UpgradeDB(object): self.cur.execute(item, parameters) return int(self.cur.fetchall()[0][0]) - def _upgrade_one_level_method(self, level): - """ - Apply switcher to call methods accordingly - """ - - if level != self.__get_current_settings_version(): - return None - - # Migrate Db with level - method_name = 'upgrade_schema_data_' + str(level) - method = getattr(self, method_name, lambda: "Invalid version") - return method() - def _upgrade_one_level_sql_statement(self, file_name): """ Execute SQL files and queries @@ -106,10 +93,10 @@ class UpgradeDB(object): # call upgrading level in loop for l in range(self.current_level, self.max_level): - if int(l) == 3: + if int(l) == 1: continue - self._upgrade_one_level_method(l) self._upgrade_one_level_sql_statement(l) + self.increment_settings_version(l) def increment_settings_version(self, level): """ diff --git a/src/sql/init_version_1.sql b/src/sql/init_version_3.sql similarity index 100% rename from src/sql/init_version_1.sql rename to src/sql/init_version_3.sql diff --git a/src/tests/sql/init_version_1.sql b/src/tests/sql/init_version_3.sql similarity index 100% rename from src/tests/sql/init_version_1.sql rename to src/tests/sql/init_version_3.sql diff --git a/src/tests/test_sqlthread.py b/src/tests/test_sqlthread.py index 59346fd2..206eb2c1 100644 --- a/src/tests/test_sqlthread.py +++ b/src/tests/test_sqlthread.py @@ -77,7 +77,7 @@ class TestSqlThread(unittest.TestCase): sqlExecuteScript(sql_as_string) - def versioning(self): + def version(self): """ Run SQL Scripts, Initialize DB with respect to versioning and Upgrade DB schema for all versions @@ -125,8 +125,18 @@ class TestSqlThread(unittest.TestCase): self.assertEqual(query[0][-1], encoded_str, "test case fail for create_function") sqlExecute('''DROP TABLE testhash''') - @versioning - def test_sql_thread_version_1(self): + @version + def test_sql_thread_version_2(self): + """ + Test with version 2 + """ + + # Assertion + res = sqlQuery(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='inventory_backup' ''') + self.assertNotEqual(res[0][0], 1, "Table inventory_backup not deleted in versioning 2") + + @version + def test_sql_thread_version_3(self): """ Test with version 1 Version 1 and 3 are same so will skip 3 @@ -139,17 +149,7 @@ class TestSqlThread(unittest.TestCase): self.assertEqual(result, ['tag'], "Data not migrated for version 1") self.assertEqual(res, [(5, 'tag', 'blob', 0, "''", 0)], "Data not migrated for version 1") - @versioning - def test_sql_thread_version_2(self): - """ - Test with version 2 - """ - - # Assertion - res = sqlQuery(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='inventory_backup' ''') - self.assertNotEqual(res[0][0], 1, "Table inventory_backup not deleted in versioning 2") - - @versioning + @version def test_sql_thread_version_4(self): """ Test with version 4 @@ -159,7 +159,7 @@ class TestSqlThread(unittest.TestCase): res = sqlQuery('''select * from inventory where objecttype = 'pubkey';''') self.assertNotEqual(len(res), 1, "Table inventory not deleted in versioning 4") - @versioning + @version def test_sql_thread_version_5(self): """ Test with version 5 @@ -173,7 +173,7 @@ class TestSqlThread(unittest.TestCase): WHERE type='table' AND name='objectprocessorqueue'; ''') self.assertNotEqual(len(res), 0, "Table objectprocessorqueue not created in versioning 5") - @versioning + @version def test_sql_thread_version_6(self): """ Test with version 6 @@ -189,7 +189,7 @@ class TestSqlThread(unittest.TestCase): objectprocessorqueue = list(filter_table_column(objectprocessorqueue, "objecttype")) self.assertEqual(objectprocessorqueue, ['objecttype'], "Data not migrated for version 6") - @versioning + @version def test_sql_thread_version_7(self): """ Test with version 7 @@ -205,7 +205,7 @@ class TestSqlThread(unittest.TestCase): sent = sqlQuery('''SELECT status FROM sent ''') self.assertEqual(sent, [('msgqueued',), ('msgqueued',)], "Data not migrated for version 7") - @versioning + @version def test_sql_thread_version_8(self): """ Test with version 8 @@ -216,7 +216,7 @@ class TestSqlThread(unittest.TestCase): result = list(filter_table_column(res, "sighash")) self.assertEqual(result, ['sighash'], "Data not migrated for version 8") - @versioning + @version def test_sql_thread_version_9(self): """ Test with version 9 @@ -231,7 +231,7 @@ class TestSqlThread(unittest.TestCase): result = list(filter_table_column(res, "address")) self.assertEqual(result, ['address'], "Data not migrated for version 9") - @versioning + @version def test_sql_thread_version_10(self): """ Test with version 10