From 455db36189ee7ba778fc61433d4a6bd019199d95 Mon Sep 17 00:00:00 2001 From: Yuru Shao Date: Fri, 2 Feb 2024 16:14:51 -0800 Subject: [PATCH] Add health check endpoint (#329) * Add health check endpoint * Add assertion on status --- snappass/main.py | 6 ++++++ tests.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/snappass/main.py b/snappass/main.py index 50b51f0..0568154 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -202,6 +202,12 @@ def show_password(password_key): return render_template('password.html', password=password) +@app.route('/_/_/health', methods=['GET']) +@check_redis_alive +def health_check(): + return {} + + @check_redis_alive def main(): app.run(host='0.0.0.0') diff --git a/tests.py b/tests.py index 1c385f9..b92eeeb 100644 --- a/tests.py +++ b/tests.py @@ -106,6 +106,11 @@ class SnapPassRoutesTestCase(TestCase): snappass.app.config['TESTING'] = True self.app = snappass.app.test_client() + def test_health_check(self): + response = self.app.get('/_/_/health') + self.assertEqual('200 OK', response.status) + self.assertEqual('{}', response.get_data(as_text=True).strip()) + def test_preview_password(self): password = "I like novelty kitten statues!" key = snappass.set_password(password, 30)