Beispiel #1
0
 def test_validity_period(self):
     """
     Should be able to pack and unpack a PDU with a valid validity_period.
     """
     submit_sm = {
         'header': {
             'command_length': 67,
             'command_id': 'submit_sm',
             'command_status': 'ESME_ROK',
             'sequence_number': 0,
         },
         'body': {
             'mandatory_parameters': {
                 'service_type': '',
                 'source_addr_ton': 'international',
                 'source_addr_npi': 'unknown',
                 'source_addr': '',
                 'dest_addr_ton': 'international',
                 'dest_addr_npi': 'unknown',
                 'destination_addr': '',
                 'esm_class': 0,
                 'protocol_id': 0,
                 'priority_flag': 0,
                 'schedule_delivery_time': '',
                 'validity_period': '000001234567800R',
                 'registered_delivery': 0,
                 'replace_if_present_flag': 0,
                 'data_coding': 0,
                 'sm_default_msg_id': 0,
                 'sm_length': 18,
                 'short_message': 'Test Short Message',
             },
         },
     }
     self.assertEqual(pdu.unpack_pdu(pdu.pack_pdu(submit_sm)), submit_sm)
Beispiel #2
0
def create_pdu_asserts():
    pdu_index = 0
    for pdu_ in pdu_objects:
        pdu_index += 1
        pstr = "\n########################################\n"
        pstr += "pdu_json_"
        pstr += ('%010d' % pdu_index)
        pstr += " = '''"
        pstr += prettydump(unpack_pdu(pack_pdu(pdu_)))
        pstr += "'''"
Beispiel #3
0
 def __init__(self, port=2775, credentials={}):
     self.credentials = credentials
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(('', port))
     self.server.listen(1)
     self.conn, self.addr = self.server.accept()
     print 'Connected by', self.addr
     while 1:
         pdu = self._ESME__recv()
         if not pdu:
             break
         self.conn.send(pack_pdu(self.__response(pdu)))
     self.conn.close()
Beispiel #4
0
 def test_pack_unpack_performance(self):
     import platform
     if platform.python_implementation() == "PyPy":
         # Skip this test on pypy, because the JIT warmup time dominates.
         return
     print ''
     """
     Pack & unpack 500 submit_sm PDUs in under 1 second
     """
     submit_sm = {
         'header': {
             'command_length': 0,
             'command_id': 'submit_sm',
             'command_status': 'ESME_ROK',
             'sequence_number': 0,
         },
         'body': {
             'mandatory_parameters': {
                 'service_type': '',
                 'source_addr_ton': 1,
                 'source_addr_npi': 1,
                 'source_addr': '',
                 'dest_addr_ton': 1,
                 'dest_addr_npi': 1,
                 'destination_addr': '',
                 'esm_class': 0,
                 'protocol_id': 0,
                 'priority_flag': 0,
                 'schedule_delivery_time': '',
                 'validity_period': '',
                 'registered_delivery': 0,
                 'replace_if_present_flag': 0,
                 'data_coding': 0,
                 'sm_default_msg_id': 0,
                 'sm_length': 1,
                 'short_message': '',
             },
         },
     }
     start = datetime.now()
     for x in range(500):
         x += 1
         submit_sm['header']['sequence_number'] = x
         sm = 'testing: x = '+str(x)+''
         submit_sm['body']['mandatory_parameters']['short_message'] = sm
         u = pdu.unpack_pdu(pdu.pack_pdu(submit_sm))
     delta = datetime.now() - start
     print '... 500 pack & unpacks in:', delta
     self.assertTrue(delta < timedelta(seconds=1))
Beispiel #5
0
 def test_pack_unpack_pdu_objects(self):
     print ''
     """
     Take a dictionary, pack and unpack it and dump it as JSON correctly
     """
     pdu_index = 0
     for pdu_object in pdu_objects:
         pdu_index += 1
         padded_index = '%010d' % pdu_index
         print '...', padded_index
         str_eval = re.sub('null', 'None', getattr(pdu_asserts, 'pdu_json_' + padded_index))
         self.assertEquals(
             pdu.unpack_pdu(pdu.pack_pdu(pdu_object)),
             eval(str_eval)
         )
Beispiel #6
0
 def test_pack_unpack_pdu_objects(self):
     """
     Take a dictionary, pack and unpack it and dump it as JSON correctly
     """
     pdu_index = 0
     for pdu_ in pdu_objects:
         pdu_index += 1
         padded_index = '%010d' % pdu_index
         self.assertEquals(
             re.sub(
                 '\n *', '',
                 prettydump(unpack_pdu(pack_pdu(pdu_)))),
             re.sub(
                 '\n *', '',
                 eval('pdu_asserts.pdu_json_'+padded_index)))
