adding testing
هذا الالتزام موجود في:
0
__init__.py
Normal file
0
__init__.py
Normal file
15
app.py
15
app.py
@@ -1,10 +1,13 @@
|
|||||||
from flask import Flask
|
"""A simple Flask web application."""
|
||||||
|
|
||||||
|
from flask import Flask, jsonify
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route("/", methods=["GET"])
|
||||||
def hello_world():
|
def home():
|
||||||
return 'Hello, Worlddddddddddd!!!'
|
"""Return a simple JSON greeting message."""
|
||||||
|
return jsonify({"message": "Hello, Flask!"})
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(host="0.0.0.0", port=5000)
|
||||||
|
|||||||
24
test_app.py
24
test_app.py
@@ -1,8 +1,20 @@
|
|||||||
from app import app
|
"""Unit tests for the Flask application."""
|
||||||
|
|
||||||
def test_homepage():
|
import unittest
|
||||||
|
from flask_app.app import app
|
||||||
|
|
||||||
with app.test_client() as client:
|
class FlaskAppTestCase(unittest.TestCase):
|
||||||
response = client.get('/')
|
"""Test cases for the Flask application."""
|
||||||
assert response.status_code == 200
|
|
||||||
assert b"Hello, Worlddddddddddd!!!" in response.data
|
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()
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم