Skip to content

Commit

Permalink
test: finished tests
Browse files Browse the repository at this point in the history
  • Loading branch information
suchencjusz committed Sep 12, 2024
1 parent 8ed33fc commit 3b9e7ad
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/filman_server/database/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ class Config:

class FilmWebMovie(BaseModel):
id: int
title: str
year: int
poster_url: str
community_rate: float
title: str | None
year: int | None
poster_url: str | None
community_rate: float | None

class Config:
orm_mode = True
Expand Down
35 changes: 30 additions & 5 deletions src/filman_server/routes/filmweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ async def update_movie(
#


@filmweb_router.post("/user/mapping/set", response_model=schemas.FilmWebUserMapping)
@filmweb_router.post(
"/user/mapping/set",
response_model=schemas.FilmWebUserMapping,
summary="Set user mapping",
description="Set user mapping between discord user and filmweb username",
)
async def set_user_mapping(
user_mapping: schemas.FilmWebUserMappingCreate,
db: Session = Depends(get_db),
Expand All @@ -73,7 +78,12 @@ async def set_user_mapping(
raise HTTPException(status_code=400, detail="User mapping already exists")


@filmweb_router.get("/user/mapping/get", response_model=schemas.FilmWebUserMapping)
@filmweb_router.get(
"/user/mapping/get",
response_model=schemas.FilmWebUserMapping,
summary="Get user mapping",
description="Get user mapping between discord user and filmweb username",
)
async def get_user_mapping(
user_id: int | None = None,
filmweb_id: str | None = None,
Expand All @@ -89,7 +99,12 @@ async def get_user_mapping(
return user_mapping


@filmweb_router.delete("/user/mapping/delete", response_model=bool)
@filmweb_router.delete(
"/user/mapping/delete",
response_model=bool,
summary="Delete user mapping",
description="Delete user mapping between discord user and filmweb username, and watched movies of this user",
)
async def delete_user_mapping(
user_id: int | None = None,
filmweb_id: str | None = None,
Expand All @@ -111,7 +126,12 @@ async def delete_user_mapping(
#


@filmweb_router.post("/user/watched/movies/add", response_model=schemas.FilmWebUserWatchedMovieCreate)
@filmweb_router.post(
"/user/watched/movies/add",
response_model=schemas.FilmWebUserWatchedMovieCreate,
summary="Add watched movie by user",
description="Add watched movie by user, if movie does not exist in database it will be added with default values",
)
async def add_watched_movie(
user_watched_movie: schemas.FilmWebUserWatchedMovieCreate,
db: Session = Depends(get_db),
Expand All @@ -131,7 +151,12 @@ async def add_watched_movie(
raise HTTPException(status_code=400, detail="Movie is already in user watched")


@filmweb_router.get("/user/watched/movies/get", response_model=List[schemas.FilmWebUserWatchedMovie])
@filmweb_router.get(
"/user/watched/movies/get",
response_model=List[schemas.FilmWebUserWatchedMovie],
summary="Get watched movies by user",
description="Get watched movies by user, with movie details",
)
async def get_watched_movies(
user_id: int | None = None,
filmweb_id: int | None = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_add_watched_movie(test_client):
assert response.json()["rate"] == 5
assert response.json()["comment"] == None
assert response.json()["favorite"] == False

response = test_client.post(
"/filmweb/user/watched/movies/add",
json={
Expand All @@ -275,15 +275,15 @@ def test_add_watched_movie(test_client):
assert response.json()["rate"] == 2
assert response.json()["comment"] == "awesome"
assert response.json()["favorite"] == True

# check if the movies were added to the watched movies
response = test_client.get("/filmweb/user/watched/movies/get", params={"user_id": 3})
assert response.status_code == 200
assert response.json()[0]["movie"]["id"] == 628
assert response.json()[0]["rate"] == 7
assert response.json()[0]["comment"] == "good movie"
assert response.json()[0]["favorite"] == False

assert response.json()[1]["movie"]["id"] == 1
assert response.json()[1]["rate"] == 5
assert response.json()[1]["comment"] == None
Expand All @@ -293,7 +293,27 @@ def test_add_watched_movie(test_client):
assert response.json()[2]["rate"] == 2
assert response.json()[2]["comment"] == "awesome"
assert response.json()[2]["favorite"] == True


# let user 1 watch 1 of the movies which does not exist
response = test_client.post(
"/filmweb/user/watched/movies/add",
json={
"id_media": 3,
"filmweb_id": "maciek",
"date": "2024-09-11T20:21:58.072Z",
"rate": 7,
"comment": "good movie",
"favorite": False,
},
)
assert response.status_code == 200

# check if the movie was added to the watched movies
response = test_client.get("/filmweb/user/watched/movies/get", params={"user_id": 1})
assert response.status_code == 200
assert len(response.json()) == 2


def test_user_mapping_delete(test_client):
test_users_data = [
{"discord_id": 321309474667253282},
Expand Down Expand Up @@ -363,4 +383,3 @@ def test_user_mapping_delete(test_client):
# check user 1 watched movies
response = test_client.get("/filmweb/user/watched/movies/get", params={"user_id": 1})
assert response.status_code == 404

0 comments on commit 3b9e7ad

Please sign in to comment.