From a2af9d76ecfb0d463d077178db9ad166c8357940 Mon Sep 17 00:00:00 2001 From: kenmoh Date: Fri, 1 Sep 2023 14:22:42 +0100 Subject: [PATCH] update return for average_rating --- app/routes/movie_routes.py | 6 +++--- app/schema/movie_schema.py | 4 ++++ app/test_movies_api.py | 20 +++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/routes/movie_routes.py b/app/routes/movie_routes.py index 48e2709..2318141 100644 --- a/app/routes/movie_routes.py +++ b/app/routes/movie_routes.py @@ -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 @@ -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 diff --git a/app/schema/movie_schema.py b/app/schema/movie_schema.py index d45ed68..43b6236 100644 --- a/app/schema/movie_schema.py +++ b/app/schema/movie_schema.py @@ -36,4 +36,8 @@ class ReviewCreateSchema(BaseModel): rating: int = Field(gt=0, le=5) +class AverageMovieReview(BaseModel): + average_rating: float + + """ END REVIEW SCHEMA""" diff --git a/app/test_movies_api.py b/app/test_movies_api.py index 045b05e..3ef1672 100644 --- a/app/test_movies_api.py +++ b/app/test_movies_api.py @@ -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", @@ -30,7 +30,7 @@ review_data = { "author": "Lee Sammy", "comment": "Testing", - "rating": 5 + "rating": 4 } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 + +