Пример #1
0
    def test_to_xml(self):
        f = AbstractBookOfferFactory()
        o = f.create()
        el = o.to_xml()

        # Get arbitrary offer values
        values = f.get_values()
        book_offer_values = {}
        for k in self.KEYS:
            book_offer_values[k] = values.pop(k)

        # Change offer type for AbstractOffer cls and create base element
        expected_el = AbstractOfferFactory(**values).create().to_xml()

        for tag, attr in (
            ("name", "name"),
            ("publisher", "publisher"),
            ("ISBN", "isbn"),
            ("author", "author"),
            ("series", "series"),
            ("year", "year"),
            ("volume", "volume"),
            ("part", "part"),
            ("language", "language"),
            ("table_of_contents", "table_of_contents"),
        ):
            el_ = ET.SubElement(expected_el, tag)
            el_.text = str(book_offer_values[attr])

        self.assertElementsEquals(el, expected_el)
Пример #2
0
    def test_to_xml(self):
        c = ConditionFactory()
        el = c.to_xml()

        expected_el = ET.Element("condition", {"type": c.condition_type})
        reason_el = ET.SubElement(expected_el, "reason")
        reason_el.text = c.reason

        self.assertElementsEquals(el, expected_el)
Пример #3
0
    def test_to_xml(self):
        f = BookOfferFactory()
        o = f.create()
        el = o.to_xml()

        # Get values and pop book values
        values = f.get_values()
        values.pop("binding")
        values.pop("page_extent")

        # Change __TYPE__ to "book"
        AbstractBookOfferFactory.__cls__.__TYPE__ = BookOffer.__TYPE__
        abstract_offer = AbstractBookOfferFactory(**values).create()

        # Create expected element manually
        expected_el = abstract_offer.to_xml()
        binding_el = ET.SubElement(expected_el, "binding")
        binding_el.text = o.binding
        page_extent_el = ET.SubElement(expected_el, "page_extent")
        page_extent_el.text = o._page_extent

        self.assertElementsEquals(el, expected_el)
Пример #4
0
    def test_to_xml(self):
        f = ArbitraryOfferFactory()
        o = f.create()
        el = o.to_xml()

        # Get arbitrary offer values
        values = f.get_values()
        model = values.pop("model")
        type_prefix = values.pop("type_prefix")

        # Change offer type for AbstractOffer cls and create base element
        AbstractOfferFactory.__cls__.__TYPE__ = ArbitraryOffer.__TYPE__
        expected_el = AbstractOfferFactory(**values).create().to_xml()

        # Add model
        model_el = ET.SubElement(expected_el, "model")
        model_el.text = model

        # Add typePrefix
        type_prefix_el = ET.SubElement(expected_el, "typePrefix")
        type_prefix_el.text = type_prefix

        self.assertElementsEquals(el, expected_el)
Пример #5
0
    def test_to_xml(self):
        f = AudioBookOfferFactory()
        o = f.create()
        el = o.to_xml()

        values = f.get_values()
        audio_book_values = {}
        for k in self.MAPPING.keys():
            audio_book_values[k] = values.pop(k)

        AbstractBookOfferFactory.__cls__.__TYPE__ = AudioBookOffer.__TYPE__
        expected_el = AbstractBookOfferFactory(**values).create().to_xml()

        for k, tag in self.MAPPING.items():
            el_ = ET.SubElement(expected_el, tag)
            el_.text = audio_book_values[k]

        self.assertElementsEquals(el, expected_el)
Пример #6
0
    def test_to_xml(self):
        o = AbstractOfferFactory().create()
        el = o.to_xml()

        attributes = {"id": o.offer_id, "bid": o.bid}
        if o._available is not None:
            attributes["available"] = o._available

        expected_el = ET.Element("offer", attributes)

        for tag, attr in (
            ("vendor", "vendor"),
            ("vendorCode", "vendor_code"),
            ("url", "url"),
            ("oldprice", "old_price"),
            ("enable_auto_discounts", "_enable_auto_discounts"),
            ("currencyId", "currency"),
            ("categoryId", "category_id"),
            ("delivery", "_delivery"),
            ("pickup", "_pickup"),
            ("store", "_store"),
            ("description", "description"),
            ("sales_notes", "sales_notes"),
            ("min-quantity", "_min_quantity"),
            ("manufacturer_warranty", "_manufacturer_warranty"),
            ("country_of_origin", "country_of_origin"),
            ("adult", "_adult"),
            ("expiry", "_expiry"),
            ("weight", "_weight"),
            ("downloadable", "_downloadable"),
            ("group_id", "_group_id"),
        ):
            v = getattr(o, attr)
            if v:
                el_ = ET.SubElement(expected_el, tag)
                el_.text = getattr(o, attr)

        # Add price
        o.price.to_xml(expected_el)

        # Add pictures
        for url in o.pictures:
            el_ = ET.SubElement(expected_el, "picture")
            el_.text = url

        ET.SubElement(expected_el, "supplier", {"ogrn": o.supplier})

        # Add delivery options
        delivery_options_el = ET.SubElement(expected_el, "delivery-options")
        for _ in o.delivery_options:
            _.to_xml(delivery_options_el)

        # Add pickup options
        pickup_options_el = ET.SubElement(expected_el, "pickup-options")
        for _ in o.pickup_options:
            _.to_xml(pickup_options_el)

        # Add barcodes
        for barcode in o.barcodes:
            el_ = ET.SubElement(expected_el, "barcode")
            el_.text = barcode

        # Add parameters
        for _ in o.parameters:
            _.to_xml(expected_el)

        # Add condition
        o.condition.to_xml(expected_el)

        # Add credit template
        ET.SubElement(expected_el, "credit-template",
                      {"id": o.credit_template_id})

        # Add dimensions
        o.dimensions.to_xml(expected_el)

        # Add age
        o.age.to_xml(expected_el)

        if o._available is not None:
            self.assertEqual(el.attrib.get("available"), o._available)
        self.assertElementsEquals(el, expected_el)