Skip to content

Commit

Permalink
update return for average_rating
Browse files Browse the repository at this point in the history
  • Loading branch information
kenmoh committed Sep 1, 2023
1 parent 37975f2 commit a2af9d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/routes/movie_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import Session

from app.database import get_db
from app.schema.movie_schema import MovieCreateSchema, MovieResponseSchema, ReviewResponseSchema, ReviewCreateSchema
from app.schema.movie_schema import MovieCreateSchema, MovieResponseSchema, ReviewResponseSchema, ReviewCreateSchema, AverageMovieReview

from app.services import services

Expand Down Expand Up @@ -71,9 +71,9 @@ def delete_review(review_id: int):


@movie_router.get('/average-rating/{movie_id}', status_code=status.HTTP_200_OK)
def get_avg_movie_rating(movie_id: int) -> float:
def get_avg_movie_rating(movie_id: int) -> AverageMovieReview:
response = requests.get(f'{REVIEW_URL}/average-rating/{movie_id}')
avg_rating: float = response.json()
avg_rating = response.json()
return avg_rating


Expand Down
4 changes: 4 additions & 0 deletions app/schema/movie_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ class ReviewCreateSchema(BaseModel):
rating: int = Field(gt=0, le=5)


class AverageMovieReview(BaseModel):
average_rating: float


""" END REVIEW SCHEMA"""
20 changes: 11 additions & 9 deletions app/test_movies_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

update_data = {
"title": "Snake and Tiger",
"length": 2.58,
"length": 3.58,
"description": "Nollywood Movie",
"cover_image_url": "string.png",
"casts": "Zubi Michael, Kanayo O. Kanayo",
Expand All @@ -30,7 +30,7 @@
review_data = {
"author": "Lee Sammy",
"comment": "Testing",
"rating": 5
"rating": 4
}


Expand All @@ -50,7 +50,7 @@ def test_add_movie():


def test_update_movie():
response = client.put(f'{BASE_URL}/3', json=update_data)
response = client.put(f'{BASE_URL}/4', json=update_data)
assert response.status_code == status.HTTP_202_ACCEPTED


Expand All @@ -59,7 +59,7 @@ def test_get_movie():
Test get book by ID
:return: Book object
"""
response = client.get(f'{BASE_URL}/3')
response = client.get(f'{BASE_URL}/4')
assert response.status_code == status.HTTP_200_OK


Expand All @@ -68,7 +68,7 @@ def test_get_movie_reviews():
Get all reviews for a single book
:return: List of reviews for a movie
"""
response = client.get(f'{BASE_URL}/reviews/3')
response = client.get(f'{BASE_URL}/reviews/4')
assert response.status_code == status.HTTP_200_OK


Expand All @@ -77,7 +77,7 @@ def test_add_movie_review():
Add review to a movie
:return: status == 201
"""
response = client.post(f'{BASE_URL}/reviews/2', json=review_data)
response = client.post(f'{BASE_URL}/reviews/5', json=review_data)
assert response.status_code == status.HTTP_201_CREATED


Expand All @@ -86,7 +86,7 @@ def test_avg_movie_rating():
Get average rating of a movie
:return: average rating, status == 200
"""
response = client.get(f'{BASE_URL}/average-rating/3')
response = client.get(f'{BASE_URL}/average-rating/4')
assert response.status_code == status.HTTP_200_OK


Expand All @@ -95,7 +95,7 @@ def test_delete_movie():
This route test delete movie route
:return: status == 204
"""
response = client.delete(f'{BASE_URL}/2')
response = client.delete(f'{BASE_URL}/3')
assert response.status_code == status.HTTP_204_NO_CONTENT


Expand All @@ -104,5 +104,7 @@ def test_delete_movie_review():
This function test a delete review route
:return: status == 204
"""
response = client.delete(f'{BASE_URL}/reviews/25')
response = client.delete(f'{BASE_URL}/reviews/29')
assert response.status_code == status.HTTP_204_NO_CONTENT


0 comments on commit a2af9d7

Please sign in to comment.