def test_add_get_books():
    store = create_bookstore("rmotr's bookstore")

    poe = add_author(store, 'Edgar Alan Poe', 'US')
    borges = add_author(store, 'Jorge Luis Borges', 'AR')
    joyce = add_author(store, 'James Joyce', 'UK')

    raven = add_book(store, 'The Raven', 'XXX-1', 'Edgar Alan Poe')
    ulysses = add_book(store, 'Ulysses', 'XXX-2', 'James Joyce')
    ficciones = add_book(store, 'Ficciones', 'XXX-3', 'Jorge Luis Borges')
    aleph = add_book(store, 'El Aleph', 'XXX-4', 'Jorge Luis Borges')

    book = get_book_by_title(store, 'The Raven')
    assert book['title'] == 'The Raven'
    assert book['isbn'] == 'XXX-1'
    assert book['author'] == 'Edgar Alan Poe'

    book = get_book_by_title(store, 'Ulysses')

    assert book['title'] == 'Ulysses'
    assert book['isbn'] == 'XXX-2'
    assert book['author'] == 'James Joyce'

    books = get_books_by_author(store, 'Jorge Luis Borges')
    assert len(books) == 2

    book1 = books[0]
    assert book1['title'] == 'Ficciones'
    assert book1['isbn'] == 'XXX-3'
    assert book1['author'] == 'Jorge Luis Borges'

    book2 = books[1]
    assert book2['title'] == 'El Aleph'
    assert book2['isbn'] == 'XXX-4'
    assert book1['author'] == 'Jorge Luis Borges'
 def test_add_book(self):
     self.add_test_data()
     book_count = store.book_count()
     bk = Book(author='aa', title='bbbbb')
     store.add_book(bk)
     self.assertTrue(store.get_book_by_id(bk.id))
     self.assertEqual(book_count + 1, store.book_count())
Example #3
0
def add_book():
    new_book = ui.get_book_info()
    try:
        store.add_book(new_book)
        ui.message('Book added')
    except BookError as e:
        ui.message(e)
def test_add_get_books():
    store = create_bookstore("rmotr's bookstore")

    poe = add_author(store, 'Edgar Allan Poe', 'US')
    borges = add_author(store, 'Jorge Luis Borges', 'AR')
    joyce = add_author(store, 'James Joyce', 'UK')

    raven = add_book(store, 'The Raven', 'XXX-1', 'Edgar Allan Poe')
    ulysses = add_book(store, 'Ulysses', 'XXX-2', 'James Joyce')
    ficciones = add_book(store, 'Ficciones', 'XXX-3', 'Jorge Luis Borges')
    aleph = add_book(store, 'El Aleph', 'XXX-4', 'Jorge Luis Borges')

    book = get_book_by_title(store, 'The Raven')
    assert book['title'] == 'The Raven'
    assert book['isbn'] == 'XXX-1'
    assert book['author'] == 'Edgar Allan Poe'

    book = get_book_by_title(store, 'Ulysses')

    assert book['title'] == 'Ulysses'
    assert book['isbn'] == 'XXX-2'
    assert book['author'] == 'James Joyce'

    books = get_books_by_author(store, 'Jorge Luis Borges')
    assert len(books) == 2

    book1 = books[0]
    assert book1['title'] == 'Ficciones'
    assert book1['isbn'] == 'XXX-3'
    assert book1['author'] == 'Jorge Luis Borges'

    book2 = books[1]
    assert book2['title'] == 'El Aleph'
    assert book2['isbn'] == 'XXX-4'
    assert book1['author'] == 'Jorge Luis Borges'
 def test_delete_all_books(self):
     self.clear_bookstore()
     bk1 = Book(title='Not in store', author='Not in store')
     bk2 = Book(title='Whatever', author='Whatever')
     store.add_book(bk1)
     store.add_book(bk2)
     store.delete_all_books()
     self.assertEqual(0, store.book_count())
Example #6
0
    def add_test_data(self):
        self.bk1 = Book(title='the title', author='the author', read=False)
        self.bk2 = Book(title='what the book is called',
                        author='the writer',
                        read=True)
        self.bk3 = Book(title='fascinating', author='the author', read=True)
        self.bk4 = Book(title='brilliant', author='schrodinger', read=False)

        store.add_book(self.bk1)
        store.add_book(self.bk2)
        store.add_book(self.bk3)
        store.add_book(self.bk4)
    def add_test_data(self):
        self.bk1 = Book(title='An Interesting Book', author='Ann Author', read=True)
        self.bk2 = Book(title='Booky Book Book', author='B. Bookwriter', read=False)
        self.bk3 = Book(title='Collection of words', author='Creative Creator')

        self.clear_bookstore()

        store.add_book(self.bk1)
        store.add_book(self.bk2)
        store.add_book(self.bk3)
 def test_add_book_duplicate_errors(self):
     bk = Book(title='aa', author='aaa')
     store.add_book(bk)
     with self.assertRaises(store.BookError):
         bk_dupe = Book(title='aa', author='aaa')
         store.add_book(bk_dupe)
 def test_add_book_empty_store(self):
     store.delete_all_books()
     bk = Book(author='aa', title='aaa')
     store.add_book(bk)
     self.assertTrue(store.get_book_by_id(bk.id))
     self.assertEqual(1, store.book_count())