Ejemplo n.º 1
0
    def test_advisers_notified(self):
        """
        Test that calling `order_completed` sends an email to all advisers
        notifying them that the order has been marked as completed.
        """
        order = OrderCompleteFactory(assignees=[])
        assignees = OrderAssigneeCompleteFactory.create_batch(2, order=order)
        subscribers = OrderSubscriberFactory.create_batch(2, order=order)

        notify.client.reset_mock()

        notify.order_completed(order)

        assert notify.client.send_email_notification.called
        # 4 = assignees/subscribers
        assert len(notify.client.send_email_notification.call_args_list) == 4

        calls_by_email = {
            data['email_address']: {
                'template_id': data['template_id'],
                'personalisation': data['personalisation'],
            }
            for _, data in notify.client.send_email_notification.call_args_list
        }
        for item in itertools.chain(assignees, subscribers):
            call = calls_by_email[item.adviser.get_current_email()]
            assert call[
                'template_id'] == Template.order_completed_for_adviser.value
            assert call['personalisation'][
                'recipient name'] == item.adviser.name
            assert call['personalisation'][
                'embedded link'] == order.get_datahub_frontend_url()
Ejemplo n.º 2
0
    def test_validation_error_if_not_all_actual_time_set(self):
        """
        Test that if not all assignee actual time fields have been set,
        a validation error is raised and the call fails.
        """
        order = OrderPaidFactory(assignees=[])
        OrderAssigneeCompleteFactory(order=order)
        OrderAssigneeFactory(order=order)

        with pytest.raises(ValidationError):
            order.complete(by=None)
Ejemplo n.º 3
0
    def test_notify_on_order_completed(self):
        """Test that a notification is triggered when an order is marked as completed."""
        order = OrderPaidFactory(assignees=[])
        OrderAssigneeCompleteFactory.create_batch(1, order=order, is_lead=True)
        OrderSubscriberFactory.create_batch(2, order=order)

        notify.client.reset_mock()

        order.complete(by=None)

        #  3 = assignees/subscribers
        assert len(notify.client.send_email_notification.call_args_list) == 3

        templates_called = [
            data[1]['template_id']
            for data in notify.client.send_email_notification.call_args_list
        ]
        assert templates_called == [
            Template.order_completed_for_adviser.value,
            Template.order_completed_for_adviser.value,
            Template.order_completed_for_adviser.value,
        ]
Ejemplo n.º 4
0
    def test_ok_if_order_in_allowed_status(self, allowed_status):
        """
        Test that the order can be marked as complete if it's in one of the allowed statuses.
        """
        order = OrderPaidFactory(status=allowed_status, assignees=[])
        OrderAssigneeCompleteFactory(order=order)
        adviser = AdviserFactory()

        with freeze_time('2018-07-12 13:00'):
            order.complete(by=adviser)

        order.refresh_from_db()
        assert order.status == OrderStatus.complete
        assert order.completed_on == dateutil_parse('2018-07-12T13:00Z')
        assert order.completed_by == adviser
Ejemplo n.º 5
0
    def test_atomicity(self):
        """
        Test that if there's a problem with saving the order, nothing gets saved.
        """
        order = OrderPaidFactory(assignees=[])
        OrderAssigneeCompleteFactory(order=order)
        with mock.patch.object(order, 'save') as mocked_save:
            mocked_save.side_effect = Exception()

            with pytest.raises(Exception):
                order.complete(by=None)

            order.refresh_from_db()
            assert order.status == OrderStatus.paid
            assert not order.completed_on
            assert not order.completed_by