Commit 398b1c03 authored by Lukas Baca's avatar Lukas Baca
Browse files

44 add tests to class

parent 944d9436
from common import * from common import *
DTN_TIME = 606658292 class TestCommon(object):
UNIX_TIME = 1553343092
def test_time_conversion(): DTN_TIME = 606658292
assert unix2dtn(UNIX_TIME) == DTN_TIME UNIX_TIME = 1553343092
assert dtn2unix(DTN_TIME) == UNIX_TIME
DATA = 1023 def test_time_conversion(self):
ENCODED_DATA = b'\x87\x7f' assert unix2dtn(self.UNIX_TIME) == self.DTN_TIME
assert dtn2unix(self.DTN_TIME) == self.UNIX_TIME
def test_encode(): DATA = 1023
ENCODED_DATA = b'\x87\x7f'
assert sdnv_encode(DATA) == ENCODED_DATA def test_encode(self):
assert sdnv_encode(self.DATA) == self.ENCODED_DATA
DATA_READ = [ 0x12, 0x11, 0x10, 0x09]; DATA_READ = [ 0x12, 0x11, 0x10, 0x09];
def test_read(): def test_read(self):
assert sdnv_read(DATA_READ,2) == (16, 3) assert sdnv_read(self.DATA_READ,2) == (16, 3)
SERIAL_RESPONSE =b'\x9f\x89\x07\x00\x01\x82\x01etest2\x82\x01dtest\x82\x01\x00\x82\x1a$(\xde\xf4\x00\x19\x01,B%r\x87\t\x01\x00\x02\x04\x82\x18\x1e\x00D]}\xd8u\x87\x08\x02\x00\x02\x01\x00D\x98\x9d\x838\x87\x01\x00\x00\x02\x02aHDF\xa27\x80\xff' SERIAL_RESPONSE =b'\x9f\x89\x07\x00\x01\x82\x01etest2\x82\x01dtest\x82\x01\x00\x82\x1a$(\xde\xf4\x00\x19\x01,B%r\x87\t\x01\x00\x02\x04\x82\x18\x1e\x00D]}\xd8u\x87\x08\x02\x00\x02\x01\x00D\x98\x9d\x838\x87\x01\x00\x00\x02\x02aHDF\xa27\x80\xff'
SERIAL_TCPCL_RESPONSE = b'\x13M\x9f\x89\x07\x00\x01\x82\x01etest2\x82\x01dtest\x82\x01\x00\x82\x1a$(\xde\xf4\x00\x19\x01,B%r\x87\t\x01\x00\x02\x04\x82\x18\x1e\x00D]}\xd8u\x87\x08\x02\x00\x02\x01\x00D\x98\x9d\x838\x87\x01\x00\x00\x02\x02aHDF\xa27\x80\xff' SERIAL_TCPCL_RESPONSE = b'\x13M\x9f\x89\x07\x00\x01\x82\x01etest2\x82\x01dtest\x82\x01\x00\x82\x1a$(\xde\xf4\x00\x19\x01,B%r\x87\t\x01\x00\x02\x04\x82\x18\x1e\x00D]}\xd8u\x87\x08\x02\x00\x02\x01\x00D\x98\x9d\x838\x87\x01\x00\x00\x02\x02aHDF\xa27\x80\xff'
def test_serialize(): def test_serialize(self):
bundle = serialize_bundle(
bundle = serialize_bundle(
"dtn:test", "dtn:test",
"dtn:test2", "dtn:test2",
"H", "H",
NULL_EID, NULL_EID,
UNIX_TIME self.UNIX_TIME
) )
assert bundle == SERIAL_RESPONSE assert bundle == self.SERIAL_RESPONSE
result = serialize_tcpcl_single_bundle_segment(bundle) result = serialize_tcpcl_single_bundle_segment(bundle)
assert result == SERIAL_TCPCL_RESPONSE assert result == self.SERIAL_TCPCL_RESPONSE
START_OFFSET = 4572 START_OFFSET = 4572
END_OFFSET = 12512 END_OFFSET = 12512
CONTACT = (606671843, 606679783, 500) CONTACT = (606671843, 606679783, 500)
SERIAL_UPCN_CONFIG_RESPONSE = b'1(dtn:pyDTN-2.dtn):(172.25.0.12:2002)::[{606671843,606679783,500}];' SERIAL_UPCN_CONFIG_RESPONSE = b'1(dtn:pyDTN-2.dtn):(172.25.0.12:2002)::[{606671843,606679783,500}];'
def test_serialize_config(): def test_serialize_config(self):
result = serialize_upcn_config_message( result = serialize_upcn_config_message(
"dtn:pyDTN-2.dtn", "dtn:pyDTN-2.dtn",
"172.25.0.12:2002", "172.25.0.12:2002",
contacts=[ contacts=[
CONTACT, self.CONTACT,
], ],
) )
assert result == SERIAL_UPCN_CONFIG_RESPONSE assert result == self.SERIAL_UPCN_CONFIG_RESPONSE
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment