fixed Own address should not save in address book issue

- removed redundant code

- written test case for address book own address saving

- fixed CQ issues

- added helper_addressbook module

- Fixed CQ issue of src.helper_addressbook module

- fixed travis-ci checks failing issue
This commit is contained in:
navjot 2020-09-08 15:25:26 +05:30
parent 09439b4a0d
commit 42037502ab
No known key found for this signature in database
GPG Key ID: 9EE70AFD71357F1C
3 changed files with 39 additions and 5 deletions

View File

@ -36,6 +36,7 @@ from foldertree import (
import settingsmixin
import support
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
import helper_addressbook
import helper_search
import l10n
from utils import str_broadcast_subscribers, avatarize
@ -2435,12 +2436,14 @@ class MyForm(settingsmixin.SMainWindow):
self.addEntryToAddressBook(address, label)
def addEntryToAddressBook(self, address, label):
if shared.isAddressInMyAddressBook(address):
if address in BMConfigParser().addresses():
"Error: You cannot add your own address in the address book."
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address)
helper_addressbook.insert(label=label, address=address)

src/ Normal file
View File

@ -0,0 +1,11 @@
Insert value into addressbook
from helper_sql import sqlExecute
def insert(address, label):
"""perform insert into addressbook"""
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address)

View File

@ -0,0 +1,20 @@
Tests for addresbook validation
import unittest
from pybitmessage.bmconfigparser import BMConfigParser
class TestAddAddressBook(unittest.TestCase):
"""this class is used for testting add address feature"""
def test_is_own_address_add_to_addressbook(self):
"""Check the logic of TCPConnection.local"""
own_addresses = BMConfigParser().addresses()
if own_addresses:
address = own_addresses[0]
address = 'BM-2cWiUsWMo4Po2UyNB3VyQdF3gxGrDX9gNm'
self.assertTrue(address not in own_addresses)