From d71900220623e20bf5a3431cf7e30bf4c6d31946 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 4 Oct 2019 23:56:56 +0300 Subject: [PATCH] Test helper_db --- src/tests/core.py | 4 ++++ src/tests/sql.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/tests/sql.py diff --git a/src/tests/core.py b/src/tests/core.py index 400f6315..51f0df9f 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -366,6 +366,10 @@ def run(): qt_tests = loader.loadTestsFromModule(bitmessageqt.tests) suite.addTests(qt_tests) + import sql + sql_tests = loader.loadTestsFromModule(sql) + suite.addTest(sql_tests) + def keep_exc(ex_cls, exc, tb): # pylint: disable=unused-argument """Own exception hook for test cases""" excQueue.put(('tests', exc)) diff --git a/src/tests/sql.py b/src/tests/sql.py new file mode 100644 index 00000000..c2f1d8f1 --- /dev/null +++ b/src/tests/sql.py @@ -0,0 +1,33 @@ +""" +SQL related core tests +""" + +import unittest + +import helper_db + + +class TestSQL(unittest.TestCase): + """A test case for common SQL-related functions""" + test_address_1 = 'BM-2cVRo3WuKL5vDCKq2XJi1yR366nkHgHfcL' + test_address_2 = 'BM-2cVJn1BusL1j4UezuYkvpqNPCr7kCebeLw' + + def test_subscriptions(self): + """Put address into subscriptions and check that it was added""" + self.assertTrue( + helper_db.put_subscriptions('pass_1', self.test_address_1)) + self.assertFalse( + helper_db.put_subscriptions('pass_2', self.test_address_1)) + + helper_db.put_subscriptions('pass_3', self.test_address_2, False) + + for label, addr in helper_db.get_subscriptions(): + if addr == self.test_address_1: + self.assertEqual(label, 'pass_1') + break + else: + self.fail('Could not find added address in subscriptions') + + for label, addr in helper_db.get_subscriptions(): + if addr == self.test_address_2: + self.fail('Got disabled subscription')