示例#1
0
    def setUp(self):
        self.borges = Author("Jorge Luis Borges", "AR")
        self.poe = Author('Edgar Allan Poe', 'US')

        self.ficciones = Book("Ficciones", author=self.borges)
        self.aleph = Book("The Aleph", author=self.borges)
        self.raven = Book("The Raven", author=self.poe)
示例#2
0
 def test_save_add_to_db(self):
     bk = Book('AAA', 'BBB', True)
     bk.save()
     self.assertIsNotNone(bk.id)  # Check book has ID
     store = BookStore()
     self.assertEqual(bk, store.get_book_by_id(bk.id))
     self.assertTrue(store.exact_match(bk))
 def test_add_book_store_with_books_in(self):
     self.add_test_data()
     book_count = self.BS.book_count()
     bk = Book('aa', 'bbbbb')
     bk.save()
     self.assertTrue(self.BS.exact_match(bk))
     self.assertEqual(book_count + 1, self.BS.book_count())
示例#4
0
def delete_book():
    try:
        Id = ui.get_book_id()
        book = store.get_book_by_id(Id)
        Book.delete(book)
        ui.message('Book deleted successfully')
    except:
        ui.message("Error!!! Book Not Found in Store")    
示例#5
0
    def test_show_books_list(self, mock_print):
        bk1 = Book('a', 'aaa')
        bk2 = Book('b', 'bbb')
        books = [bk1, bk2]
        ui.show_books(books)

        mock_print.assert_any_call(bk1)
        mock_print.assert_any_call(bk2)
示例#6
0
def fixtures():
    fix = Namespace()

    fix.borges = Author("Jorge Luis Borges", "AR")
    fix.poe = Author('Edgar Allan Poe', 'US')

    fix.ficciones = Book("Ficciones", author=fix.borges)
    fix.aleph = Book("The Aleph", author=fix.borges)
    fix.raven = Book("The Raven", author=fix.poe)

    return fix
示例#7
0
def delete_book():
    try:
        book_id = ui.get_book_id()
        book = store.get_book_by_id(book_id)
        answer = ui.ask_question("Type DELETE to confirm you'd like to delete this book: ")
        if answer == "DELETE":
            Book.delete(book)
        else:
            ui.message("Returning to main menu. Book has not been deleted.")
    except:
        ui.message('Error - book not found with that ID')
示例#8
0
def deploy():
    db.drop_all()
    db.create_all()
    jane = Author(
        name='Jane Austen',
        intro=
        'Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.'
    )
    jk = Author(
        name='J. K. Rowling',
        intro=
        'Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Potter fantasy series. '
    )
    book1 = Book(
        name='Pride and Prejudice',
        year='1813',
        author_id=1,
        summary=
        'Pride and Prejudice is a romance novel by Jane Austen, first published in 1813. The story charts the emotional development of the protagonist, Elizabeth Bennet, who learns the error of making hasty judgments and comes to appreciate the difference between the superficial and the essential. The comedy of the writing lies in the depiction of manners, education, marriage, and money in the British Regency.'
    )
    book2 = Book(
        name='Harry Potter and the Chamber of Secrets',
        year='1998',
        author_id=2,
        summary=
        'Harry Potter and the Chamber of Secrets is a fantasy novel written by British author J. K. Rowling and the second novel in the Harry Potter series. The plot follows his second year at Hogwarts School of Witchcraft and Wizardry, during which a series of messages on the walls of the school corridors warn that the "Chamber of Secrets" has been opened and that the "heir of Slytherin" would kill all pupils who do not come from all-magical families. These threats are found after attacks which leave residents of the school "petrified" (frozen like stone). Throughout the year, Harry and his friends Ron and Hermione investigate the attacks.'
    )
    book3 = Book(
        name='Harry Potter and the Goblet of Fire',
        year='2001',
        author_id=2,
        summary=
        'Harry Potter and the Goblet of Fire is a fantasy novel written by British author J. K. Rowling and the fourth novel in the Harry Potter series. It follows Harry Potter, a wizard in his fourth year at Hogwarts School of Witchcraft and Wizardry and the mystery surrounding the entry of his name into the Triwizard Tournament, in which he is forced to compete.'
    )
    book4 = Book(
        name='Harry Potter and the Half-Blood Prince',
        year='2005',
        author_id=2,
        summary=
        'Harry Potter and the Half-Blood Prince is a fantasy novel written by British author J. K. Rowling and the sixth and penultimate novel in the Harry Potter series. Set during protagonist his sixth year at Hogwarts, the novel explores the past of his nemesis, Lord Voldemort, and his preparations for the final battle against Voldemort alongside his headmaster and mentor Albus Dumbledore.'
    )

    db.session.add(jane)
    db.session.add(jk)
    db.session.add(book1)
    db.session.add(book2)
    db.session.add(book3)
    db.session.add(book4)

    db.session.commit()
    def test_delete_all_books(self):
        bk1 = Book('Not in store', 'Not in store')
        bk2 = Book('Whatever', 'Whatever')
        bk1.save()
        bk2.save()

        self.BS.delete_all_books()
        self.assertEqual(0, self.BS.book_count())
