mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 17:45:41 -04:00
more tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from flask import Blueprint, current_app, jsonify, request
|
from flask import Blueprint, current_app, jsonify, request
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
from werkzeug.exceptions import ServiceUnavailable
|
||||||
|
|
||||||
from app import db, version
|
from app import db, version
|
||||||
from app.dao.organization_dao import dao_count_organizations_with_live_services
|
from app.dao.organization_dao import dao_count_organizations_with_live_services
|
||||||
@@ -28,7 +29,8 @@ def show_status():
|
|||||||
current_app.logger.error(
|
current_app.logger.error(
|
||||||
f"Unexpected error in show_status: {str(e)}", exc_info=True
|
f"Unexpected error in show_status: {str(e)}", exc_info=True
|
||||||
)
|
)
|
||||||
raise Exception(status_code=503, detail="Service temporarily unavailable")
|
# raise Exception(status_code=503, detail="Service temporarily unavailable")
|
||||||
|
raise ServiceUnavailable("Service temporarily unavailable")
|
||||||
|
|
||||||
|
|
||||||
@status.route("/_status/live-service-and-organization-counts")
|
@status.route("/_status/live-service-and-organization-counts")
|
||||||
@@ -46,7 +48,8 @@ def live_service_and_organization_counts():
|
|||||||
f"Unexpected error in live_service_and_organization_counts: {str(e)}",
|
f"Unexpected error in live_service_and_organization_counts: {str(e)}",
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
raise Exception(status_code=503, detail="Service temporarily unavailable")
|
# raise Exception(status_code=503, detail="Service temporarily unavailable")
|
||||||
|
raise ServiceUnavailable("Service temporarily unavailable")
|
||||||
|
|
||||||
|
|
||||||
def get_db_version():
|
def get_db_version():
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import json
|
from flask import json
|
||||||
|
|
||||||
@@ -64,3 +66,17 @@ def test_populated_live_service_and_organization_counts(admin_request):
|
|||||||
"organizations": 1,
|
"organizations": 1,
|
||||||
"services": 4,
|
"services": 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_live_service_and_org_counts_exception(admin_request):
|
||||||
|
with patch("app.status.healthcheck.jsonify") as mock_jsonify:
|
||||||
|
mock_jsonify.side_effect = ValueError("JSON serialization failed")
|
||||||
|
admin_request.get(
|
||||||
|
"status.live_service_and_organization_counts", _expected_status=503
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_show_status_exception(admin_request):
|
||||||
|
with patch("app.status.healthcheck.jsonify") as mock_jsonify:
|
||||||
|
mock_jsonify.side_effect = ValueError("JSON serialization failed")
|
||||||
|
admin_request.get("status.show_status", _expected_status=503)
|
||||||
|
|||||||
Reference in New Issue
Block a user