"""Test for the Hello Handler.""" from unittest.mock import MagicMock from unittest.mock import patch from sqlalchemy.exc import SQLAlchemyError from product.constants import error from product.logic import hello def test_health_check(): """Check the health check. Note: while running tests, we connect to sqlite, which will make this mark this pull request as successfull. """ assert hello.health_check() @patch('product.connectors.mysql._db_session') def test_failed_health_check(db_session): """Check when a health check has failed (exception).""" session = MagicMock() session.execute = MagicMock(side_effect=SQLAlchemyError()) db_session.return_value = session response = hello.health_check() assert not response assert response.errors.get('code') == error.INTERNAL_ERROR