예제 #1
0
    def setUp(self):
        '''
        Creates the Database and one user for tests.
        '''

        i = 1
        while i <= 20:

            c = Categorys(category="category", )
            c.save()
            if 1 <= 10:
                p = Products(
                    product="123456" + str(i),
                    nutrition_grade_fr=1,
                    product_name_fr="Product" + str(i),
                    ingredients_text_fr="Ingredients" + str(i),
                    product_image_large="Product_img_l" + str(i),
                    product_image_small="Product_img_s" + str(i),
                    product_image_nutrition_large="Product_img_n_l" + str(i),
                    product_image_nutrition_small="Product_img_n_s" + str(i),
                    stores="Stores" + str(i),
                    url="Url" + str(i),
                )

                cat = Categorys.objects.get(category="category")
                p.category = cat
                p.save()
            else:
                p = Products(
                    product="123456" + str(i),
                    nutrition_grade_fr=2,
                    product_name_fr="Product" + str(i),
                    ingredients_text_fr="Ingredients" + str(i),
                    product_image_large="Product_img_l" + str(i),
                    product_image_small="Product_img_s" + str(i),
                    product_image_nutrition_large="Product_img_n_l" + str(i),
                    product_image_nutrition_small="Product_img_n_s" + str(i),
                    stores="Stores" + str(i),
                    url="Url" + str(i),
                )

                cat = Categorys.objects.get(category="category")
                p.category = cat
                p.save()
            i += 1

        user = CustomUser.objects.create(email="*****@*****.**",
                                         first_name="first_name",
                                         second_name="second_name",
                                         password="******")

        user = CustomUser.objects.get(email=user)
        chosen_product = Products.objects.get(product="1234561")
        remplacement_product = Products.objects.get(product="1234562")

        history = History.objects.create(
            user=user,
            chosen_product=chosen_product,
            remplacement_product=remplacement_product)
예제 #2
0
    def test_results_page_shows(self):
        '''
        Tests the search page, and the products page.
        '''
        i = 1
        while i <= 20:
            
            c = Categorys(
                category="category",
            )
            c.save()
            if 1 <= 10:
                p = Products(
                    product="123456"+str(i),
                    nutrition_grade_fr= 1,
                    product_name_fr="Product"+str(i),
                    ingredients_text_fr="Ingredients"+str(i),
                    product_image_large="Product_img_l"+str(i),
                    product_image_small="Product_img_s"+str(i),
                    product_image_nutrition_large="Product_img_n_l"+str(i),
                    product_image_nutrition_small="Product_img_n_s"+str(i),
                    stores="Stores"+str(i),
                    url="Url"+str(i),
                    )
                
                cat = Categorys.objects.get(category="category")
                p.category = cat
                p.save()
            else:
                p = Products(
                    product="123456"+str(i),
                    nutrition_grade_fr= 2,
                    product_name_fr="Product"+str(i),
                    ingredients_text_fr="Ingredients"+str(i),
                    product_image_large="Product_img_l"+str(i),
                    product_image_small="Product_img_s"+str(i),
                    product_image_nutrition_large="Product_img_n_l"+str(i),
                    product_image_nutrition_small="Product_img_n_s"+str(i),
                    stores="Stores"+str(i),
                    url="Url"+str(i),
                    )
                
                cat = Categorys.objects.get(category="category")
                p.category = cat
                p.save()
            i += 1

        self.driver.get(self.live_server_url)
        self.driver.find_element_by_id("searchForm").send_keys('Product')
        self.driver.find_element_by_id("searchForm").submit()

        
        self.assertTrue(self.driver.title == 'Page Products')
    def setUp(self):
        cat = Categorys.objects.create(category="test1")
        p = Products(
            product="123456",
            nutrition_grade_fr=1,
            product_name_fr="Product",
            ingredients_text_fr="Ingredients",
            product_image_large="Product_img_l",
            product_image_small="Product_img_s",
            product_image_nutrition_large="Product_img_n_l",
            product_image_nutrition_small="Product_img_n_s",
            stores="Stores",
            url="Url",
        )

        cat = Categorys.objects.get(category="test1")
        p.category = cat
        p.save()
예제 #4
0
    def handle(self, *args, **options):

        help = "Insert all products an relations in the models tables."

        print("Debout du travail!...")

        DataFiles.download_and_clean_all_products(DataFiles)

        products_to_insert = DataFiles.products_to_inser

        print(
            "Nous avons ",
            len(products_to_insert),
            "produits téléchargées et nettoyées!",
        )

        print("Insértion de tous les produits dans la base de données!")

        try:
            for data_dict in products_to_insert:
                c = Categorys(category=data_dict["category"])
                c.save()

                if data_dict["nutrition_grade_fr"] == "a":
                    nut = 1
                if data_dict["nutrition_grade_fr"] == "b":
                    nut = 2
                if data_dict["nutrition_grade_fr"] == "c":
                    nut = 3
                if data_dict["nutrition_grade_fr"] == "d":
                    nut = 4
                if data_dict["nutrition_grade_fr"] == "e":
                    nut = 5

                p = Products(
                    product=str(data_dict["product"]),
                    nutrition_grade_fr=nut,
                    product_name_fr=data_dict["product_name_fr"],
                    ingredients_text_fr=data_dict["ingredients_text_fr"],
                    product_image_large=data_dict["product_image_large"],
                    product_image_small=data_dict["product_image_small"],
                    product_image_nutrition_large=data_dict[
                        "product_image_nutrition_large"
                    ],
                    product_image_nutrition_small=data_dict[
                        "product_image_nutrition_small"
                    ],
                    stores=data_dict["stores"],
                    url=data_dict["url"],
                )

                cat = Categorys.objects.get(category=data_dict["category"])
                p.category = cat
                p.save()

        except:
            raise CommandError(
                "Ups une erreur est arrivé, insertion aborté!! sur le produit",
                p.product_name_fr,
            )

        self.stdout.write(
            self.style.SUCCESS(
                "Les produits sont, à present, sauvegardées dans la base de données!"
            )
        )