def test_update_film(db: Session): film = FilmFactory() db.refresh(film) new_film_data = FilmUpdateSchema.from_orm(FilmFactory.build()) updated_film = film_crud.update(db, film, new_film_data) retrieved_film_data = FilmUpdateSchema.from_orm(updated_film) assert new_film_data == retrieved_film_data
def test_delete_film(client: TestClient, http_basic_auth: HTTPBasicAuth): film = FilmFactory() response = client.delete(f'/films/{film.id}', auth=http_basic_auth) assert response.status_code == status.HTTP_200_OK actual_film = FilmSchema.from_orm(film) retrieved_film = FilmSchema.parse_raw(response.text) assert actual_film == retrieved_film
def test_create_review(db: Session): user = UserFactory() film = FilmFactory() actual_review_data = ReviewCreateSchema.from_orm( ReviewCreateFactory(film_id=film.id)) review = review_crud.create_with_user(db, user, actual_review_data) retrieved_reviewed_data = ReviewCreateSchema.from_orm(review) assert actual_review_data == retrieved_reviewed_data assert user == review.user
def test_update_film(client: TestClient, http_basic_auth: HTTPBasicAuth): film = FilmFactory() new_film_data = FilmUpdateSchema.from_orm(FilmFactory.build()) response = client.put(f'/films/{film.id}', json=jsonable_encoder(new_film_data), auth=http_basic_auth) assert response.status_code == status.HTTP_200_OK retrieved_film_data = FilmUpdateSchema.parse_raw(response.text) assert new_film_data == retrieved_film_data
def test_get_film_rating(client: TestClient, http_basic_auth: HTTPBasicAuth): film = FilmFactory() ReviewFactory(film=film, rating=2, comment=None) ReviewFactory(film=film, rating=3, comment='') ReviewFactory(film=film, rating=10) response = client.get(f'/films/{film.id}/rating', auth=http_basic_auth) assert response.status_code == status.HTTP_200_OK expected_ratings = FilmRatingSchema(rating=5, num_ratings=3, num_reviews=1) actual_ratings = FilmRatingSchema.parse_raw(response.text) assert expected_ratings == actual_ratings
def test_create_review(db: Session, client: TestClient, http_basic_auth: HTTPBasicAuth): user = user_crud.get_multi(db)[0] # there is already one from basic auth film = FilmFactory() actual_review_data = ReviewCreateFactory(user_id=user.id, film_id=film.id) response = client.post('/reviews', json=jsonable_encoder(actual_review_data), auth=http_basic_auth) assert response.status_code == status.HTTP_201_CREATED retrieved_reviewed_data = ReviewCreateSchema.parse_raw(response.text) assert actual_review_data == retrieved_reviewed_data
def test_get_film(db: Session): actual_film = FilmFactory() retrieved_film = film_crud.get(db, actual_film.id) assert retrieved_film == actual_film
def test_get_film_rating(): film = FilmFactory() ReviewFactory(film=film, rating=2) ReviewFactory(film=film, rating=3) ReviewFactory(film=film, rating=10) assert film.rating == 5
def test_delete_film(db: Session): film = FilmFactory() deleted_film = film_crud.remove(db, film.id) retrieved_film = film_crud.get(db, film.id) assert film == deleted_film assert retrieved_film is None