-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest.py
More file actions
28 lines (19 loc) · 755 Bytes
/
test.py
File metadata and controls
28 lines (19 loc) · 755 Bytes
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
import requests
# example api test
import json
apiurl = 'https://localhost:8000'
def test_post_headers_body_json():
url = apiurl + '/mark'
# Additional headers.
headers = {'Content-Type': 'application/json'}
# Body
payload = {'user_id': "test", 'flagged_string': "test string", 'category': "stereotyping", 'info': "none",
'url': "example.com"}
# convert dict to json by json.dumps() for body data.
resp = requests.post(url, headers=headers, data=json.dumps(payload, indent=4))
# Validate response headers and body contents, e.g. status code.
assert resp.status_code == 200
resp_body = resp.json()
assert resp_body['url'] == url
# print response full body as text
print(resp.text)