示例#10
0
def deploy():
    db.drop_all()
    db.create_all()
    jane = Author(
        name='Jane Austen',
        intro=
        'Jane Austen was an English novelist known primarily for her six major novels, got the British landed gentry at the end of the 18th century.'
    )
    yh = Author(
        name='Yu Hua',
        intro=
        'Yu Hua is a Chinese author, born April 3, 1960 in Hangzhou, Zhejiang province.'
    )
    scott = Author(
        name='F. Scott Fitzgerald',
        intro=
        'an American novelist and short story writer, whose works illustrate the Jazz Age'
    )
    book1 = Book(
        name='Pride and Prejudice',
        year='1813',
        author_id=1,
        summary=
        'A romance novel by Jane Austen, first published in 1813. The story charts the emotional development of the protagonist, Elizabeth Bennet, who learns the error of making hasty judgments and comes to appreciate the difference between the superficial and the essential. The comedy of the writing lies in the depiction of manners, education, marriage, and money in the British Regency.'
    )
    book2 = Book(
        name='To Live',
        year='1993',
        author_id=2,
        summary=
        'To Live is one of the most representative work by Yu Hua. The story begins with the narrator traveling through the countryside to collect folk songs and local legends and starting to hear a old peasant talking about his experiences, which encompass many significant historical events in China including the Great Leap Forward, Three-anti and Five-anti Campaigns and Cultural Revolution. '
    )
    book5 = Book(
        name='The Great Gatsby',
        year='1922',
        author_id=3,
        summary=
        'The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional town of West Egg on prosperous Long Island in the summer of 1922. '
    )

    db.session.add(yh)
    db.session.add(jk)
    db.session.add(scott)
    db.session.add(book1)
    db.session.add(book2)
    db.session.add(book5)

    db.session.commit()
示例#11
0
    def test_book_creation(self):
        borges = Author("Jorge Luis Borges", "AR")
        poe = Author('Edgar Allan Poe', 'US')

        ficciones = Book("Ficciones", author=borges)
        aleph = Book("The Aleph", author=borges)
        raven = Book("The Raven", author=poe)

        self.assertEqual(ficciones.title, "Ficciones")
        self.assertEqual(ficciones.author, borges)

        self.assertEqual(aleph.title, "The Aleph")
        self.assertEqual(aleph.author, borges)

        self.assertEqual(raven.title, "The Raven")
        self.assertEqual(raven.author, poe)
示例#12
0
def get_book_info():
    """ Create a new Book from title and author provided by user
     :returns: a Book created from the title and author. """

    title = input('Enter book title: ')
    author = input('Enter book author: ')
    return Book(title, author)
