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:
parent
8763c80bad
commit
4e1990b63e
|
@ -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):
|
|||
))
|
||||
return
|
||||
|
||||
self.addEntryToAddressBook(address, label)
|
||||
|
||||
def addEntryToAddressBook(self, address, label):
|
||||
if shared.isAddressInMyAddressBook(address):
|
||||
if address in BMConfigParser().addresses():
|
||||
self.updateStatusBar(_translate(
|
||||
"MainWindow",
|
||||
"Error: You cannot add your own address in the address book."
|
||||
))
|
||||
return
|
||||
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address)
|
||||
|
||||
helper_addressbook.insert(label=label, address=address)
|
||||
self.rerenderMessagelistFromLabels()
|
||||
self.rerenderMessagelistToLabels()
|
||||
self.rerenderAddressBook()
|
||||
|
|
11
src/helper_addressbook.py
Normal file
11
src/helper_addressbook.py
Normal 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)
|
20
src/tests/test_addressbook.py
Normal file
20
src/tests/test_addressbook.py
Normal 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]
|
||||
else:
|
||||
address = 'BM-2cWiUsWMo4Po2UyNB3VyQdF3gxGrDX9gNm'
|
||||
|
||||
self.assertTrue(address not in own_addresses)
|
Loading…
Reference in New Issue
Block a user