Skip to content

Commit 5803410

Browse files
committed
sql db initializing tests
1 parent 107e1e0 commit 5803410

1 file changed

Lines changed: 138 additions & 9 deletions

File tree

src/tests/test_sqlthread.py

Lines changed: 138 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def _setup_db(self): # pylint: disable=W0622, redefined-builtin
3535
self.test_db.create_sql_function()
3636
self.test_db.initialize_schema()
3737

38+
def get_table_schema(self, table_name):
39+
self.test_db.cur.execute("""PRAGMA table_info({})""".format(table_name))
40+
res = self.test_db.cur.fetchall()
41+
res = [[x[1], x[2]] for x in res]
42+
return res
43+
3844
def initialise_database(self, test_db_cur, file): # pylint: disable=W0622, redefined-builtin
3945
"""
4046
Initialise DB
@@ -67,6 +73,138 @@ def test_create_function(self):
6773
self.assertEqual(query[0][-1], encoded_str, "test case fail for create_function")
6874

6975

76+
class TestInitializerBitmessageDB(TestSqlBase, unittest.TestCase):
77+
"""Test case for SQL initializer"""
78+
79+
def setUp(self):
80+
"""
81+
Setup DB schema before start.
82+
And applying default schema for initializer test.
83+
"""
84+
self._setup_db()
85+
86+
def test_inbox_table_init(self):
87+
"""
88+
Test inbox table
89+
"""
90+
res = self.get_table_schema("inbox")
91+
check = [['msgid', 'blob'],
92+
['toaddress', 'text'],
93+
['fromaddress', 'text'],
94+
['subject', 'text'],
95+
['received', 'text'],
96+
['message', 'text'],
97+
['folder', 'text'],
98+
['encodingtype', 'int'],
99+
['read', 'bool'],
100+
['sighash', 'blob']]
101+
self.assertEqual(res,check,"inbox table not valid")
102+
103+
def test_sent_table_init(self):
104+
"""
105+
Test sent table
106+
"""
107+
res = self.get_table_schema("sent")
108+
check = [['msgid', 'blob'],
109+
['toaddress', 'text'],
110+
['toripe', 'blob'],
111+
['fromaddress', 'text'],
112+
['subject', 'text'],
113+
['message', 'text'],
114+
['ackdata', 'blob'],
115+
['senttime', 'integer'],
116+
['lastactiontime', 'integer'],
117+
['sleeptill', 'integer'],
118+
['status', 'text'],
119+
['retrynumber', 'integer'],
120+
['folder', 'text'],
121+
['encodingtype', 'int'],
122+
['ttl', 'int']]
123+
self.assertEqual(res, check, "sent table not valid")
124+
125+
def test_subscriptions_table_init(self):
126+
"""
127+
Test subscriptions table
128+
"""
129+
res = self.get_table_schema("subscriptions")
130+
check = [['label', 'text'],
131+
['address', 'text'],
132+
['enabled', 'bool']]
133+
self.assertEqual(res, check, "subscriptions table not valid")
134+
135+
def test_addressbook_table_init(self):
136+
"""
137+
Test addressbook table
138+
"""
139+
res = self.get_table_schema("addressbook")
140+
check = [['label', 'text'],
141+
['address', 'text']]
142+
self.assertEqual(res, check, "addressbook table not valid")
143+
144+
def test_blacklist_table_init(self):
145+
"""
146+
Test blacklist table
147+
"""
148+
res = self.get_table_schema("blacklist")
149+
check = [['label', 'text'],
150+
['address', 'text'],
151+
['enabled', 'bool']]
152+
self.assertEqual(res, check, "blacklist table not valid")
153+
154+
def test_whitelist_table_init(self):
155+
"""
156+
Test whitelist table
157+
"""
158+
res = self.get_table_schema("whitelist")
159+
check = [['label', 'text'],
160+
['address', 'text'],
161+
['enabled', 'bool']]
162+
self.assertEqual(res, check, "whitelist table not valid")
163+
164+
def test_pubkeys_table_init(self):
165+
"""
166+
Test pubkeys table
167+
"""
168+
res = self.get_table_schema("pubkeys")
169+
check = [['address', 'text'],
170+
['addressversion', 'int'],
171+
['transmitdata', 'blob'],
172+
['time', 'int'],
173+
['usedpersonally', 'text']]
174+
self.assertEqual(res, check, "pubkeys table not valid")
175+
176+
def test_inventory_table_init(self):
177+
"""
178+
Test inventory table
179+
"""
180+
res = self.get_table_schema("inventory")
181+
check = [['hash', 'blob'],
182+
['objecttype', 'int'],
183+
['streamnumber', 'int'],
184+
['payload', 'blob'],
185+
['expirestime', 'integer'],
186+
['tag', 'blob']]
187+
self.assertEqual(res, check, "inventory table not valid")
188+
189+
def test_settings_table_init(self):
190+
"""
191+
Test settings table
192+
"""
193+
res = self.get_table_schema("settings")
194+
check = [['key', 'blob'],
195+
['value', 'blob']]
196+
self.assertEqual(res, check, "settings table not valid")
197+
198+
def test_objectprocessorqueue_table_init(self):
199+
"""
200+
Test objectprocessorqueue table
201+
"""
202+
res = self.get_table_schema("objectprocessorqueue")
203+
check = [['objecttype', 'int'],
204+
['data', 'blob']]
205+
self.assertEqual(res, check, "objectprocessorqueue table not valid")
206+
207+
70208
class TestUpgradeBitmessageDB(TestSqlBase, unittest.TestCase): # pylint: disable=protected-access
71209
"""Test case for SQL versions"""
72210

@@ -104,7 +242,6 @@ def test_bm_db_version_2(self):
104242
"""
105243
Test with version 2
106244
"""
107-
108245
res = self.test_db.cur.execute(''' SELECT count(name) FROM sqlite_master
109246
WHERE type='table' AND name='inventory_backup' ''')
110247
self.assertNotEqual(res, 1, "Table inventory_backup not deleted in versioning 2")
@@ -115,7 +252,6 @@ def test_bm_db_version_3(self):
115252
Test with version 1
116253
Version 1 and 3 are same so will skip 3
117254
"""
118-
119255
res = self.test_db.cur.execute('''PRAGMA table_info('inventory');''')
120256
result = list(filter_table_column(res, "tag"))
121257
self.assertEqual(result, ['tag'], "Data not migrated for version 3")
@@ -125,7 +261,6 @@ def test_bm_db_version_4(self):
125261
"""
126262
Test with version 4
127263
"""
128-
129264
self.test_db.cur.execute("select * from pubkeys where addressversion = '1';")
130265
res = self.test_db.cur.fetchall()
131266
self.assertEqual(len(res), 1, "Table inventory not deleted in versioning 4")
@@ -135,7 +270,6 @@ def test_bm_db_version_5(self):
135270
"""
136271
Test with version 5
137272
"""
138-
139273
self.test_db.cur.execute(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='knownnodes' ''') # noqa
140274
res = self.test_db.cur.fetchall()
141275
self.assertNotEqual(res[0][0], 1, "Table knownnodes not deleted in versioning 5")
@@ -152,7 +286,6 @@ def test_bm_db_version_6(self):
152286
"""
153287
Test with version 6
154288
"""
155-
156289
self.test_db.cur.execute('''PRAGMA table_info('inventory');''')
157290
inventory = self.test_db.cur.fetchall()
158291
inventory = list(filter_table_column(inventory, "expirestime"))
@@ -168,7 +301,6 @@ def test_bm_db_version_7(self):
168301
"""
169302
Test with version 7
170303
"""
171-
172304
self.test_db.cur.execute('''SELECT * FROM pubkeys ''')
173305
pubkeys = self.test_db.cur.fetchall()
174306
self.assertEqual(pubkeys, [], "Data not migrated for version 7")
@@ -186,7 +318,6 @@ def test_bm_db_version_8(self):
186318
"""
187319
Test with version 8
188320
"""
189-
190321
self.test_db.cur.execute('''PRAGMA table_info('inbox');''')
191322
res = self.test_db.cur.fetchall()
192323
result = list(filter_table_column(res, "sighash"))
@@ -197,7 +328,6 @@ def test_bm_db_version_9(self):
197328
"""
198329
Test with version 9
199330
"""
200-
201331
self.test_db.cur.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='pubkeys_backup'") # noqa
202332
res = self.test_db.cur.fetchall()
203333
self.assertNotEqual(res[0][0], 1, "Table pubkeys_backup not deleted")
@@ -207,7 +337,6 @@ def test_bm_db_version_10(self):
207337
"""
208338
Test with version 10
209339
"""
210-
211340
label = "test"
212341
self.test_db.cur.execute("SELECT * FROM addressbook WHERE label='test' ") # noqa
213342
res = self.test_db.cur.fetchall()

0 commit comments

Comments
 (0)