def test_health_details(db, mock_sqlalchemy_health_datetime): assert layabase.check(db) == ( "pass", { "sqlite:select": { "componentType": "datastore", "observedValue": "", "status": "pass", "time": "2018-10-11T15:05:05.663979", } }, )
def test_health_details_success(database, mock_mongo_health_datetime): assert layabase.check(database) == ( "pass", { "mongomock:ping": { "componentType": "datastore", "observedValue": { "ok": 1.0 }, "status": "pass", "time": "2018-10-11T15:05:05.663979", } }, )
def test_health_details_failure(disconnected_database, mock_sqlalchemy_health_datetime, monkeypatch): monkeypatch.setattr(disconnected_database.metadata.bind.dialect, "do_ping", lambda x: False) assert layabase.check(disconnected_database) == ( "fail", { "sqlite:select": { "componentType": "datastore", "status": "fail", "time": "2018-10-11T15:05:05.663979", "output": "Unable to ping database.", } }, )
def test_health_details_failure(database, mock_mongo_health_datetime): def fail_ping(*args): raise Exception("Unable to ping") database.command = fail_ping assert layabase.check(database) == ( "fail", { "mongomock:ping": { "componentType": "datastore", "output": "Unable to ping", "status": "fail", "time": "2018-10-11T15:05:05.663979", } }, )
def test_health_details_failure_due_to_exception( disconnected_database, mock_sqlalchemy_health_datetime, monkeypatch): def raise_exception(*args): raise Exception("This is the error") monkeypatch.setattr(disconnected_database.metadata.bind.dialect, "do_ping", raise_exception) assert layabase.check(disconnected_database) == ( "fail", { "sqlite:select": { "componentType": "datastore", "status": "fail", "time": "2018-10-11T15:05:05.663979", "output": "This is the error", } }, )
def test_health_details_no_db(db): with pytest.raises(Exception) as exception_info: layabase.check(None) assert "A database connection URL must be provided." == str(exception_info.value)