Test case for insert method default values

This commit is contained in:
navjot 2020-11-07 16:11:29 +05:30
parent 1bc3fe7b42
commit 0ec15d1d4d
No known key found for this signature in database
GPG Key ID: 9EE70AFD71357F1C
2 changed files with 47 additions and 22 deletions

View File

@ -12,36 +12,36 @@ from helper_sql import sqlExecute
def insert(t, is_testcase=False):
"""Perform an insert into the `sent` table"""
all_fields_availabe = all([True if i else False for i in t])
if not all_fields_availabe:
# pylint: disable=unused-variable
if '' in t or 0 in t:
temp = list(t)
if not temp[0]:
temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid
temp_dict = {
0: uuid.uuid4().bytes, # if msgid is empty the put uuid
7: int(time.time()), # sentTime
8: int(time.time()), # lastActionTime
9: 0, # sleeptill
10: 'msgqueued',
11: 0, # retryNumber
12: 'sent', # folder
13: 2, # encoding
14: BMConfigParser().getint('bitmessagesettings', 'ttl')
}
if not temp[2] or not temp[6]:
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
if not temp[2]:
temp[2] = ripe
temp_dict[2] = ripe
if not temp[6]:
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel)
temp[6] = ackdata
if not temp[7]: # sentTime
temp[7] = int(time.time())
if not temp[8]: # lastActionTime
temp[8] = int(time.time())
if not temp[9] and temp[9] != 0: # sleeptill
temp[9] = 0
if not temp[10]:
temp[10] = 'msgqueued'
if not temp[11] and temp[11] != 0:
temp[11] = 0
if not temp[12]:
temp[12] = 'sent'
if not temp[13]:
temp[13] = 2 # checking encoding
if not temp[14]:
temp[14] = BMConfigParser().getint('bitmessagesettings', 'ttl')
temp_dict[6] = ackdata
for i in dict(enumerate(temp)):
if not temp[i]:
temp[i] = temp_dict[i]
t = tuple(temp)
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
return t if is_testcase else None

View File

@ -265,6 +265,31 @@ class TestCore(unittest.TestCase):
result = helper_sent.insert(t, True)
self.assertNotEqual(result[0], '')
def test_defalut_insert_values(self):
"""Test missing values in insert method for message sending"""
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWgjdfkj89fdf'
message = 'test message'
subject = 'test subject'
t = ('', # msgid
toAddress,
'', # ripe
fromAddress,
subject,
message,
'', # ackdata
'', # sentTime
'', # lastActionTime
'', # sleeptill
'', # status
'', # retryNumber
'', # folder
'', # encoding
'') # ttl
result = helper_sent.insert(t, True)
for index in [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]:
self.assertNotEqual(result[index], '')
def run():
"""Starts all tests defined in this module"""