def test_add_book_to_reader_person_books_read_list( client, db_session, mock_person_with_3_books_read): newly_read_book = BookFactory.create(name="mock_Read_book") data = [{"id": newly_read_book.id, "type": newly_read_book._s_type}] res = client.post(f"/People/{mock_person_with_3_books_read.id}/books_read", json={"data": data}) assert res.status_code == 204 person_books_read_list = (db_session.query(models.Book).filter( models.Book.reader_id == mock_person_with_3_books_read.id).all()) assert len(person_books_read_list) == 4 assert person_books_read_list[3].id == newly_read_book.id
def test_add_invalid_book_to_reader_person_books_read_list( client, db_session, mock_person_with_3_books_read): newly_read_book = BookFactory.create(name="mock_Read_book") data = [{"id": newly_read_book.id}] # no type res = client.post(f"/People/{mock_person_with_3_books_read.id}/books_read", json={"data": data}) assert res.status_code == 403 data = [{"id": "invalid id"}] # invalid id res = client.post(f"/People/{mock_person_with_3_books_read.id}/books_read", json={"data": data}) assert res.status_code == 404
def test_patch_publishers_books_list(client, db_session, mock_publisher_with_3_books): book = BookFactory.create(name="mock_book") res = client.patch(f"/Publishers/{mock_publisher_with_3_books.id}/books", json={"data": [{ "id": book.id, "type": book._s_type }]}) assert res.status_code == 200 publishers_books_list = (db_session.query(models.Book).filter( models.Book.publisher_id == mock_publisher_with_3_books.id).all()) response_data = res.get_json() assert len(publishers_books_list) == 1 assert mock_publisher_with_3_books.books[0].id == response_data["data"][0][ "id"]