Shorly update description

This commit is contained in:
Colin Goutte 2023-08-26 23:42:16 +02:00
parent 5c00c51b43
commit b410fa9bc8
2 changed files with 21 additions and 0 deletions

18
dev.py
View File

@ -53,6 +53,24 @@ async def create_movie(payload: schemas.MoviePayload, db: Session = Depends(get_
@app.put("/movies/{id_}")
async def update_movie(
id_: str,
payload: schemas.MoviePayload,
db: Session = Depends(get_db),
request: Request = None,
) -> schemas.MovieObject:
try:
movie = crud.get_movie_by_id(db, id_)
except LookupError:
raise HTTPException(status_code=404, detail=f"No movie found with id {id_}")
crud_params = payload.dict()
movie = crud.update_movie(db, id_, **crud_params)
return movie
@app.patch("/movies/{id_}")
async def patch_movie(
id_: str, db: Session = Depends(get_db), request: Request = None
) -> schemas.MovieObject:
try:

View File

@ -86,6 +86,8 @@ class BaseCrud(unittest.TestCase):
def test_update_movie_api(self):
self.create_payload["genres"] = ["anime"]
self.create_payload["description"] = legacy_description = "will be deleted"
response = client.post("/movies/", json=self.create_payload)
movie_id = response.json()["id"]
created_movie_path = f"/movies/{movie_id}"
@ -105,6 +107,7 @@ class BaseCrud(unittest.TestCase):
response_get = client.get(f"/movies/{movie_id}")
assert response_get.json()["title"] == new_name
assert response_get.json()["genres"] == new_genres
assert response_get.json()["description"] == ""
def test_list_movies(self):
response = client.get("/movies/")