Test case for insert method default values
This commit is contained in:
parent
1bc3fe7b42
commit
0ec15d1d4d
|
@ -12,36 +12,36 @@ from helper_sql import sqlExecute
|
||||||
|
|
||||||
def insert(t, is_testcase=False):
|
def insert(t, is_testcase=False):
|
||||||
"""Perform an insert into the `sent` table"""
|
"""Perform an insert into the `sent` table"""
|
||||||
all_fields_availabe = all([True if i else False for i in t])
|
# pylint: disable=unused-variable
|
||||||
if not all_fields_availabe:
|
|
||||||
|
if '' in t or 0 in t:
|
||||||
temp = list(t)
|
temp = list(t)
|
||||||
if not temp[0]:
|
temp_dict = {
|
||||||
temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid
|
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]:
|
if not temp[2] or not temp[6]:
|
||||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
|
||||||
if not temp[2]:
|
if not temp[2]:
|
||||||
temp[2] = ripe
|
temp_dict[2] = ripe
|
||||||
|
|
||||||
if not temp[6]:
|
if not temp[6]:
|
||||||
stealthLevel = BMConfigParser().safeGetInt(
|
stealthLevel = BMConfigParser().safeGetInt(
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
temp[6] = ackdata
|
temp_dict[6] = ackdata
|
||||||
if not temp[7]: # sentTime
|
|
||||||
temp[7] = int(time.time())
|
for i in dict(enumerate(temp)):
|
||||||
if not temp[8]: # lastActionTime
|
if not temp[i]:
|
||||||
temp[8] = int(time.time())
|
temp[i] = temp_dict[i]
|
||||||
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')
|
|
||||||
t = tuple(temp)
|
t = tuple(temp)
|
||||||
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||||
return t if is_testcase else None
|
return t if is_testcase else None
|
||||||
|
|
|
@ -265,6 +265,31 @@ class TestCore(unittest.TestCase):
|
||||||
result = helper_sent.insert(t, True)
|
result = helper_sent.insert(t, True)
|
||||||
self.assertNotEqual(result[0], '')
|
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():
|
def run():
|
||||||
"""Starts all tests defined in this module"""
|
"""Starts all tests defined in this module"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user