-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_case.py
More file actions
64 lines (53 loc) · 1.88 KB
/
test_case.py
File metadata and controls
64 lines (53 loc) · 1.88 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
#!/usr/bin/python3
import unittest
import pytest
import requests
import json
import jsonpath
class Login_Test_API(unittest.TestCase):
def setUp(self):
# print("Running one time setUp")
self.ApiUrl = "https://jsonplaceholder.typicode.com"
def test_check_headers(self):
url = self.ApiUrl+"/posts/1"
response = requests.get(url)
print(response.status_code)
print(response.headers.get('Date'))
print(response.headers.get('Server'))
assert (response.status_code) == 200
def test_json_data(self):
url=self.ApiUrl+"/posts/1"
json_data = requests.get(url).json()
user_id=json_data['userId']
title=json_data['title']
print(user_id)
print(title)
assert user_id == 1
def test_json_delete(self):
url = self.ApiUrl + "/posts/1"
response = requests.delete(url)
print(response.status_code)
assert (response.status_code) == 200
def test_json_post(self):
url = self.ApiUrl + "/posts"
json_input={"title":"foo","body":"bar","userId":"1"}
response=requests.post(url,json_input)
print(response.content)
print(response.status_code)
assert response.status_code == 201
def test_json_put(self):
url = self.ApiUrl + "/posts/1"
json_input = {"id": "1", "title": "Foo", "body": "bar","userId":"1"}
response = requests.put(url, json_input)
print(response.content)
print(response.status_code)
assert response.status_code == 200
def test_json_patch(self):
url = self.ApiUrl + "/posts/1"
json_input = {"title": "fo00o"}
response = requests.patch(url, json_input)
print(response.content)
print(response.status_code)
# assert response.status_code == 201
def tearDown(self):
print("End of testing REST API")