Esempio n. 1
0
 def test_to_xml(self):
     name, value, unit = "Size", "33", "M"
     p = ParameterFactory(name, value, unit)
     el = p.to_xml()
     expected_el = ET.Element("param", {"name": name, "unit": unit})
     expected_el.text = value
     self.assertElementsEquals(el, expected_el)
Esempio n. 2
0
 def test_to_xml_with_parent(self, p):
     parent_el = mock.MagicMock()
     parent_el.append = mock.MagicMock()
     p.return_value = ET.Element("test")
     base = models.AbstractModel()
     base.to_xml(parent_el)
     self.assertEqual(p.call_count, 1)
     self.assertEqual(parent_el.append.call_count, 1)
Esempio n. 3
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)
Esempio n. 4
0
    def test_to_xml(self):
        f = SimplifiedOfferFactory()
        o = f.create()
        el = o.to_xml()

        values = f.get_values()
        name = values.pop("name")
        expected_el = AbstractOfferFactory(**values).create().to_xml()

        name_el = ET.Element("name")
        name_el.text = name
        expected_el.insert(0, name_el)

        self.assertElementsEquals(el, expected_el)
 def test_to_xml_none_plus_attr(self):
     c = CurrencyFactory(plus=None)
     el = c.to_xml()
     expected_attribs = {"id": c.currency, "rate": c.rate}
     expected_xml = ET.Element("currency", expected_attribs)
     self.assertElementsEquals(el, expected_xml)
 def test_to_xml(self):
     c = CurrencyFactory()
     el = c.to_xml()
     expected_xml = ET.Element("currency", c.to_dict())
     self.assertEqual(ET.tostring(el), ET.tostring(expected_xml))
Esempio n. 7
0
 def test_to_xml(self):
     c = CategoryFactory(parent_id=None)
     el = c.to_xml()
     expected_el = ET.Element("category", {"id": c.category_id})
     expected_el.text = c.name
     self.assertElementsEquals(el, expected_el)
Esempio n. 8
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)
 def test_to_xml(self):
     dim = DimensionsFactory()
     el = dim.to_xml()
     expected_el = ET.Element("dimensions")
     expected_el.text = "/".join([dim._length, dim._width, dim._height])
     self.assertElementsEquals(el, expected_el)
Esempio n. 10
0
 def test_to_xml(self):
     a = AgeFactory()
     el = a.to_xml()
     expected_el = ET.Element("age", {"unit": a.unit})
     expected_el.text = a._value
     self.assertElementsEquals(el, expected_el)
 def test_to_xml(self):
     o = OptionFactory(order_before=None)
     el = o.to_xml()
     expected_el = ET.Element("option", {"cost": o.cost, "days": o.days})
     self.assertElementsEquals(el, expected_el)
Esempio n. 12
0
 def test_to_xml(self):
     p = PriceFactory(is_starting=True)
     el = p.to_xml()
     expected_el = ET.Element("price", {"from": "true"})
     expected_el.text = p._value
     self.assertElementsEquals(el, expected_el)