Written test case for helper_sent.insert method

This commit is contained in:
navjot 2020-11-04 20:39:29 +05:30
parent e60d12ddbf
commit 0023fc4b3d
No known key found for this signature in database
GPG Key ID: 9EE70AFD71357F1C
2 changed files with 37 additions and 2 deletions

View File

@ -12,10 +12,8 @@ def insert(t):
if not t[0] or not t[-1]: if not t[0] or not t[-1]:
temp = list(t) temp = list(t)
if not t[0]: if not t[0]:
print('zero index is not available')
temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid
if not t[-1]: if not t[-1]:
print('Lasr index is not available')
temp[-1] = BMConfigParser().getint('bitmessagesettings', 'ttl') temp[-1] = BMConfigParser().getint('bitmessagesettings', 'ttl')
t = tuple(temp) t = tuple(temp)
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)

View File

@ -238,6 +238,43 @@ class TestCore(unittest.TestCase):
streams = decoded[7:] streams = decoded[7:]
self.assertEqual(streams, [1, 2, 3]) self.assertEqual(streams, [1, 2, 3])
def test_insert_method(self):
"""Test insert method of helper_sent module with message sending"""
import helper_sent
from addresses import decodeAddress
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP' # this address is autoresponder address
message = 'test message'
subject = 'test subject'
fromAddress = 'BM-2cVdyaMNhYfnw8j1SDPW3QBhjzKzP9vtdp' # here use your own address for testing
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress)
encoding = 2
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel)
print('ackdata: ', ackdata)
t = ('',
toAddress,
ripe,
fromAddress,
subject,
message,
ackdata,
int(time.time()), # sentTime
int(time.time()), # lastActionTime
0,
'msgqueued',
0,
'sent',
encoding,
0)
helper_sent.insert(t)
self.assertTrue(True)
def run(): def run():
"""Starts all tests defined in this module""" """Starts all tests defined in this module"""