示例#1
0
def filled_basket():
    basket = BasketFactory()
    product1 = ProductFactory()
    product2 = ProductFactory()
    basket.add_product(product1, quantity=10)
    basket.add_product(product2, quantity=20)
    return basket
示例#2
0
 def test_create_line_reference(self):
     basket = BasketFactory()
     product = ProductFactory(title="A product")
     option = OptionFactory(name="product_option", code="product_option")
     option_product = ProductFactory(title='Asunción')
     options = [{'option': option, 'value': option_product}]
     basket.add_product(product, options=options)
示例#3
0
 def test_basket_lines_queryset_is_ordered(self):
     # This is needed to make sure a formset is not performing the query
     # again with an order_by clause (losing all calculated discounts)
     basket = BasketFactory()
     product = ProductFactory(title="A product")
     another_product = ProductFactory(title="Another product")
     basket.add_product(product)
     basket.add_product(another_product)
     queryset = basket.all_lines()
     self.assertTrue(queryset.ordered)
示例#4
0
    def test_description(self):
        basket = BasketFactory()
        product = ProductFactory(title="A product")
        basket.add_product(product)

        line = basket.lines.first()
        self.assertEqual(line.description, "A product")
示例#5
0
    def test_description_with_attributes(self):
        basket = BasketFactory()
        product = ProductFactory(title="A product")
        basket.add_product(product)

        line = basket.lines.first()
        BasketLineAttributeFactory(
            line=line, value='\u2603', option__name='with')
        self.assertEqual(line.description, "A product (with = '\u2603')")
示例#6
0
    def test_doesnt_allow_duplicate_upc(self):
        ProductFactory(parent=None, upc="12345")
        category = CategoryFactory()
        self.assertTrue(Product.objects.get(upc="12345"))

        response = self.submit(title="Nice T-Shirt",
                               category=category,
                               upc="12345")

        self.assertEqual(Product.objects.count(), 1)
        self.assertNotEqual(
            Product.objects.get(upc='12345').title, 'Nice T-Shirt')
        self.assertContains(response, "Product with this UPC already exists.")
示例#7
0
    def setUp(self):
        self.product = ProductFactory()
        self.store1_location = '{"type": "Point", "coordinates": [87.39,12.02]}'
        self.store2_location = '{"type": "Point", "coordinates": [88.39,11.02]}'
        self.store1 = StoreFactory(is_pickup_store=True,
                                   location=self.store1_location)
        self.store2 = StoreFactory(is_pickup_store=True,
                                   location=self.store2_location)

        self.store_stock1 = StoreStockFactory(store=self.store1,
                                              product=self.product)
        self.store_stock1 = StoreStockFactory(store=self.store2,
                                              product=self.product)
示例#8
0
    def test_can_update_a_product_without_stockrecord(self):
        new_title = 'foobar'
        category = CategoryFactory()
        product = ProductFactory(stockrecords=[])

        page = self.get(
            reverse('dashboard:catalogue-product', kwargs={'pk': product.id}))
        form = page.forms[0]
        form['productcategory_set-0-category'] = category.id
        self.assertNotEqual(form['title'].value, new_title)
        form['title'] = new_title
        form.submit()

        try:
            product = Product.objects.get(pk=product.pk)
        except Product.DoesNotExist:
            pass
        else:
            self.assertTrue(product.title == new_title)
            if product.has_stockrecords:
                self.fail('Product has stock records but should not')
示例#9
0
 def setUp(self):
     self.pclass = ProductClassFactory(name='Books', slug='books')
     self.parent = ProductFactory(structure='parent', stockrecords=[])
     super().setUp()