added checks in helper_sent module
This commit is contained in:
parent
b7d920d529
commit
1bc3fe7b42
|
@ -2,18 +2,46 @@
|
|||
Insert values into sent table
|
||||
"""
|
||||
|
||||
import time
|
||||
import uuid
|
||||
from addresses import decodeAddress
|
||||
from bmconfigparser import BMConfigParser
|
||||
from helper_ackPayload import genAckPayload
|
||||
from helper_sql import sqlExecute
|
||||
|
||||
|
||||
def insert(t):
|
||||
def insert(t, is_testcase=False):
|
||||
"""Perform an insert into the `sent` table"""
|
||||
if not t[0] or not t[-1]:
|
||||
all_fields_availabe = all([True if i else False for i in t])
|
||||
if not all_fields_availabe:
|
||||
temp = list(t)
|
||||
if not t[0]:
|
||||
if not temp[0]:
|
||||
temp[0] = uuid.uuid4().bytes # if msgid is empty the put uuid
|
||||
if not t[-1]:
|
||||
temp[-1] = 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
|
||||
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')
|
||||
t = tuple(temp)
|
||||
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||
return t if is_testcase else None
|
||||
|
|
|
@ -12,15 +12,10 @@ import sys
|
|||
import time
|
||||
import unittest
|
||||
|
||||
import base64
|
||||
import json
|
||||
import xmlrpclib
|
||||
import protocol
|
||||
import state
|
||||
import helper_sent
|
||||
|
||||
from addresses import decodeAddress
|
||||
from helper_ackPayload import genAckPayload
|
||||
from bmconfigparser import BMConfigParser
|
||||
from helper_msgcoding import MsgEncode, MsgDecode
|
||||
from helper_startup import start_proxyconfig
|
||||
|
@ -245,41 +240,30 @@ class TestCore(unittest.TestCase):
|
|||
streams = decoded[7:]
|
||||
self.assertEqual(streams, [1, 2, 3])
|
||||
|
||||
def test_insert_method(self):
|
||||
def test_insert_method_msgid(self):
|
||||
"""Test insert method of helper_sent module with message sending"""
|
||||
api = xmlrpclib.ServerProxy("http://username:password@127.0.0.1:8442/")
|
||||
fromAddress = api.createRandomAddress(base64.encodestring('random_3'))
|
||||
|
||||
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP' # this address is autoresponder address
|
||||
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
|
||||
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWgjdfkj89fdf'
|
||||
message = 'test message'
|
||||
subject = 'test subject'
|
||||
|
||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
|
||||
print('status: ', status)
|
||||
print('addressVersionNumber: ', addressVersionNumber)
|
||||
encoding = 2
|
||||
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
print('ackdata: ', ackdata)
|
||||
t = ('',
|
||||
t = ('', # msgid
|
||||
toAddress,
|
||||
ripe,
|
||||
'', # ripe
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
'', # ackdata
|
||||
int(time.time()), # sentTime
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
0, # sleeptill
|
||||
'msgqueued',
|
||||
0,
|
||||
'sent',
|
||||
encoding,
|
||||
0)
|
||||
helper_sent.insert(t)
|
||||
msg_exist = True if json.loads(
|
||||
api.getSentMessagesByAddress(fromAddress))['sentMessages'] else False
|
||||
self.assertTrue(msg_exist)
|
||||
result = helper_sent.insert(t, True)
|
||||
self.assertNotEqual(result[0], '')
|
||||
|
||||
|
||||
def run():
|
||||
|
|
Reference in New Issue
Block a user