Ejemplo n.º 1
0
    def handle(self, *args, **options):
        # Get products html from site.
        try:
            products_info = ChanelProducts().get_all_products_info()

            if products_info == [] or products_info is None:
                raise Exception("No products info.")

            # Get html per product.
            for product in products_info:
                url = product.get("url", {})

                html = ChanelHtml(url)

                document = ChanelProductDocument(html.get_html_data(url))

                builder = ChanelProductBuilder(document, product)

                # Create product.
                builder.create_all_product_information()

            self.stdout.write(
                self.style.SUCCESS(
                    "Successfully created the Chanel products."))

        except Exception as e:
            self.stdout.write(self.style.ERROR("Opps"))
            self.stdout.write(self.style.ERROR(e))
Ejemplo n.º 2
0
    def test_product_images(self):
        images = ChanelProductDocument.product_images(self)

        assert images != []
        assert images is not None
        self.assertIsInstance(images[0], str)
        self.assertIsInstance(images, list)
Ejemplo n.º 3
0
    def test_products_get_name(self):
        name = ChanelProductDocument.product_name(self)

        assert name != ""
        assert name is not None
        self.assertIsInstance(name, str)
        # TODO: This is obviously very specific based on the static url given above, and both should be generic.
        self.assertEqual(name, "Classic Handbag Lambskin & Gold-Tone Metal")
Ejemplo n.º 4
0
    def test_product_color(self):
        color = ChanelProductDocument.product_color(self)

        assert color != ""
        assert color is not None
        self.assertIsInstance(color, str)
        # TODO: This is obviously very specific based on the static url given above, and both should be generic.
        self.assertEqual(color, "Black")
Ejemplo n.º 5
0
    def test_product_material(self):
        material = ChanelProductDocument.product_material(self)

        assert material != ""
        assert material is not None
        self.assertIsInstance(material, str)
        # TODO: This is obviously very specific based on the static url given above, and both should be generic.
        self.assertEqual(material, "Lambskin & Gold-Tone Metal")
Ejemplo n.º 6
0
    def test_product_currency(self):
        currency = ChanelProductDocument.product_currency(self)

        assert currency != ""
        assert currency is not None
        self.assertIsInstance(currency, str)
        # TODO: This is obviously very specific based on the static url given above, and both should be generic.
        self.assertEqual(currency, "$")
Ejemplo n.º 7
0
    def test_product_amount(self):
        amount = ChanelProductDocument.product_amount(self.html)

        assert amount != ""
        assert amount is not None
        self.assertIsInstance(amount, float)
        # TODO: This is obviously very specific based on the static url given above, and both should be generic.
        self.assertEqual(amount, 6_500)
Ejemplo n.º 8
0
    def test_product_dimensions(self):
        dimensions = ChanelProductDocument.product_dimensions(self.html)

        assert dimensions != ""
        assert dimensions is not None
        self.assertIsInstance(dimensions, str)
        # TODO: This is obviously very specific based on the static url given above, and both should be generic.
        self.assertEqual(dimensions, "6 × 9.9 × 2.5 in")
Ejemplo n.º 9
0
 def setUp(self):
     self.product_info = {
         "url":
         "https://www.chanel.com/us/fashion/p/A01112Y0129594305/classic-handbag-lambskin-gold-tone-metal",
         "id": "A01112Y0129594305",
         "collection_season": "reorders",
     }
     self.html = ChanelHtml.get_html_data(self,
                                          self.product_info.get("url"))
     self.product = ChanelProductDocument(self.html)
Ejemplo n.º 10
0
    def test_products_get_product_html(self):
        title = ChanelProductDocument.page_title(self.html)

        clean_title_words = re.split(r"\W+", title)
        clean_url_words = self.product_info.get("url").split("-")
        del clean_url_words[0]

        for word in clean_url_words:
            word = word.capitalize()

            if word.endswith("quickview"):
                word = word.strip("/quickview")

            if word == "With":
                word = word.lower()

            self.assertIn(word, clean_title_words)