Beispiel #1
0
    def prepare_different_items_list(self, rest_client, headers):
        serializer = Serializer()
        url = self.config["global"]["xml_url"]
        xml = rest_client.send_get_binary(url, None, None)
        read_item_list = list()
        if xml[1] != 200:
            logging.info("No file found under the URI: %s, exiting now..." %
                         str(url))
            exit(-1)

        root_item = serializer.deserialize_xml(str(xml[0], "utf8"))
        commodities = root_item

        magento_product_list = list(self.get_product_list(headers)[0]["items"])
        magento_product_dict = dict()

        for magento_product in magento_product_list:
            magento_product_dict[magento_product["sku"]] = magento_product

        for commodity in commodities:
            if commodity[1].text:
                if commodity[1].text in magento_product_dict:
                    magento_product = magento_product_dict[commodity[1].text]
                    result_magento_product = self.link_products(
                        magento_product, commodity)

                    if result_magento_product:
                        read_item_list.append(result_magento_product)
                else:
                    logging.warning(
                        "There is no product of sku {0} in Magento database.".
                        format(commodity[1].text))

        return read_item_list
Beispiel #2
0
    def add_dummy_products(self, rest_client, headers):
        serializer = Serializer()
        xml = rest_client.send_get_binary(self.config["global"]["xml_url"],
                                          None, None)
        root_item = serializer.deserialize_xml(str(xml[0], "utf8"))
        commodities = root_item

        for commodity in commodities:
            product = self.get_dummy_product(commodity)
            json_content = json.dumps(product)
            json_data = rest_client.send_post(
                self.config["global"]["host"] + "/rest/" +
                self.config["global"]["store"] + "/V1/products/", headers,
                json_content)
            if json_data[1] != 200:
                if "message" in dict(json_data[0]):
                    logging.error(json_data[0]["message"])
                else:
                    logging.error(json.dumps(json_data[0]))