Ejemplo n.º 1
0
    def test_changing_product_is_prohibited(self):
        ps = ProductStockFactory(type='added')

        ps.product = ProductFactory()

        with self.assertRaises(AssertionError):
            ps.save()
Ejemplo n.º 2
0
    def test_changing_amount_is_prohibited(self):
        ps = ProductStockFactory()

        ps.amount += 1

        with self.assertRaises(AssertionError):
            ps.save()
Ejemplo n.º 3
0
    def test_changing_product_is_prohibited(self):
        ps = ProductStockFactory(type='added')

        ps.product = ProductFactory()

        with self.assertRaises(AssertionError):
            ps.save()
Ejemplo n.º 4
0
 def test_is_available_on_stock_product_2(self):
     OrderRoundFactory()
     product = ProductFactory(order_round=None)
     ProductStockFactory(product=product, amount=5)
     ProductStockFactory(product=product, amount=4)
     OrderProductFactory(product=product, amount=9, order__paid=True)
     self.assertFalse(product.is_available)
Ejemplo n.º 5
0
    def test_changing_amount_is_prohibited(self):
        ps = ProductStockFactory()

        ps.amount += 1

        with self.assertRaises(AssertionError):
            ps.save()
Ejemplo n.º 6
0
 def test_amount_available_with_stock_1(self):
     product = ProductFactory(maximum_total_order=None, order_round=None)
     stock1 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     stock2 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     self.assertEqual(product.amount_available,
                      (stock1.amount + stock2.amount))
Ejemplo n.º 7
0
 def test_verbose_availability_with_stock_2(self):
     product = ProductFactory(order_round=None)
     stock1 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     stock2 = ProductStockFactory(product=product,
                                  type=ProductStock.TYPE_ADDED)
     self.assertEqual(product.verbose_availability(),
                      "%s in voorraad" % (stock1.amount + stock2.amount))
Ejemplo n.º 8
0
    def test_verbose_availability_with_stock_3(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock1 = ProductStockFactory(product=product,
                                     type=ProductStock.TYPE_ADDED)
        stock2 = ProductStockFactory(product=product,
                                     type=ProductStock.TYPE_ADDED)
        odp1 = OrderProductFactory(product=product, amount=1, order__paid=True)

        self.assertEqual(
            product.verbose_availability(),
            "%s in voorraad" % ((stock1.amount + stock2.amount) - odp1.amount))
Ejemplo n.º 9
0
    def test_amount_available_with_stock_2(self):
        product = ProductFactory(maximum_total_order=None, order_round=None)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=10)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=20),
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_LOST,
                            amount=5),

        self.assertEqual(product.amount_available, 25)
Ejemplo n.º 10
0
    def test_verbose_availability_with_stock_4(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=10)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_ADDED,
                            amount=5)
        ProductStockFactory(product=product,
                            type=ProductStock.TYPE_LOST,
                            amount=3)
        OrderProductFactory(product=product, amount=1, order__paid=True)

        self.assertEqual(product.verbose_availability(), "11 in voorraad")
Ejemplo n.º 11
0
    def test_that_stock_product_amount_is_decreased(self):
        # 10 available
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product, amount=10)
        self.assertEqual(10, product.amount_available)

        order1 = OrderFactory(order_round=self.round,
                              finalized=True,
                              paid=True)
        OrderProductFactory(order=order1, product=product, amount=8)

        # 8 ordered, leaves 2
        self.assertEqual(8, product.amount_ordered)
        self.assertEqual(2, product.amount_available)

        # attempt to order 5
        order2 = OrderFactory(order_round=self.round)
        order2_product = OrderProductFactory(order=order2,
                                             product=product,
                                             amount=5)

        update_totals_for_products_with_max_order_amounts(order2)

        # re-fetch, amount is decreased to remaining 2
        order2_product = OrderProduct.objects.get(pk=order2_product.pk)
        self.assertEqual(2, order2_product.amount)
Ejemplo n.º 12
0
    def test_verbose_availability_with_stock_sold_out(self):
        OrderRoundFactory()
        product = ProductFactory(order_round=None)
        stock = ProductStockFactory(product=product,
                                    type=ProductStock.TYPE_ADDED)
        OrderProductFactory(product=product,
                            amount=stock.amount,
                            order__paid=True)

        self.assertEqual(product.verbose_availability(), "uitverkocht")
Ejemplo n.º 13
0
    def test_sold_out_stock_product_is_removed(self):
        # 10 available
        product = ProductFactory(order_round=None)
        ProductStockFactory(product=product, amount=10)
        self.assertEqual(10, product.amount_available)

        order1 = OrderFactory(order_round=self.round,
                              finalized=True,
                              paid=True)
        OrderProductFactory(order=order1, product=product, amount=10)

        # 10 ordered, 0 remain
        self.assertEqual(10, product.amount_ordered)
        self.assertEqual(0, product.amount_available)

        # order 1 more
        order2 = OrderFactory(order_round=self.round)
        OrderProductFactory(order=order2, product=product, amount=1)

        self.assertEqual(2, len(product.orderproducts.all()))
        update_totals_for_products_with_max_order_amounts(order2)
        self.assertEqual(1, len(product.orderproducts.all()))
Ejemplo n.º 14
0
 def test_regular_save(self):
     ps = ProductStockFactory()
     ps.save()
Ejemplo n.º 15
0
 def test_regular_save(self):
     ps = ProductStockFactory()
     ps.save()
Ejemplo n.º 16
0
 def test_percentage_available_with_stock_is_always_0(self):
     product = ProductFactory()
     ProductStockFactory(amount=10, product=product)
     OrderProductFactory(product=product, order__paid=True, amount=1)
     self.assertEqual(product.percentage_available, 100)
Ejemplo n.º 17
0
 def test_is_available_on_stock_product_1(self):
     product = ProductFactory(order_round=None)
     ProductStockFactory(product=product, amount=2)
     self.assertTrue(product.is_available)