-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_mark.py
More file actions
41 lines (31 loc) · 1.28 KB
/
test_mark.py
File metadata and controls
41 lines (31 loc) · 1.28 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
import requests
import json
import sys
from main import app
from main import validate
from main import getDb
from fastapi.testclient import TestClient
from testing.integration.util.assert_util import comparePayloads
def override_validate():
return {"sub": 'test'}
app.dependency_overrides[validate] = override_validate
def test_save_mark():
url = '/mark'
# Additional headers.
headers = {'Content-Type': 'application/json' }
# Body
payload = {'user_id': "test", 'flagged_string': "test string", 'category': "stereotyping", 'info': "none", 'url': "example.com"}
client = TestClient(app)
# convert dict to json by json.dumps() for body data.
resp = client.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, "Unexpected status code. Was: " + str(resp.status_code)
resp_body = resp.json()
assert resp_body['url'] == 'example.com', "Unexpected url. Was: " + resp_body['url']
#make sure payload stored properly
storedPayload = getDb().get(resp_body["_id"])
comparePayloads(payload, storedPayload)
# print response full body as text
print(resp.text)
if __name__ == '__main__':
test_save_mark()