diff --git a/tests/app/celery/test_process_pinpoint_receipts_tasks.py b/tests/app/celery/test_process_pinpoint_receipts_tasks.py index 84c72c3615..2188475f20 100644 --- a/tests/app/celery/test_process_pinpoint_receipts_tasks.py +++ b/tests/app/celery/test_process_pinpoint_receipts_tasks.py @@ -86,7 +86,7 @@ def test_process_pinpoint_results_succeeded(sample_template, notify_db, notify_d process_pinpoint_results(pinpoint_successful_callback(reference="ref")) updated_notification = get_notification_by_id(notification.id) - assert mock_callback_task.not_called() + mock_callback_task.assert_not_called() assert updated_notification.status == NOTIFICATION_SENT assert updated_notification.provider_response is None diff --git a/tests/app/celery/test_process_sns_receipts_tasks.py b/tests/app/celery/test_process_sns_receipts_tasks.py index c443b5d0d3..614fa3469a 100644 --- a/tests/app/celery/test_process_sns_receipts_tasks.py +++ b/tests/app/celery/test_process_sns_receipts_tasks.py @@ -161,8 +161,8 @@ def test_process_sns_results_does_not_process_other_providers(sample_template, m ) process_sns_results(response=sns_success_callback(reference="ref1")) is None - assert mock_logger.called_once_with("") - assert not mock_dao.called + mock_logger.assert_called_once() + mock_dao.assert_not_called() def test_process_sns_results_calls_service_callback(sample_template, notify_db_session, notify_db, mocker): diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 82a7bf0a75..d8675db0be 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -104,14 +104,14 @@ def test_acknowledge_happy_path(self, mocker): acknowledge_sms_normal_mock = mocker.patch("app.sms_normal.acknowledge", return_value=True) acknowledge_sms_priority_mock = mocker.patch("app.sms_bulk.acknowledge", return_value=False) acknowledge_receipt(SMS_TYPE, NORMAL, receipt) - assert acknowledge_sms_normal_mock.called_once_with(receipt) - assert acknowledge_sms_priority_mock.not_called() + acknowledge_sms_normal_mock.assert_called_once_with(receipt) + acknowledge_sms_priority_mock.assert_not_called() def test_acknowledge_wrong_queue(self, mocker, notify_api): receipt = uuid.uuid4() acknowledge_sms_bulk_mock = mocker.patch("app.sms_bulk.acknowledge", return_value=True) acknowledge_receipt(EMAIL_TYPE, NORMAL, receipt) - assert acknowledge_sms_bulk_mock.called_once_with(receipt) + acknowledge_sms_bulk_mock.assert_called_once_with(receipt) def test_acknowledge_no_queue(self): with pytest.raises(ValueError): diff --git a/tests/app/clients/test_freshdesk.py b/tests/app/clients/test_freshdesk.py index 8ccbdae256..ae0ada8b7e 100644 --- a/tests/app/clients/test_freshdesk.py +++ b/tests/app/clients/test_freshdesk.py @@ -66,7 +66,7 @@ def match_json(request): with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(**contact_request)).send_ticket() assert response == 201 - assert email_freshdesk_ticket_mock.not_called() + email_freshdesk_ticket_mock.assert_not_called() def test_send_ticket_go_live_request(self, email_freshdesk_ticket_mock, notify_api: Flask): def match_json(request): @@ -117,7 +117,7 @@ def match_json(request): with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() assert response == 201 - assert email_freshdesk_ticket_mock.not_called() + email_freshdesk_ticket_mock.assert_not_called() def test_send_ticket_branding_request(self, email_freshdesk_ticket_mock, notify_api: Flask): def match_json(request): @@ -179,7 +179,7 @@ def match_json(request): with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() assert response == 201 - assert email_freshdesk_ticket_mock.not_called() + email_freshdesk_ticket_mock.assert_not_called() def test_send_ticket_other_category(self, email_freshdesk_ticket_mock, notify_api: Flask): def match_json(request): @@ -227,7 +227,7 @@ def match_json(request): with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() assert response == 201 - assert email_freshdesk_ticket_mock.not_called() + email_freshdesk_ticket_mock.assert_not_called() def test_send_ticket_other(self, email_freshdesk_ticket_mock, notify_api: Flask): def match_json(request): @@ -258,7 +258,7 @@ def match_json(request): with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(email_address="test@email.com")).send_ticket() assert response == 201 - assert email_freshdesk_ticket_mock.not_called() + email_freshdesk_ticket_mock.assert_not_called() def test_send_ticket_user_profile(self, email_freshdesk_ticket_mock, notify_api: Flask): def match_json(request): @@ -294,7 +294,7 @@ def match_json(request): ) ).send_ticket() assert response == 201 - assert email_freshdesk_ticket_mock.not_called() + email_freshdesk_ticket_mock.assert_not_called() def test_send_ticket_freshdesk_integration_disabled(self, mocker, email_freshdesk_ticket_mock, notify_api: Flask): mocked_post = mocker.patch("requests.post") diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index bb30b48fa4..00b89a0a29 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -1231,7 +1231,7 @@ def test_preview_letter_template_precompiled_pdf_file_type(notify_api, client, a file_type="pdf", ) - assert mock_get_letter_pdf.called_once_with(notification) + mock_get_letter_pdf.assert_called_once_with(notification) assert base64.b64decode(resp["content"]) == content @@ -1334,7 +1334,7 @@ def test_preview_letter_template_precompiled_png_file_type_or_pdf_with_overlay( with pytest.raises(ValueError): mock_post.last_request.json() - assert mock_get_letter_pdf.called_once_with(notification) + mock_get_letter_pdf.assert_called_once_with(notification) assert base64.b64decode(resp["content"]) == expected_returned_content diff --git a/tests/app/test_email_limit_utils.py b/tests/app/test_email_limit_utils.py index f30ee8879a..295f72b31e 100644 --- a/tests/app/test_email_limit_utils.py +++ b/tests/app/test_email_limit_utils.py @@ -19,28 +19,21 @@ def test_fetch_todays_requested_email_count(self, client, mocker, sample_service assert actual_result == expected_result if redis_value is None: - assert mocked_set.called_once_with( + mocked_set.assert_called_once_with( cache_key, db_value, + ex=7200, ) else: mocked_set.assert_not_called() @pytest.mark.parametrize("redis_value, db_value, increment_by", [(None, 5, 5), ("3", 5, 3)]) - def test_increment_todays_requested_email_count(self, mocker, sample_service, redis_value, db_value, increment_by): + def test_increment_todays_requested_email_count(self, client, mocker, sample_service, redis_value, db_value, increment_by): cache_key = email_daily_count_cache_key(sample_service.id) mocker.patch("app.redis_store.get", lambda x: redis_value if x == cache_key else None) - mocked_set = mocker.patch("app.redis_store.set") mocked_incrby = mocker.patch("app.redis_store.incrby") mocker.patch("app.email_limit_utils.fetch_todays_email_count", return_value=db_value) - increment_todays_email_count(sample_service.id, increment_by) - - assert mocked_incrby.called_once_with(cache_key, increment_by) - if redis_value is None: - assert mocked_set.called_once_with( - cache_key, - db_value, - ) - else: - mocked_set.assert_not_called() + with set_config(client.application, "REDIS_ENABLED", True): + increment_todays_email_count(sample_service.id, increment_by) + mocked_incrby.assert_called_once_with(cache_key, increment_by) diff --git a/tests/app/test_sms_fragment_utils.py b/tests/app/test_sms_fragment_utils.py index ff57ada1cc..78bbe49db5 100644 --- a/tests/app/test_sms_fragment_utils.py +++ b/tests/app/test_sms_fragment_utils.py @@ -21,29 +21,22 @@ def test_fetch_todays_requested_sms_count(client, mocker, sample_service, redis_ assert actual_result == expected_result if redis_value is None: - assert mocked_set.called_once_with( + mocked_set.assert_called_once_with( cache_key, db_value, + ex=7200, ) else: mocked_set.assert_not_called() @pytest.mark.parametrize("redis_value,db_value,increment_by", [(None, 5, 5), ("3", 5, 3)]) -def test_increment_todays_requested_sms_count(mocker, sample_service, redis_value, db_value, increment_by): +def test_increment_todays_requested_sms_count(mocker, client, sample_service, redis_value, db_value, increment_by): cache_key = sms_daily_count_cache_key(sample_service.id) mocker.patch("app.redis_store.get", lambda x: redis_value if x == cache_key else None) - mocked_set = mocker.patch("app.redis_store.set") mocked_incrby = mocker.patch("app.redis_store.incrby") mocker.patch("app.sms_fragment_utils.fetch_todays_requested_sms_count", return_value=db_value) - increment_todays_requested_sms_count(sample_service.id, increment_by) - - assert mocked_incrby.called_once_with(cache_key, increment_by) - if redis_value is None: - assert mocked_set.called_once_with( - cache_key, - db_value, - ) - else: - mocked_set.assert_not_called() + with set_config(client.application, "REDIS_ENABLED", True): + increment_todays_requested_sms_count(sample_service.id, increment_by) + mocked_incrby.assert_called_once_with(cache_key, increment_by)