forked from shiftkey-labs/DevOps-Foundations-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
67 lines (55 loc) · 2.13 KB
/
test_app.py
File metadata and controls
67 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import unittest
import json
from app import app
class TestApp(unittest.TestCase):
def setUp(self):
self.client = app.test_client()
def test_hello_endpoint(self):
response = self.client.get('/api/test')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json, {"message": "Hello World!"})
def test_add_endpoint(self):
payload = json.dumps({
"number_1": 5,
"number_2": 3
})
response = self.client.post('/api/add',
data=payload,
content_type='application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json, {"result": 8})
def test_add_invalid_input(self):
payload = json.dumps({
"number_1": 5
})
response = self.client.post('/api/add',
data=payload,
content_type='application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json, {"error": "Invalid input"})
# Optional: Tests for additional operations
# Uncomment and complete these tests if you implement
# the below routes
# def test_multiply_endpoint(self):
# # Prepare test data
# payload = json.dumps({
# "number_1": 4,
# "number_2": 5
# })
#
# # TODO: Get Response from API endpoint '/api/multiply'
# # response = self.client.post('/api/multiply', data=payload,
# # content_type='application/json')
#
# # TODO: Assert equals if API response is OK (200)
# # self.assertEqual(response.status_code, 200)
#
# # TODO: Assert equals if API response 'result' is 20 (4 * 5)
# # self.assertEqual(response.json, {"result": 20})
# def test_subtract_endpoint(self):
# # Write test code here
# def test_divide_endpoint(self):
# # Write test code here
# Add more tests for any additional routes created
if __name__ == '__main__':
unittest.main()