def test_atomicity(self): """Test that if there's a problem with saving the order, the quote is not saved either.""" order = OrderWithOpenQuoteFactory() with mock.patch.object(order, 'save') as mocked_save: mocked_save.side_effect = Exception() with pytest.raises(Exception): order.accept_quote(by=None) quote = order.quote order.refresh_from_db() quote.refresh_from_db() assert not quote.is_accepted() assert not order.invoice assert not Invoice.objects.count()
def test_ok_if_order_in_allowed_status(self, allowed_status): """ Test that the quote of an order can be accepted if the order is in one of the allowed statuses. """ order = OrderWithOpenQuoteFactory(status=allowed_status) contact = ContactFactory() order.accept_quote(by=contact) order.refresh_from_db() assert order.status == OrderStatus.quote_accepted assert order.quote.accepted_on assert order.quote.accepted_by == contact assert order.invoice assert order.invoice.billing_company_name == order.billing_company_name assert order.invoice.billing_address_1 == order.billing_address_1 assert order.invoice.billing_address_2 == order.billing_address_2 assert order.invoice.billing_address_town == order.billing_address_town assert order.invoice.billing_address_county == order.billing_address_county assert order.invoice.billing_address_postcode == order.billing_address_postcode assert order.invoice.billing_address_country == order.billing_address_country assert order.invoice.po_number == order.po_number assert order.invoice.contact_email == order.get_current_contact_email()