Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_database_connected_unsuable(mocker):
mocker.patch("django.db.connection.is_usable", return_value=False)
errors = checks.check_database_connected([])
assert len(errors) == 1
assert errors[0].id == health.ERROR_UNUSABLE_DATABASE
def test_check_database_connected_success(mocker):
errors = checks.check_database_connected([])
assert errors == []
def test_check_database_connected_cannot_connect(mocker):
ensure_connection = mocker.patch("django.db.connection.ensure_connection")
ensure_connection.side_effect = OperationalError
errors = checks.check_database_connected([])
assert len(errors) == 1
assert errors[0].id == health.ERROR_CANNOT_CONNECT_DATABASE
def test_check_database_connected_misconfigured(mocker):
ensure_connection = mocker.patch("django.db.connection.ensure_connection")
ensure_connection.side_effect = ImproperlyConfigured
errors = checks.check_database_connected([])
assert len(errors) == 1
assert errors[0].id == health.ERROR_MISCONFIGURED_DATABASE