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_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_update_nonexistent_film(client: TestClient, http_basic_auth: HTTPBasicAuth): new_film_data = FilmUpdateSchema.from_orm(FilmFactory.build()) response = client.put('/films/1', json=jsonable_encoder(new_film_data), auth=http_basic_auth) assert response.status_code == status.HTTP_404_NOT_FOUND
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_get_films(client: TestClient, http_basic_auth: HTTPBasicAuth): films = FilmFactory.create_batch(3) response = client.get('/films', auth=http_basic_auth) assert response.status_code == status.HTTP_200_OK actual_films = FilmListSchema(__root__=films) retrieved_films = FilmListSchema.parse_raw(response.text) assert actual_films == retrieved_films
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_create_film(client: TestClient, http_basic_auth: HTTPBasicAuth): actual_film_data = FilmCreateSchema.from_orm(FilmFactory.build()) response = client.post('/films', json=jsonable_encoder(actual_film_data), auth=http_basic_auth) assert response.status_code == status.HTTP_201_CREATED print(response.text) retrieved_filmed_data = FilmCreateSchema.parse_raw(response.text) assert actual_film_data == retrieved_filmed_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
def test_create_film(db: Session): actual_film_data = FilmCreateSchema.from_orm(FilmFactory.build()) film = film_crud.create(db, actual_film_data) retrieved_filmed_data = FilmCreateSchema.from_orm(film) assert actual_film_data == retrieved_filmed_data
def test_get_films(db: Session): actual_films = FilmFactory.create_batch(3) retrieved_films = film_crud.get_multi(db) assert actual_films == retrieved_films