From 6edb729c1ab585964cc1b2882aba2fa9d5d20614 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 16 Oct 2025 18:19:57 +0300 Subject: [PATCH] adding testing --- __init__.py | 0 app.py | 15 +++++++++------ test_app.py | 26 +++++++++++++++++++------- 3 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py index 2597091..298bb7a 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,13 @@ -from flask import Flask +"""A simple Flask web application.""" + +from flask import Flask, jsonify app = Flask(__name__) -@app.route('/') -def hello_world(): - return 'Hello, Worlddddddddddd!!!' +@app.route("/", methods=["GET"]) +def home(): + """Return a simple JSON greeting message.""" + return jsonify({"message": "Hello, Flask!"}) -if __name__ == '__main__': - app.run(debug=True) +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/test_app.py b/test_app.py index c39a090..2023cbc 100644 --- a/test_app.py +++ b/test_app.py @@ -1,8 +1,20 @@ -from app import app +"""Unit tests for the Flask application.""" -def test_homepage(): - - with app.test_client() as client: - response = client.get('/') - assert response.status_code == 200 - assert b"Hello, Worlddddddddddd!!!" in response.data +import unittest +from flask_app.app import app + +class FlaskAppTestCase(unittest.TestCase): + """Test cases for the Flask application.""" + + def setUp(self): + """Set up the test client before each test.""" + self.client = app.test_client() + + def test_home_route(self): + """Test that the home route returns the expected message.""" + response = self.client.get("/") + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json, {"message": "Hello, Flask!"}) + +if __name__ == "__main__": + unittest.main()