Skip to content

Commit cd6b014

Browse files
committed
feat(flask-redis): add /health endpoint & health-test
Signed-off-by: Gaurav Kumar <gauravkrbkj121@gmail.com>
1 parent 6e8a620 commit cd6b014

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

flask-redis/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask
1+
from flask import Flask, jsonify
22
from routes.book_routes import book
33

44
app = Flask(__name__)
@@ -10,5 +10,10 @@
1010
def hello():
1111
return {"message": "Welcome to the Book Management System!"}, 200
1212

13+
@app.route("/health")
14+
def health():
15+
return jsonify({"status": "ok"})
16+
17+
1318
if __name__ == '__main__':
1419
app.run(host='0.0.0.0', port=5000, debug=True)

flask-redis/tests/test_health.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import sys
3+
import pytest
4+
5+
tests_dir = os.path.dirname(__file__)
6+
project_dir = os.path.abspath(os.path.join(tests_dir, os.pardir))
7+
sys.path.insert(0, project_dir)
8+
9+
from app import app
10+
11+
@pytest.fixture
12+
def client():
13+
app.config["TESTING"] = True
14+
with app.test_client() as client:
15+
yield client
16+
17+
def test_health(client):
18+
resp = client.get("/health")
19+
assert resp.status_code == 200
20+
assert resp.get_json() == {"status": "ok"}

0 commit comments

Comments
 (0)