def test_doesnt_save_if_pricing_didnt_change(self): """ Test that if the pricing didn't change, update_order_pricing doesn't do anything. """ order = OrderFactory() with mock.patch.object(order, 'save') as mocked_save: assert order.total_cost > 0 order.description = 'updated description' update_order_pricing(order, commit=True) assert not mocked_save.called
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
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
def update_order_pricing_on_pre_order_save(sender, instance, **kwargs): """ Update the order pricing before an order is saved. Do not commit as the actual commit will be performed later on by the action triggerer. """ update_order_pricing(instance, commit=False)
def update_order_pricing_on_related_obj_save(sender, instance, **kwargs): """ Update the order pricing after an order assignee is saved or deleted. """ update_order_pricing(instance.order, commit=True)