Skip to content

Commit

Permalink
add test to ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
FireFading committed Apr 14, 2023
1 parent 8323abc commit 45922fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions app/schemas/rating.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import uuid

from app.schemas.products import Product
from app.schemas.users import User
from pydantic import BaseModel


class Rating(BaseModel):
stars: int
user: User
product: Product
product_id: uuid.UUID

class Config:
orm_mode = True
Expand Down
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Urls:
delete_product = "/products/delete/"

create_rating = "/products/ratings/new/"
get_ratings = "/products/ratings/get/"


class TestUser:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_rating.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from app.utils.messages import messages
from fastapi import status
from tests.settings import rating, urls
from tests.settings import rating, test_user, urls


class TestRating:
Expand All @@ -11,3 +11,10 @@ async def test_create_new_rating(self, create_product, auth_client):
response = auth_client.post(urls.create_rating, json=rating)
assert response.status_code == status.HTTP_201_CREATED
assert response.json().get("detail") == messages.RATING_CREATED

response = auth_client.get(f"{urls.get_ratings}{product_id}")
assert response.status_code == status.HTTP_200_OK
result = response.json()[0]
assert result.get("stars") == rating.get("stars")
assert result.get("product_id") == rating.get("product_id")
assert result.get("user").get("email") == test_user.email

0 comments on commit 45922fe

Please sign in to comment.