Exemple #1
0
 def get_template_object(self, templ_id: int) -> IpapTemplate:
     obj = lib.ipap_message_get_template_object(self.obj, c_uint16(templ_id))
     if obj:  # not null
         template = IpapTemplate(obj)
         return template
     else:
         raise ValueError("Template with id:{} was not found".format(str(templ_id)))
Exemple #2
0
    def create_bidding_object_template(self, templ_fields: dict,
                                       field_container: IpapFieldContainer,
                                       mandatory_fields: list,
                                       object_type: ObjectType,
                                       templ_type: TemplateType) -> IpapTemplate:
        """
        Create a bidding object template
        :param templ_fields:        Fields to include given by the user
        :param field_container:     Container with all possible fields defined in the ipap_message
        :param mandatory_fields:    Mandatory fields to include given by the template type
        :param object_type:         object type (i.e., bid, allocation)
        :param templ_type:          template's types (data, options)
        :return: a new template
        """
        template_source_id = TemplateIdSource()

        field_keys = self.calculate_template_fields(object_type, templ_type, templ_fields, mandatory_fields)

        # Create the bid template associated with the auction
        template = IpapTemplate()
        template.set_id(template_source_id.new_id())
        template.set_max_fields(len(field_keys))
        template.set_type(templ_type)

        for key in field_keys:
            field_key = field_keys[key]
            self.add_template_field(template, field_container, field_key.get_eno(), field_key.get_ftype())

        return template
Exemple #3
0
 def get_template(self, templid: int) -> IpapTemplate:
     obj = lib.ipap_template_container_get_template(self.obj,
                                                    c_uint16(templid))
     if obj:  # not null
         ipap_template = IpapTemplate(obj=obj)
         return ipap_template
     else:
         raise ValueError('Template {0} not found'.format(str(templid)))
Exemple #4
0
    def test_add_template(self):
        ipap_field = IpapField()
        ipap_field.set_field_type(0, 30, 8, 3, b"campo_1", b"campo_2",
                                  b"campo_3")

        _id = 12
        template = IpapTemplate()
        template.set_id(_id)
        template.set_type(TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        template.add_field(8, UnknownField.KNOWN, True, ipap_field)

        self.template_container.add_template(template)
Exemple #5
0
    def test_delete_all_templates(self):
        ipap_field = IpapField()
        ipap_field.set_field_type(0, 30, 8, 3, b"campo_1", b"campo_2",
                                  b"campo_3")

        _id = 12
        template = IpapTemplate()
        template.set_id(_id)
        template.set_type(TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        template.add_field(8, UnknownField.KNOWN, True, ipap_field)

        self.template_container.add_template(template)
        self.template_container.delete_all_templates()
        val = self.template_container.get_num_templates()
        self.assertEqual(val, 0)
Exemple #6
0
    def setUp(self):

        self.ipap_field_container = IpapFieldContainer()
        self.ipap_field_container.initialize_forward()
        self.ipap_field_container.initialize_reverse()

        self.template = IpapTemplate()
        _id = 2
        self.template.set_id(_id)

        self.ipap_data_record = IpapDataRecord(templ_id=_id)

        self.template.set_type(TemplateType.IPAP_SETID_AUCTION_TEMPLATE)
        ipap_field1 = self.ipap_field_container.get_field(0, 30)
        ipap_field2 = self.ipap_field_container.get_field(0, 32)

        self.template.add_field(ipap_field1.get_length(), UnknownField.KNOWN,
                                True, ipap_field1)
        self.template.add_field(ipap_field2.get_length(), UnknownField.KNOWN,
                                True, ipap_field2)
Exemple #7
0
    def get_template_list(self) -> str:
        """
        Gets the list of templates applicable for the auction.
        :return:list of template ids separated by comma.
        """
        first_time: bool  = True
        template = IpapTemplate()
        ret = ""

        for object_type in range(1, ObjectType.IPAP_MAX_OBJECT_TYPE.value):

            list_templates = template.get_object_template_types(ObjectType(object_type));
            for templ_type in list_templates:
                template_id = self.get_bidding_object_template( ObjectType(object_type), templ_type)
                if first_time:
                    ret = ret + "{0}".format(str(template_id))
                    first_time = False
                else:
                    ret = ret + ",{0}".format(str(template_id))

        return ret
Exemple #8
0
    def create_auction_template(self, field_container, template_type: TemplateType) -> IpapTemplate:
        """
        Create an auction template based on its mandatory fields

        :rtype: IpapTemplate
        :param field_container: container with all possible fields defined
        :param template_type:   Type of template to use.
        :return: template created.
        """
        template_source_id = TemplateIdSource()

        # Create the bid template associated with the auction
        template = IpapTemplate()
        list_fields = template.get_template_type_mandatory_field(template_type)
        template.set_id(template_source_id.new_id())
        template.set_max_fields(len(list_fields))
        template.set_type(template_type)

        for i in range(0, len(list_fields)):
            self.add_template_field(template, field_container, list_fields[i].get_eno(), list_fields[i].get_ftype())

        return template
Exemple #9
0
 def setUp(self):
     self.template = IpapTemplate()
     _id = 12
     self.template.set_id(_id)