def test_update_billable_units_for_letter_doesnt_update_if_sent_with_test_key(mocker, sample_letter_notification): sample_letter_notification.billable_units = 0 sample_letter_notification.key_type = KEY_TYPE_TEST mock_logger = mocker.patch('app.celery.tasks.current_app.logger.info') update_billable_units_for_letter(sample_letter_notification.id, 2) notification = Notification.query.filter(Notification.reference == sample_letter_notification.reference).one() assert notification.billable_units == 0 mock_logger.assert_not_called()
def test_update_billable_units_for_letter(mocker, sample_letter_notification, number_of_pages, expected_billable_units): sample_letter_notification.billable_units = 0 mock_logger = mocker.patch('app.celery.tasks.current_app.logger.info') update_billable_units_for_letter(sample_letter_notification.id, number_of_pages) notification = Notification.query.filter(Notification.reference == sample_letter_notification.reference).one() assert notification.billable_units == expected_billable_units mock_logger.assert_called_once_with( f"Letter notification id: {sample_letter_notification.id} reference {sample_letter_notification.reference}:" f" billable units set to {expected_billable_units}" )