def test_send_licence_to_hmrc_integration_with_background_task_failure_max_attempts(
            self, send_licence, task_get, schedule_max_tried_task_as_new_task):
        send_licence.side_effect = HMRCIntegrationException(
            "Recieved an unexpected response")
        task_get.return_value = MockTask(
            MAX_ATTEMPTS -
            1)  # Make the current task attempt 1 less than MAX_ATTEMPTS
        schedule_max_tried_task_as_new_task.return_value = None

        with self.assertRaises(Exception) as error:
            # Note: Using `.now()` operation to test code synchronously
            send_licence_to_hmrc_integration.now(
                str(self.standard_licence.id),
                self.hmrc_integration_status,
            )

        send_licence.assert_called_once()
        task_get.assert_called_with(
            queue=HMRC_INTEGRATION_QUEUE,
            task_params=
            f'[["{self.standard_licence.id}", "{self.hmrc_integration_status}"], {{}}]',
        )
        schedule_max_tried_task_as_new_task.assert_called_with(
            str(self.standard_licence.id),
            self.hmrc_integration_status,
        )
        self.assertEqual(
            str(error.exception),
            f"Failed to send licence '{self.standard_licence.id}', action "
            f"'{self.hmrc_integration_status}' to HMRC Integration",
        )
    def test_send_licence_to_hmrc_integration_with_background_task_success(
            self, send_licence):
        send_licence.return_value = None

        # Note: Using `.now()` operation to test code synchronously
        send_licence_to_hmrc_integration.now(str(self.standard_licence.id),
                                             self.hmrc_integration_status)

        send_licence.assert_called_once()
    def test_send_licence_to_hmrc_integration_failure(self, send_licence,
                                                      task_get):
        send_licence.side_effect = HMRCIntegrationException(
            "Recieved an unexpected response")
        task_get.return_value = MockTask(0)

        # Note: Using `.now()` operation to test code synchronously
        send_licence_to_hmrc_integration.now(
            str(self.standard_licence.id),
            self.hmrc_integration_status,
            scheduled_as_background_task=False,
        )

        send_licence.assert_called_with(self.standard_licence,
                                        self.hmrc_integration_status)
        task_get.assert_not_called()