예제 #1
0
def create_book(pub_id):
    form = CreateBookForm()
    form.pub_id.data = pub_id  # pre-populates pub_id
    if form.validate_on_submit():
        book = Book(title=form.title.data, author=form.author.data, avg_rating=form.avg_rating.data,
                    book_format=form.format.data, image=form.img_url.data, num_pages=form.num_pages.data,
                    pub_id=form.pub_id.data)
        db.session.add(book)
        db.session.commit()
        flash('Book added successfully')
        return redirect(url_for('main.display_publisher', publisher_id=pub_id))
    return render_template('create-book.html', form=form, pub_id=pub_id)
예제 #2
0
def add_book():
    form = AddForm()
    if form.validate_on_submit():
        book = Book(title=form.title.data,
                    author=form.author.data,
                    avg_rating=form.avg_rating.data,
                    format=form.format.data,
                    image=form.image.data,
                    num_pages=form.num_pages.data,
                    pub_id=form.pub_id.data)
        db.session.add(book)
        db.session.commit()
        return redirect(url_for('main.display_books'))
    return render_template('add.html', form=form)
예제 #3
0
def add_book(pub_id):
    form = AddBookForm()
    form.pub_id.data = pub_id

    if form.validate_on_submit():
        book = Book(title=form.title.data,
                    author=form.author.data,
                    rating=form.avg_rating.data,
                    format=form.format.data,
                    image=form.image.data,
                    pages=form.num_pages.data,
                    pub_id=form.pub_id.data,)
        db.session.add(book)
        db.session.commit()
        flash('Book added successfully')
        return redirect(url_for("main.display_publisher", publisher_id=pub_id))

    return render_template('add_book.html', form=form)
def create_book(pub_id):
    form = CreateBookForm()
    form.pub_id.data = pub_id

    if form.validate_on_submit():
        book = Book(title=form.title.data,
                    author=form.author.data,
                    avg_rating=form.avg_rating.data,
                    book_format=form.book_format.data,
                    image=form.img_url.data,
                    pub_id=form.pub_id.data,
                    num_pages=form.num_pages.data)
        db.session.add(book)
        db.session.commit()
        flash(
            'Book Has Been Successfully Creates And Has Been Added To The End Of The Catalog'
        )
        return redirect(url_for('main.display_books', publisher_id=pub_id))
    return render_template('create_book.html', form=form, pub_id=pub_id)
예제 #5
0
def test_it_raises_error_if_price_is_to_high():
    with pytest.raises(AssertionError):
        Book('Test title', price=100000)
예제 #6
0
def test_it_rounds_price_up():
    assert Decimal('10.99') == Book('Test title', price=10.985).price
예제 #7
0
def test_it_raises_error_with_price_equals_less_than_zero():
    with pytest.raises(AssertionError):
        Book('Test title', price=-1)
예제 #8
0
def test_it_sets_none_if_gets_empty_string():
    book = Book('Test title', publication_year='')
    assert book.publication_year is None
예제 #9
0
def test_it_is_created_with_title():
    assert Book('Test title')
예제 #10
0
def test_it_raises_error_if_publication_year_is_less_than_zero():
    with pytest.raises(AssertionError):
        Book('Test title', publication_year=-1)
예제 #11
0
def test_it_raises_error_with_title_as_empty_string():
    with pytest.raises(AssertionError):
        Book('')
예제 #12
0
def test_it_raises_error_with_empty_title():
    with pytest.raises(AssertionError):
        Book(None)
예제 #13
0
def test_it_has_inserted_at_value():
    assert Book('Test title').inserted_at
예제 #14
0
    flask_app = create_app('dev')

    with flask_app.app_context():
        db.create_all()

        p1 = Publication("Oxford Publications")
        p2 = Publication("Paramount Press")
        p3 = Publication("Oracle Books Inc")
        p4 = Publication("Vintage Books and Comics")
        p5 = Publication("Trolls Press")
        p6 = Publication("Broadway Press")
        p7 = Publication("Downhill Publishers")
        p8 = Publication("Kingfisher Inc")
        db.session.add_all([p1, p2, p3, p4, p5, p6, p7, p8])

        b1 = Book("Miky's Delivery Service", "William Dobelli", 3.9, "ePub",
                  "broom-145379.svg", 123, 1)
        b2 = Book("The Secret Life of Walter Kitty", "Kitty Stiller", 4.1,
                  "Hardcover", "cat-150306.svg", 133, 1)
        b3 = Book("The Empty Book of Life", "Roy Williamson", 4.2, "eBook",
                  "book-life-34063.svg", 153, 1)
        b4 = Book("Life After Dealth", "Nikita Kimmel", 3.8, "Paperback",
                  "mummy-146868.svg", 175, 2)
        b5 = Book("The Legend of Dracula", "Charles Rowling", 4.6, "Hardcover",
                  "man-37603.svg", 253, 2)
        b6 = Book("Taming Dragons", "James Vonnegut", 4.5,
                  "MassMarket Paperback", "dragon-23164.svg", 229, 2)
        b7 = Book("The Singing Magpie", "Oscar Steinbeck", 5, "Hardcover",
                  "magpie-147852.svg", 188, 3)
        b8 = Book("Mr. Incognito", "Amelia Funke", 4.2, "Hardcover",
                  "incognito-160143.svg", 205, 3)
        b9 = Book("A Dog without purpose", "Edgar Dahl", 4.8,
예제 #15
0
def create_book():
    book = Book('Test book')
    book.save()
예제 #16
0
def test_optional_values_can_be_none():
    assert Book('Test title',
                authors=None,
                isbn=None,
                price=None,
                publication_year=None)
예제 #17
0
def test_it_has_publication_year():
    book = Book('Test title', publication_year=2020)
    assert book.publication_year == Decimal('2020')
예제 #18
0
def test_it_is_created_with_empty_authors():
    assert Book('Test title', authors=None)
예제 #19
0
def test_it_raises_error_if_publication_year_is_greater_than_actual_year():
    with pytest.raises(AssertionError):
        actual_year = datetime.now().year
        Book('Test title', publication_year=actual_year + 1)
예제 #20
0
def test_it_raises_error_with_authors_as_empty_string():
    with pytest.raises(AssertionError):
        Book('Test title', authors='')
예제 #21
0
def test_it_create_decimal_from_string():
    book = Book('Test title', publication_year='2010')
    assert book.publication_year == Decimal('2010')
예제 #22
0
def test_it_is_created_with_valid_isbn():
    assert Book('Test title', isbn='83-89533-13-8')
예제 #23
0
def test_it_can_be_deleted():
    book = Book('Test Book')
    book.delete()
    assert book.deleted_at
예제 #24
0
def test_it_raises_error_with_invalid_isbn():
    with pytest.raises(AssertionError):
        Book('Test title', isbn='83-89533-13-8-1')