Exemplo n.º 1
0
    def test_read_data_records(self):
        ipap_message = IpapMessage(1, 1, False)
        template_id = ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        ipap_message.add_field(template_id, 0, 30)

        ipap_data_record = IpapDataRecord(templ_id=template_id)
        ipap_field_value1 = IpapValueField()
        value = 12231213
        ipap_field_value1.set_value_uint64(value)

        # Replace the value
        ipap_data_record.insert_field(0, 30, ipap_field_value1)
        ipap_message.include_data(template_id, ipap_data_record)

        lst = self.ipap_message_parser.read_data_records(
            ipap_message, template_id)
        self.assertEqual(len(lst), 1)

        lst = self.ipap_message_parser.read_data_records(ipap_message, 100)
        self.assertEqual(len(lst), 0)
Exemplo n.º 2
0
    def test_read_template(self):
        ipap_message = IpapMessage(1, 1, False)
        template_id = ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        ipap_message.add_field(template_id, 0, 30)

        ipap_data_record = IpapDataRecord(templ_id=template_id)
        ipap_field_value1 = IpapValueField()
        value = 12231213
        ipap_field_value1.set_value_uint64(value)

        # Replace the value
        ipap_data_record.insert_field(0, 30, ipap_field_value1)
        ipap_message.include_data(template_id, ipap_data_record)

        template = self.ipap_message_parser.read_template(
            ipap_message, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.assertEqual(template.get_type(),
                         TemplateType.IPAP_SETID_AUCTION_TEMPLATE)

        with self.assertRaises(ValueError):
            template = self.ipap_message_parser.read_template(
                ipap_message, TemplateType.IPAP_OPTNS_AUCTION_TEMPLATE)
Exemplo n.º 3
0
class IpapMessageTest(unittest.TestCase):
    """
    IpapMessageTest
    """
    def setUp(self):
        self.ipap_message = IpapMessage(1, 1, False)
        self.ipap_message2 = IpapMessage(1, 1, True)

    def test_new_data_template(self):
        val = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.assertEqual(val, 256)

    def test_add_field(self):
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)

        # test adding an invalid field
        with self.assertRaises(ValueError):
            self.ipap_message.add_field(template_id, 0, 3000)

        # test adding an invalid template id.
        with self.assertRaises(ValueError):
            self.ipap_message.add_field(2, 0, 30)

    def test_delete_template(self):
        print('start test_delete_template')
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)
        self.ipap_message.delete_template(template_id)

        lst = self.ipap_message.get_template_list()
        self.assertEqual(len(lst), 0)

    def test_delete_all_templates(self):
        print('start test_delete_all_templates')
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)
        self.ipap_message.delete_all_templates()
        lst = self.ipap_message.get_template_list()
        self.assertEqual(len(lst), 0)

    def test_get_template_list(self):
        print('start test_get_template_list')
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)
        lst = self.ipap_message.get_template_list()
        self.assertEqual(lst[0], 256)

    def test_get_template_object(self):
        print('start test_get_template_object')
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)

        template = self.ipap_message.get_template_object(template_id)
        template_type = template.get_type()
        self.assertEqual(template_type,
                         TemplateType.IPAP_SETID_AUCTION_TEMPLATE)

        lst = template.get_fields()
        print('num fields:', len(lst))

        with self.assertRaises(ValueError):
            template = self.ipap_message.get_template_object(4)

    def test_include_data(self):
        print('in test_include_data')
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)

        template = self.ipap_message.get_template_object(template_id)
        lst = template.get_fields()

        ipap_data_record = IpapDataRecord(templ_id=template_id)
        ipap_field_value1 = IpapValueField()
        value = 12231213
        ipap_field_value1.set_value_uint64(value)

        template = self.ipap_message.get_template_object(template_id)
        lst = template.get_fields()

        # Replace the value
        ipap_data_record.insert_field(0, 30, ipap_field_value1)
        self.ipap_message.include_data(template_id, ipap_data_record)

        record_size = self.ipap_message.get_data_record_size()
        self.assertEqual(record_size, 1)

    def test_get_data_record_at_pos(self):
        template_id = self.ipap_message.new_data_template(
            10, TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        self.ipap_message.add_field(template_id, 0, 30)

        ipap_data_record = IpapDataRecord(templ_id=template_id)
        ipap_field_value1 = IpapValueField()
        value = 12231213
        ipap_field_value1.set_value_uint64(value)

        # Replace the value
        ipap_data_record.insert_field(0, 30, ipap_field_value1)
        self.ipap_message.include_data(template_id, ipap_data_record)
        ipap_data_record2 = self.ipap_message.get_data_record_at_pos(0)

    def test_import(self):
        print('In test import')
        self.ipap_message2.set_syn(True)
        self.ipap_message2.set_seqno(300)
        self.ipap_message2.output()

        str_msg = self.ipap_message2.get_message()
        ipap_message3 = IpapMessage(1, 1, True, str_msg)

        str_msg = 'aqui estoy'
        with self.assertRaises(ValueError):
            ipap_message4 = IpapMessage(1, 1, True, str_msg)