Beispiel #7
0
 def test_pack_unpack_performance(self):
     """
     Pack & unpack 500 submit_sm PDUs in under 1 second
     """
     submit_sm = {
         'header': {
             'command_length': 0,
             'command_id': 'submit_sm',
             'command_status': 'ESME_ROK',
             'sequence_number': 0,
         },
         'body': {
             'mandatory_parameters': {
                 'service_type': '',
                 'source_addr_ton': 1,
                 'source_addr_npi': 1,
                 'source_addr': '',
                 'dest_addr_ton': 1,
                 'dest_addr_npi': 1,
                 'destination_addr': '',
                 'esm_class': 0,
                 'protocol_id': 0,
                 'priority_flag': 0,
                 'schedule_delivery_time': '',
                 'validity_period': '',
                 'registered_delivery': 0,
                 'replace_if_present_flag': 0,
                 'data_coding': 0,
                 'sm_default_msg_id': 0,
                 'sm_length': 1,
                 'short_message': '',
             },
         },
     }
     start = datetime.now()
     for x in range(500):
         x += 1
         submit_sm['header']['sequence_number'] = x
         sm = 'testing: x = '+str(x)+''
         submit_sm['body']['mandatory_parameters']['short_message'] = sm
         unpack_pdu(pack_pdu(submit_sm))
     delta = datetime.now() - start
     self.assertTrue(delta < timedelta(seconds=1))
Beispiel #8
0
 def test_pack_unpack_of_unicode(self):
     """
     SMPP module should be able to pack & unpack unicode characters
     without a problem
     """
     submit_sm = {
         'header': {
             'command_length': 67,
             'command_id': 'submit_sm',
             'command_status': 'ESME_ROK',
             'sequence_number': 0,
         },
         'body': {
             'mandatory_parameters': {
                 'service_type': '',
                 'source_addr_ton': 'international',
                 'source_addr_npi': 'unknown',
                 'source_addr': '',
                 'dest_addr_ton': 'international',
                 'dest_addr_npi': 'unknown',
                 'destination_addr': '',
                 'esm_class': 0,
                 'protocol_id': 0,
                 'priority_flag': 0,
                 'schedule_delivery_time': '',
                 'validity_period': '',
                 'registered_delivery': 0,
                 'replace_if_present_flag': 0,
                 'data_coding': 0,
                 'sm_default_msg_id': 0,
                 'sm_length': 34,
                 'short_message':
                     u'Vumi says: أبن الشرموطة'.encode('utf-8'),
             },
         },
     }
     self.assertDictEquals(
         hex_to_named(submit_sm),
         unpack_pdu(pack_pdu(submit_sm))
     )
Beispiel #9
0
 def test_ignore_invalid_null_after_short_message_field(self):
     """
     At least one provider sends us an invalid deliver_sm PDU with a null
     byte after the short_message field.
     """
     deliver_sm = {
         'header': {
             'command_length': 0,
             'command_id': 'deliver_sm',
             'command_status': 'ESME_ROK',
             'sequence_number': 0,
         },
         'body': {
             'mandatory_parameters': {
                 'service_type': '',
                 'source_addr_ton': 1,
                 'source_addr_npi': 1,
                 'source_addr': '',
                 'dest_addr_ton': 1,
                 'dest_addr_npi': 1,
                 'destination_addr': '',
                 'esm_class': 0,
                 'protocol_id': 0,
                 'priority_flag': 0,
                 'schedule_delivery_time': '',
                 'validity_period': '',
                 'registered_delivery': 0,
                 'replace_if_present_flag': 0,
                 'data_coding': 0,
                 'sm_default_msg_id': 0,
                 'sm_length': 1,
                 'short_message': 'test',
             },
         },
     }
     packed_pdu = pdu.pack_pdu(deliver_sm)
     unpacked_pdu = pdu.unpack_pdu(packed_pdu)
     unpacked_dodgy_pdu = pdu.unpack_pdu(packed_pdu + '\x00')
     self.assertEqual(unpacked_pdu, unpacked_dodgy_pdu)
Beispiel #10
0
 def test_pack_unpack_of_ascii_and_unicode_8_16_32(self):
     """
     SMPP module should be able to pack & unpack unicode characters
     without a problem
     """
     submit_sm = {
         'header': {
             'command_length': 65,
             'command_id': 'submit_sm',
             'command_status': 'ESME_ROK',
             'sequence_number': 0,
         },
         'body': {
             'mandatory_parameters': {
                 'service_type': '',
                 'source_addr_ton': 'international',
                 'source_addr_npi': 'unknown',
                 'source_addr': '',
                 'dest_addr_ton': 'international',
                 'dest_addr_npi': 'unknown',
                 'destination_addr': '',
                 'esm_class': 0,
                 'protocol_id': 0,
                 'priority_flag': 0,
                 'schedule_delivery_time': '',
                 'validity_period': '',
                 'registered_delivery': 0,
                 'replace_if_present_flag': 0,
                 'data_coding': 0,
                 'sm_default_msg_id': 0,
                 'sm_length': 32,
                 'short_message': u'a \xf0\x20\u0373\u0020\u0433\u0020\u0533\u0020\u05f3\u0020\u0633\u0020\u13a3\u0020\u16a3 \U0001f090'.encode('utf-8'),
             },
         },
     }
     self.assertDictEquals(
         hex_to_named(submit_sm),
         pdu.unpack_pdu(pdu.pack_pdu(submit_sm))
     )
Beispiel #11
0
 def get_bin(self):
     return pack_pdu(self.obj)