def test_displays_all_products(self):
        product1 = Product()
        product1.name = 'Product 1'
        product1.category = 'Category 1'
        product1.description = 'Description 1'
        product1.price = 100.00
        product1.save()

        product2 = Product()
        product2.name = 'Product 2'
        product2.category = 'Category 1'
        product2.description = 'Description 1'
        product2.price = 100.00
        product2.save()

        response = self.client.get('/')

        self.assertContains(response, 'Product 1')
        self.assertContains(response, 'Product 2')
示例#2
0
    def test_displays_all_products(self):
        product1 = Product()
        product1.name = 'Product 1'
        product1.category = 'Category 1'
        product1.description = 'Description 1'
        product1.price = 100.00
        product1.save()

        product2 = Product()
        product2.name = 'Product 2'
        product2.category = 'Category 1'
        product2.description = 'Description 1'
        product2.price = 100.00
        product2.save()

        response = self.client.get('/')

        self.assertContains(response, 'Product 1')
        self.assertContains(response, 'Product 2')
    def test_saving_and_retrieving_products(self):
        first_product = Product()
        first_product.name = 'Product 1'
        first_product.category = 'Category 1'
        first_product.description = 'Description 1'
        first_product.price = 100.00
        first_product.save()

        second_product = Product()
        second_product.name = 'Product 2'
        second_product.category = 'Category 2'
        second_product.description = 'Description 2'
        second_product.price = 200.00
        second_product.save()

        saved_products = Product.objects.all()
        self.assertEqual(saved_products.count(), 2)

        first_saved_product = saved_products[0]
        second_saved_product = saved_products[1]
        self.assertEqual(first_saved_product.name, 'Product 1')
        self.assertEqual(second_saved_product.name, 'Product 2')
示例#4
0
    def test_saving_and_retrieving_products(self):
        first_product = Product()
        first_product.name = 'Product 1'
        first_product.category = 'Category 1'
        first_product.description = 'Description 1'
        first_product.price = 100.00
        first_product.save()

        second_product = Product()
        second_product.name = 'Product 2'
        second_product.category = 'Category 2'
        second_product.description = 'Description 2'
        second_product.price = 200.00
        second_product.save()

        saved_products = Product.objects.all()
        self.assertEqual(saved_products.count(), 2)

        first_saved_product = saved_products[0]
        second_saved_product = saved_products[1]
        self.assertEqual(first_saved_product.name, 'Product 1')
        self.assertEqual(second_saved_product.name, 'Product 2')