コード例 #1
0
    def test_notify_on_quote_accepted(self, mocked_notify_client):
        """Test that a notification is triggered when a quote is accepted."""
        order = OrderWithOpenQuoteFactory(assignees=[])
        OrderAssigneeFactory.create_batch(1, order=order, is_lead=True)
        OrderSubscriberFactory.create_batch(2, order=order)

        mocked_notify_client.reset_mock()

        order.accept_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_accepted_for_customer.value,
            Template.quote_accepted_for_adviser.value,
            Template.quote_accepted_for_adviser.value,
            Template.quote_accepted_for_adviser.value,
        ]
コード例 #2
0
    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()
コード例 #3
0
ファイル: test_signals.py プロジェクト: uktrade/data-hub-api
def test_accepting_quote_updates_opensearch(opensearch_with_signals):
    """
    Test that when a quote is accepted and the invoice created, the payment_due_date field
    in OpenSearch gets updated.
    """
    order = OrderWithOpenQuoteFactory()
    opensearch_with_signals.indices.refresh()

    result = opensearch_with_signals.get(
        index=OrderSearchApp.search_model.get_write_index(),
        id=order.pk,
    )
    assert not result['_source']['payment_due_date']

    order.accept_quote(by=None)
    opensearch_with_signals.indices.refresh()

    result = opensearch_with_signals.get(
        index=OrderSearchApp.search_model.get_write_index(),
        id=order.pk,
    )
    assert result['_source'][
        'payment_due_date'] == order.invoice.payment_due_date.isoformat()
コード例 #4
0
    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()
コード例 #5
0
def test_accepting_quote_updates_es(setup_es):
    """
    Test that when a quote is accepted and the invoice created, the payment_due_date field
    in ES gets updated.
    """
    order = OrderWithOpenQuoteFactory()
    setup_es.indices.refresh()

    result = setup_es.get(
        index=OrderSearchApp.es_model.get_write_index(),
        doc_type=OrderSearchApp.name,
        id=order.pk,
    )
    assert not result['_source']['payment_due_date']

    order.accept_quote(by=None)
    setup_es.indices.refresh()

    result = setup_es.get(
        index=OrderSearchApp.es_model.get_write_index(),
        doc_type=OrderSearchApp.name,
        id=order.pk,
    )
    assert result['_source']['payment_due_date'] == order.invoice.payment_due_date.isoformat()