def test_pricing_updated_on_order_save(self):
        """
        Test that if an order is saved, the related pricing is recalculated and
        the order updated.
        """
        order = OrderFactory(vat_status=VATStatus.uk, discount_value=0)
        assert order.vat_cost > 0

        order.vat_status = VATStatus.outside_eu
        order.save()

        order.refresh_from_db()
        assert order.vat_cost == 0
    def test_with_commit(self):
        """
        Test that if udpate_order_pricing is called with commit = True,
        the order model is changed and the db as well.
        """
        order = OrderFactory(vat_status=VATStatus.uk)
        orig_total_cost = order.total_cost

        # change order and recalculate pricing without saving
        order.vat_status = VATStatus.outside_eu
        update_order_pricing(order, commit=True)

        assert order.total_cost != orig_total_cost

        # refresh and check that it changed
        order.refresh_from_db()
        assert order.total_cost != orig_total_cost
Esempio n. 3
0
    def test_without_committing(self):
        """
        Test that if udpate_order_pricing is called without committing,
        the order model is changed but not the db.
        """
        order = OrderFactory(vat_status=VATStatus.UK)
        orig_total_cost = order.total_cost

        # change order and recalculate pricing without saving
        order.vat_status = VATStatus.OUTSIDE_EU
        update_order_pricing(order, commit=False)

        assert order.total_cost != orig_total_cost

        # refresh and check that it hasn't changed
        order.refresh_from_db()
        assert order.total_cost == orig_total_cost