Skip to content

Commit a35dbe4

Browse files
committed
adding the unit test
1 parent 7917724 commit a35dbe4

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed
-1 Bytes
Binary file not shown.
969 Bytes
Binary file not shown.

my_project_env/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
@app.route('/')
88
def home():
9-
test= "L5oo next year"
10-
return jsonify(message="Hello level 400 FET, Quality Assurance! " + test)
9+
return jsonify(message="Hello level 400 FET, Quality Assurance!")
1110

1211

1312
if __name__ == '__main__':
14-
app.run(debug=True)
13+
app.run(debug=True)

my_project_env/testapp.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1+
# import unittest
2+
# from app import app
3+
4+
# class FlaskAppTestCase(unittest.TestCase):
5+
# def setUp(self):
6+
# # Create a test client
7+
# self.app = app.test_client()
8+
# self.app.testing = True
9+
10+
# def test_home(self):
11+
# # Send a GET request to the home page
12+
# response = self.app.get('/')
13+
14+
# # Check if the status code is 200 (OK)
15+
# self.assertEqual(response.status_code, 200)
16+
17+
# # Check if the response data is as expected
18+
# self.assertEqual(response.json, {"message": "Hello level 400 FET, Quality Assurance!"})
19+
20+
# if __name__ == '__main__':
21+
# unittest.main()
22+
23+
# lecturers version
24+
# test_app.py
125
import unittest
226
from app import app
327

4-
class FlaskAppTestCase(unittest.TestCase):
28+
29+
class TestApp(unittest.TestCase):
530
def setUp(self):
6-
# Create a test client
731
self.app = app.test_client()
8-
self.app.testing = True
932

10-
def test_home(self):
11-
# Send a GET request to the home page
33+
def test_home_route(self):
1234
response = self.app.get('/')
13-
14-
# Check if the status code is 200 (OK)
1535
self.assertEqual(response.status_code, 200)
16-
17-
# Check if the response data is as expected
1836
self.assertEqual(response.json, {"message": "Hello level 400 FET, Quality Assurance!"})
1937

38+
2039
if __name__ == '__main__':
2140
unittest.main()

0 commit comments

Comments
 (0)