From 2f5d6214ffd4259774e775379ba2017f80c6674d Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sun, 7 Feb 2021 21:15:59 +0200 Subject: [PATCH] Move addressbook test to bitmessageqt.tests because it uses Qt --- src/bitmessageqt/tests/__init__.py | 3 ++- src/bitmessageqt/tests/addressbook.py | 17 +++++++++++++ src/helper_addressGenerator.py | 35 --------------------------- src/tests/core.py | 9 ------- 4 files changed, 19 insertions(+), 45 deletions(-) create mode 100644 src/bitmessageqt/tests/addressbook.py delete mode 100644 src/helper_addressGenerator.py diff --git a/src/bitmessageqt/tests/__init__.py b/src/bitmessageqt/tests/__init__.py index 199438f9..69766014 100644 --- a/src/bitmessageqt/tests/__init__.py +++ b/src/bitmessageqt/tests/__init__.py @@ -1,6 +1,7 @@ """bitmessageqt tests""" +from addressbook import TestAddressbook from main import TestMain, TestUISignaler from support import TestSupport -__all__ = ["TestMain", "TestSupport", "TestUISignaler"] +__all__ = ["TestAddressbook", "TestMain", "TestSupport", "TestUISignaler"] diff --git a/src/bitmessageqt/tests/addressbook.py b/src/bitmessageqt/tests/addressbook.py new file mode 100644 index 00000000..cd86c5d6 --- /dev/null +++ b/src/bitmessageqt/tests/addressbook.py @@ -0,0 +1,17 @@ +import helper_addressbook +from bitmessageqt.support import createAddressIfNeeded + +from main import TestBase + + +class TestAddressbook(TestBase): + """Test case for addressbook""" + + def test_add_own_address_to_addressbook(self): + """Checking own address adding in addressbook""" + try: + address = createAddressIfNeeded(self.window) + self.assertFalse( + helper_addressbook.insert(label='test', address=address)) + except IndexError: + self.fail("Can't generate addresses") diff --git a/src/helper_addressGenerator.py b/src/helper_addressGenerator.py deleted file mode 100644 index 39e96fd0..00000000 --- a/src/helper_addressGenerator.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -Create random address -""" - -import time -import defaults -import queues -import state - -from bmconfigparser import BMConfigParser - - -def checkHasNormalAddress(): - """method for checking address""" - for address in BMConfigParser().addresses(): - - if BMConfigParser().safeGetBoolean(address, 'enabled'): - return address - return False - - -def createAddressIfNeeded(label_text, streamNumberForAddress=1): - """method for creating random address""" - if not checkHasNormalAddress(): - queues.addressGeneratorQueue.put(( - 'createRandomAddress', 4, streamNumberForAddress, - label_text, - 1, "", False, - defaults.networkDefaultProofOfWorkNonceTrialsPerByte, - defaults.networkDefaultPayloadLengthExtraBytes - )) - start_time = time.time() - while int(time.time() - start_time) < 10 and state.shutdown == 0 and not checkHasNormalAddress(): - time.sleep(.2) - return checkHasNormalAddress() diff --git a/src/tests/core.py b/src/tests/core.py index 7fb6a9c0..400f6315 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -343,15 +343,6 @@ class TestCore(unittest.TestCase): 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""" - from helper_addressGenerator import createAddressIfNeeded - try: - address = createAddressIfNeeded('test1') - self.assertFalse(helper_addressbook.insert(label='test', address=address)) - except IndexError: - self.fail("Can't generate addresses") - def test_adding_two_same_case_sensitive_addresses(self): """Testing same case sensitive address store in addressbook""" address1 = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP'