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)
    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
    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
Esempio n. 4
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,
        ]