Beispiel #1
0
    def test_notify_on_quote_generated(self, mocked_notify_client):
        """Test that a notification is triggered when a quote is generated."""
        order = OrderFactory(assignees=[])
        OrderAssigneeFactory.create_batch(1, order=order, is_lead=True)
        OrderSubscriberFactory.create_batch(2, order=order)

        mocked_notify_client.reset_mock()

        order.generate_quote(by=None)

        #  1 = customer, 3 = assignees/subscribers
        assert len(
            mocked_notify_client.send_email_notification.call_args_list) == (
                3 + 1)

        templates_called = [
            data[1]['template_id'] for data in
            mocked_notify_client.send_email_notification.call_args_list
        ]
        assert templates_called == [
            Template.quote_sent_for_customer.value,
            Template.quote_sent_for_adviser.value,
            Template.quote_sent_for_adviser.value,
            Template.quote_sent_for_adviser.value,
        ]
    def test_fails_if_theres_already_an_active_quote(self, validators):
        """Test raises APIConflictException if there's already an active quote."""
        validators.NoOtherActiveQuoteExistsValidator.side_effect = APIConflictException(
            'error')

        order = OrderFactory()
        with pytest.raises(APIConflictException):
            order.generate_quote(by=None)
    def test_fails_with_incomplete_fields(self, validators):
        """Test raises ValidationError if the order is incomplete."""
        validators.OrderDetailsFilledInValidator.side_effect = ValidationError(
            'error')

        order = OrderFactory()
        with pytest.raises(ValidationError):
            order.generate_quote(by=None)
    def test_atomicity(self):
        """Test that if there's a problem with saving the order, the quote is not saved either."""
        order = OrderFactory()
        with mock.patch.object(order, 'save') as mocked_save:
            mocked_save.side_effect = Exception()

            with pytest.raises(Exception):
                order.generate_quote(by=None)
            assert not Quote.objects.count()
    def test_without_committing(self):
        """Test that a quote can be generated without saving its changes."""
        order = OrderFactory()
        order.generate_quote(by=AdviserFactory(), commit=False)

        assert order.quote.reference
        assert order.quote.content
        assert order.status == OrderStatus.quote_awaiting_acceptance

        order.refresh_from_db()
        assert not order.quote
        assert not Quote.objects.count()
        assert order.status == OrderStatus.draft
Beispiel #6
0
    def test_without_committing(self):
        """Test that a quote can be generated without saving its changes."""
        order = OrderFactory()
        order.generate_quote(by=AdviserFactory(), commit=False)

        assert order.quote.reference
        assert order.quote.content
        assert order.status == OrderStatus.QUOTE_AWAITING_ACCEPTANCE

        order.refresh_from_db()
        assert not order.quote
        assert not Quote.objects.count()
        assert order.status == OrderStatus.DRAFT
    def test_success(self):
        """Test that a quote can be generated."""
        company = CompanyFactory(
            registered_address_1='Reg address 1',
            registered_address_2='Reg address 2',
            registered_address_town='Reg address town',
            registered_address_county='Reg address county',
            registered_address_postcode='Reg address postcode',
            registered_address_country_id=constants.Country.japan.value.id,
        )
        order = OrderFactory(
            company=company,
            billing_company_name='',
            billing_contact_name='',
            billing_email='',
            billing_phone='',
            billing_address_1='',
            billing_address_2='',
            billing_address_town='',
            billing_address_county='',
            billing_address_postcode='',
            billing_address_country_id=None,
        )
        adviser = AdviserFactory()
        order.generate_quote(by=adviser)

        # quote created and populated
        assert order.quote.pk
        assert order.quote.reference
        assert order.quote.content
        assert order.quote.created_by == adviser

        # status changed
        assert order.status == OrderStatus.quote_awaiting_acceptance

        assert not order.billing_contact_name
        assert not order.billing_email
        assert not order.billing_phone

        # billing fields populated
        assert order.billing_company_name == company.name
        assert order.billing_address_1 == company.registered_address_1
        assert order.billing_address_2 == company.registered_address_2
        assert order.billing_address_county == company.registered_address_county
        assert order.billing_address_town == company.registered_address_town
        assert order.billing_address_postcode == company.registered_address_postcode
        assert order.billing_address_country == company.registered_address_country
 def test_fails_if_order_not_in_draft(self, disallowed_status):
     """Test that if the order is not in `draft`, a quote cannot be generated."""
     order = OrderFactory(status=disallowed_status)
     with pytest.raises(APIConflictException):
         order.generate_quote(by=None)