diff --git a/flask-redis/app.py b/flask-redis/app.py index bf701d1..37ceff4 100644 --- a/flask-redis/app.py +++ b/flask-redis/app.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, jsonify from routes.book_routes import book app = Flask(__name__) @@ -10,5 +10,10 @@ def hello(): return {"message": "Welcome to the Book Management System!"}, 200 +@app.route("/health") +def health(): + return jsonify({"status": "ok"}) + + if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True) diff --git a/flask-redis/tests/test_health.py b/flask-redis/tests/test_health.py new file mode 100644 index 0000000..d32beed --- /dev/null +++ b/flask-redis/tests/test_health.py @@ -0,0 +1,20 @@ +import os +import sys +import pytest + +tests_dir = os.path.dirname(__file__) +project_dir = os.path.abspath(os.path.join(tests_dir, os.pardir)) +sys.path.insert(0, project_dir) + +from app import app + +@pytest.fixture +def client(): + app.config["TESTING"] = True + with app.test_client() as client: + yield client + +def test_health(client): + resp = client.get("/health") + assert resp.status_code == 200 + assert resp.get_json() == {"status": "ok"}