Spaces:
Runtime error
Runtime error
Download tests/test_votes.py from abdullah090809/FastAPI-Project: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/abdullah090809/FastAPI-Project/resolve/main/tests/test_votes.py
- Command line
-
hf download hf://spaces/abdullah090809/FastAPI-Project/tests/test_votes.py
-
curl -L -o test_votes.py https://huggingface.co/spaces/abdullah090809/FastAPI-Project/resolve/main/tests/test_votes.py
1.42 kB
| import pytest | |
| from app.models import Votes | |
| from app.schemas.vote import VoteBase | |
| def test_vote(test_posts,session,create_test_user): | |
| vote = { | |
| "post_id": test_posts[3].id, | |
| "user_id": create_test_user["id"] | |
| } | |
| new_vote=Votes(**vote) | |
| session.add(new_vote) | |
| session.commit() | |
| def test_vote_on_post(authorize_client,test_posts): | |
| response = authorize_client.post("/vote",json={"post_id": test_posts[3].id, "dir": 1}) | |
| response.status_code == 201 | |
| def test_vote_twice(authorize_client,test_posts,test_vote): | |
| response = authorize_client.post("/vote/",json={"post_id": test_posts[3].id, "dir": 1}) | |
| assert response.status_code == 409 | |
| def test_unvote_on_post(authorize_client,test_posts,test_vote): | |
| response = authorize_client.post("/vote",json={"post_id": test_posts[3].id, "dir": 0}) | |
| response.status_code == 201 | |
| def test_unvote_on_post_vote_does_not_exit(authorize_client,test_posts): | |
| response = authorize_client.post("/vote",json={"post_id": test_posts[3].id, "dir": 0}) | |
| response.status_code == 404 | |
| def test_unvote_on_post_does_not_exit(authorize_client,test_posts): | |
| response = authorize_client.post("/vote",json={"post_id": -9999, "dir": 0}) | |
| response.status_code == 404 | |
| def test_unauthorize_vote_on_post(client,test_posts): | |
| response = client.post("/vote",json={"post_id": test_posts[3].id, "dir": 1}) | |
| response.status_code == 401 |