-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiUnitTest.py
More file actions
52 lines (42 loc) · 1.85 KB
/
ApiUnitTest.py
File metadata and controls
52 lines (42 loc) · 1.85 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
import unittest
from ApiHandler import ApiHandler
class ApiTest(unittest.TestCase):
def test_get(self):
api_handler = ApiHandler()
result = api_handler.get("posts", 99)
self.assertDictEqual(
result, {"title": "temporibus sit alias " +
"delectus eligendi possimus magni",
"userId": 10, "id": 99,
"body": "quo deleniti praesentium " +
"dicta non quod\n" +
"aut est molestias\n" +
"molestias et officia quis nihil\nitaque dolorem quia"})
def test_get_error(self):
api_handler = ApiHandler()
result = api_handler.get("post", 99)
self.assertDictEqual(result, {"title": "N/A"})
def test_post(self):
api_handler = ApiHandler()
newData = {"userId": 500,
"title": "Security Interview Post",
"body": "This is an insertion test with a known API"}
result = api_handler.post("posts", newData)
self.assertTupleEqual(result, (101, 201, "Express"))
def test_post_error(self):
api_handler = ApiHandler()
newData = {"userId": 500,
"title": "Security Interview Post",
"body": "This is an insertion test with a known API"}
result = api_handler.post("post", newData)
self.assertTupleEqual(result, ("Error", "Not Found"))
def test_delete(self):
api_handler = ApiHandler()
result = api_handler.delete("posts", 101)
self.assertTupleEqual(result, (200, "nosniff"))
def test_delete_error(self):
api_handler = ApiHandler()
result = api_handler.delete("post", 101)
self.assertTupleEqual(result, ("Error", "Not Found"))
if __name__ == "__main__":
unittest.main()