def test_with_too_close_delivery_date(self):
        """
        Now = 18/04/2017
        delivery date = 08/05/2017 (in 20 days)

        Therefore expiry date would be passed so an exception is raised.
        """
        order = mock.MagicMock(
            delivery_date=dateutil_parse('2017-05-08').date(), )

        with pytest.raises(ValidationError):
            calculate_quote_expiry_date(order)
    def test_with_close_delivery_date(self):
        """
        Now = 18/04/2017
        delivery date = 11/05/2017 (in 23 days)

        Therefore expiry date = 20/04/2017 (in 2 days)
        """
        order = mock.MagicMock(
            delivery_date=dateutil_parse('2017-05-11').date(), )
        expiry_date = calculate_quote_expiry_date(order)
        assert expiry_date == dateutil_parse('2017-04-20').date()
    def test_with_delivery_date_in_far_future(self):
        """
        Now = 18/04/2017
        delivery date = 20/06/2017 (in 2 months)

        Therefore expiry date = 18/05/2017 (in 30 days)
        """
        order = mock.MagicMock(
            delivery_date=dateutil_parse('2017-06-20').date(), )
        expiry_date = calculate_quote_expiry_date(order)
        assert expiry_date == dateutil_parse('2017-05-18').date()
Example #4
0
    def create_from_order(self, order, by, commit=True):
        """
        :param order: Order instance for this quote
        :param by: who made the action
        :param commit: True if the changes have to be committed

        :returns: Quote object generated from the order
        """
        expires_on = calculate_quote_expiry_date(order)

        quote = self.model(
            reference=generate_quote_reference(order),
            content=generate_quote_content(order, expires_on),
            expires_on=expires_on,
            terms_and_conditions=get_latest_terms_and_conditions(),
        )

        if commit:
            quote.created_by = by
            quote.save()

        return quote