Skip to content

Commit b9b7ecc

Browse files
author
Piotr Gulbinowicz
committed
add feedback api tests
1 parent 58095d9 commit b9b7ecc

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

api/tests/universal/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ def create_flush(client: TestClient, username: str, password: str, flush: dict):
1515
auth=BasicAuth(username=username, password=password),
1616
)
1717
assert response.status_code == status.HTTP_201_CREATED
18+
19+
20+
def create_feedback(client: TestClient, username: str, password: str, note: str):
21+
response = client.post(
22+
"/feedback",
23+
auth=BasicAuth(username=username, password=password),
24+
params={"note": note},
25+
)
26+
print(response.text)
27+
print(response.status_code)
28+
assert response.status_code == status.HTTP_201_CREATED
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import httpx
2+
from fastapi import status
3+
from fastapi.testclient import TestClient
4+
from universal.helpers import create_feedback, create_user
5+
6+
from api.main import app, get_feedback_count
7+
8+
client = TestClient(app)
9+
10+
11+
def test_insert_new_feedback():
12+
test_users = {
13+
"testcreatefeedback": "asdasdasd",
14+
"testcreatefeedback2": "asdasdasd",
15+
"testcreatefeedback3": "asdasdasd",
16+
}
17+
notes = [
18+
"w0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0ww0w",
19+
"w0ww0www0ww0ww0ww0ww0ww0wdsasd",
20+
"ęśąćź_#Ý7ж;ü÷VëÏqÑõfYÛ,ÛéO¡ü$âKÜòUúæeEá2iï:ÇüN¡¹eÑ;yïùà?þ<Ù÷G¹PëgùX8ó",
21+
]
22+
for test_user in test_users.keys():
23+
create_user(client, test_user, test_users[test_user])
24+
for i, note in enumerate(notes):
25+
create_feedback(
26+
client,
27+
test_user,
28+
test_users[test_user],
29+
note,
30+
)
31+
assert get_feedback_count(test_user) == i + 1
32+
33+
34+
def test_insert_feedback_bad_auth():
35+
response = client.post(
36+
"/feedback",
37+
auth=httpx.BasicAuth(
38+
username="usernamenonexistent", password="passwordnexistent"
39+
),
40+
params={"note": "notenotenotenotenotenotenotenotenotenotenotenotenote"},
41+
)
42+
assert response.status_code == status.HTTP_401_UNAUTHORIZED
43+
44+
45+
def test_insert_feedback_note_too_long():
46+
create_user(client, "testfeedbacknotetoolong", "testfeedbacknotetoolong")
47+
response = client.post(
48+
"/feedback",
49+
auth=httpx.BasicAuth(
50+
username="testfeedbacknotetoolong", password="testfeedbacknotetoolong"
51+
),
52+
params={
53+
"note": "notenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenotenote" # noqa: E501
54+
},
55+
)
56+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
57+
58+
59+
def test_insert_feedback_note_too_short():
60+
create_user(client, "testfeedbacknotetooshort", "testfeedbacknotetooshort")
61+
response = client.post(
62+
"/feedback",
63+
auth=httpx.BasicAuth(
64+
username="testfeedbacknotetooshort", password="testfeedbacknotetooshort"
65+
),
66+
params={"note": "note"},
67+
)
68+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY

0 commit comments

Comments
 (0)