示例#13
0
def test_book_creation():
    borges = Author("Jorge Luis Borges", "AR")
    poe = Author('Edgar Allan Poe', 'US')

    ficciones = Book("Ficciones", author=borges)
    aleph = Book("The Aleph", author=borges)
    raven = Book("The Raven", author=poe)

    assert ficciones.title == "Ficciones"
    assert ficciones.author == borges

    assert aleph.title == "The Aleph"
    assert aleph.author == borges

    assert raven.title == "The Raven"
    assert raven.author == poe
示例#14
0
    def test_save_update_changes_to_db(self):

        bk = Book('CCC', 'DDD', True)
        bk.save()

        # Change some attributes and save
        bk.author = 'EEE'
        bk.title = 'FFF'
        bk.read = False

        bk.save()

        store = BookStore()

        # Check DB has same data as bk Book object
        self.assertEqual(bk, store.get_book_by_id(bk.id))
        self.assertTrue(bk, store.exact_match(bk))
    def add_test_data(self):
        self.clear_bookstore()

        self.bk1 = Book('An Interesting Book', 'Ann Author', True)
        self.bk2 = Book('Booky Book Book', 'B. Bookwriter', False)
        self.bk3 = Book('Collection of words', 'Creative Creator')

        self.bk1.save()
        self.bk2.save()
        self.bk3.save()
 def test_exact_match_not_found_author(self):
     self.add_test_data()
     bk = Book('Collection of words', 'Someone Else')
     self.assertFalse(self.BS.exact_match(bk))
 def test_add_book_duplicate_errors_case_insensitive(self):
     bk = Book('a', 'a')
     bk.save()
     with self.assertRaises(BookError):
         bk_dupe = Book('a', 'A')
         bk_dupe.save()
示例#18
0
def test_get_books_from_author():
    borges = Author("Jorge Luis Borges", "AR")
    ficciones = Book("Ficciones", author=borges)
    aleph = Book("The Aleph", author=borges)

    assert borges.get_books() == [ficciones, aleph]
 def test_exact_match_not_found_title(self):
     self.add_test_data()
     bk = Book('Collection of Stories', 'Creative Creator')
     self.assertFalse(self.BS.exact_match(bk))
 def test_exact_match_not_found_title_author(self):
     self.add_test_data()
     bk = Book('Collection of Cheese', 'Beyonce')
     self.assertFalse(self.BS.exact_match(bk))
示例#21
0
from bookstore import Book, Author


def test_author_creation():
    borges = Author("Jorge Luis Borges", "AR")
    poe = Author('Edgar Allan Poe', 'US')

    assert borges.name == "Jorge Luis Borges"
    assert borges.nationality == "AR"

    assert poe.name == "Edgar Allan Poe"
    assert poe.nationality == "US"

def test_get_books_from_author():
    borges = Author("Jorge Luis Borges", "AR")
    ficciones = Book("Ficciones", author=borges)
    aleph = Book("The Aleph", author=borges)

    assert borges.get_books() == [ficciones, aleph]
ciones = Book("Ficciones", author=borges)
        aleph = Book("The Aleph", author=borges)

        self.assertEqual(borges.get_books(), [ficciones, aleph])
 def test_delete_book_empty_list_errors(self):
     bk = Book('Not in store', 'Not in store')
     with self.assertRaises(BookError):
         self.BS.delete_book(-100)
 def test_exact_match_found(self):
     self.add_test_data()
     bk = Book('Collection of words', 'Creative Creator')
     self.assertTrue(self.BS.exact_match(bk))
 def test_exact_match_not_found_empty_store(self):
     bk = Book('Whatever', 'Whatever')
     self.clear_bookstore()
     self.assertFalse(self.BS.exact_match(bk))
 def test_add_book_empty_store(self):
     bk = Book('aa', 'aaa')
     bk.save()
     self.assertTrue(self.BS.exact_match(bk))
     self.assertEqual(1, self.BS.book_count())
 def test_is_book_in_store_empty_list(self):
     self.clear_bookstore()
     not_in_store = Book('aaaa', 'bbbb')
     self.assertFalse(self.BS.exact_match(not_in_store))
