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