|
| 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