示例#27
0
    def test_get_books_from_author(self):
        borges = Author("Jorge Luis Borges", "AR")
        ficciones = Book("Ficciones", author=borges)
        aleph = Book("The Aleph", author=borges)

        self.assertEqual(borges.get_books(), [ficciones, aleph])
class TestBookstore(TestCase):
    @classmethod
    def setUpClass(cls):
        bookstore.db = os.path.join('database', 'test_books.db')
        BookStore.instance = None

    def setUp(self):
        self.BS = BookStore()
        self.clear_bookstore()

    def add_test_data(self):
        self.clear_bookstore()

        self.bk1 = Book('An Interesting Book', 'Ann Author', True)
        self.bk2 = Book('Booky Book Book', 'B. Bookwriter', False)
        self.bk3 = Book('Collection of words', 'Creative Creator')

        self.bk1.save()
        self.bk2.save()
        self.bk3.save()

    def clear_bookstore(self):
        self.BS.delete_all_books()

    def test_singleton(self):
        bs = BookStore()
        bs2 = BookStore()
        self.assertEqual(bs, bs2)

    def test_add_book_empty_store(self):
        bk = Book('aa', 'aaa')
        bk.save()
        self.assertTrue(self.BS.exact_match(bk))
        self.assertEqual(1, self.BS.book_count())

    def test_add_book_store_with_books_in(self):
        self.add_test_data()
        book_count = self.BS.book_count()
        bk = Book('aa', 'bbbbb')
        bk.save()
        self.assertTrue(self.BS.exact_match(bk))
        self.assertEqual(book_count + 1, self.BS.book_count())

    def test_add_book_duplicate_errors(self):
        bk = Book('aa', 'aaa')
        bk.save()
        with self.assertRaises(BookError):
            bk_dupe = Book('aa', 'aaa')
            bk_dupe.save()

    def test_add_book_duplicate_errors_case_insensitive(self):
        bk = Book('a', 'a')
        bk.save()
        with self.assertRaises(BookError):
            bk_dupe = Book('a', 'A')
            bk_dupe.save()

    def test_get_book_by_id_found(self):
        self.add_test_data()
        result = self.BS.get_book_by_id(self.bk1.id)
        self.assertEqual(result, self.bk1)

    def test_get_book_by_id_not_found(self):
        # This test fails - student should fix
        self.add_test_data()
        result = self.BS.get_book_by_id(-1)
        self.assertIsNone(result)

    def test_delete_book(self):
        self.add_test_data()
        count = self.BS.book_count()
        self.BS.delete_book(self.bk2.id)
        self.assertEqual(count - 1, self.BS.book_count())
        self.assertFalse(self.BS.exact_match(self.bk2))

    def test_delete_book_not_in_store_errors(self):
        self.add_test_data()
        bk = Book('Not in store', 'Not in store')
        with self.assertRaises(BookError):
            self.BS.delete_book(-10)

    def test_delete_book_empty_list_errors(self):
        bk = Book('Not in store', 'Not in store')
        with self.assertRaises(BookError):
            self.BS.delete_book(-100)

    def test_delete_all_books(self):
        bk1 = Book('Not in store', 'Not in store')
        bk2 = Book('Whatever', 'Whatever')
        bk1.save()
        bk2.save()

        self.BS.delete_all_books()
        self.assertEqual(0, self.BS.book_count())

    def test_delete_all_books_empty(self):
        self.BS.delete_all_books()
        self.assertEqual(0, self.BS.book_count())

    def test_count_books(self):
        self.add_test_data()
        count = self.BS.book_count()
        self.assertEqual(3, count)

    def test_set_read_book_read(self):
        self.add_test_data()
        self.bk1.read = True
        self.bk1.save()

        bk1_from_store = self.BS.get_book_by_id(self.bk1.id)
        self.assertTrue(bk1_from_store.read)

    def test_set_unread_book_read(self):
        self.add_test_data()
        self.bk2.read = True
        self.bk2.save()

        bk2_from_store = self.BS.get_book_by_id(self.bk2.id)
        self.assertTrue(bk2_from_store.read)

    def test_set_read_book_unread(self):
        self.add_test_data()

        self.bk1.read = False
        self.bk1.save()

        bk1_from_store = self.BS.get_book_by_id(self.bk1.id)
        self.assertFalse(bk1_from_store.read)

    def test_set_unread_book_unread(self):
        self.add_test_data()
        self.bk2.read = False
        self.bk2.save()

        bk2_from_store = self.BS.get_book_by_id(self.bk2.id)
        self.assertFalse(bk2_from_store.read)

    def test_get_all_books(self):
        self.add_test_data()
        self.assertCountEqual([self.bk1, self.bk2, self.bk3],
                              self.BS.get_all_books())

    def test_is_book_in_store_present(self):
        self.add_test_data()
        self.assertTrue(self.BS.exact_match(self.bk1))
        self.assertTrue(self.BS.exact_match(self.bk2))
        self.assertTrue(self.BS.exact_match(self.bk3))

    def test_is_book_in_store_not_present(self):
        not_in_store = Book('aaaa', 'bbbb')
        self.add_test_data()
        self.assertFalse(self.BS.exact_match(not_in_store))

    def test_is_book_in_store_empty_list(self):
        self.clear_bookstore()
        not_in_store = Book('aaaa', 'bbbb')
        self.assertFalse(self.BS.exact_match(not_in_store))

    def test_search_book_author_match(self):
        self.add_test_data()
        self.assertCountEqual([self.bk1], self.BS.book_search('Ann'))

    def test_search_book_title_match(self):
        self.add_test_data()
        self.assertCountEqual([self.bk1, self.bk2],
                              self.BS.book_search('Book'))

    def test_search_book_not_found(self):
        self.add_test_data()
        self.assertEqual([], self.BS.book_search('Not in list'))

    def test_search_book_empty_store(self):
        self.clear_bookstore()
        self.assertEqual([], self.BS.book_search('Not in list'))

    def test_search_book_case_insensitive_title_match(self):
        self.add_test_data()
        self.assertCountEqual([self.bk1, self.bk2],
                              self.BS.book_search('bOoK'))

    def test_search_book_case_insensitive_author_match(self):
        self.add_test_data()
        self.assertCountEqual([self.bk3], self.BS.book_search('cReAtOr'))

    def test_exact_match_found(self):
        self.add_test_data()
        bk = Book('Collection of words', 'Creative Creator')
        self.assertTrue(self.BS.exact_match(bk))

    def test_exact_match_not_found_author(self):
        self.add_test_data()
        bk = Book('Collection of words', 'Someone Else')
        self.assertFalse(self.BS.exact_match(bk))

    def test_exact_match_not_found_title(self):
        self.add_test_data()
        bk = Book('Collection of Stories', 'Creative Creator')
        self.assertFalse(self.BS.exact_match(bk))

    def test_exact_match_not_found_title_author(self):
        self.add_test_data()
        bk = Book('Collection of Cheese', 'Beyonce')
        self.assertFalse(self.BS.exact_match(bk))

    def test_exact_match_not_found_empty_store(self):
        bk = Book('Whatever', 'Whatever')
        self.clear_bookstore()
        self.assertFalse(self.BS.exact_match(bk))

    def test_get_books_by_read_read(self):
        self.add_test_data()
        read_books = self.BS.get_books_by_read_value(True)
        self.assertCountEqual([self.bk1], read_books)

    def test_get_books_by_read_unread(self):
        self.add_test_data()
        read_books = self.BS.get_books_by_read_value(False)
        self.assertCountEqual([self.bk2, self.bk3], read_books)
 def test_add_book_duplicate_errors(self):
     bk = Book('aa', 'aaa')
     bk.save()
     with self.assertRaises(BookError):
         bk_dupe = Book('aa', 'aaa')
         bk_dupe.save()
 def test_delete_book_not_in_store_errors(self):
     self.add_test_data()
     bk = Book('Not in store', 'Not in store')
     with self.assertRaises(BookError):
         self.BS.delete_book(-10)