Exemple #1
0
 def test_single_book_with_branch_and_language(self):
     self.assertEqual(
         QueryBuilder.bibliocommons_query(books=[don_quixote],
                                          branch='Fremont Branch',
                                          isolanguage='eng'),
         '(identifier:(0142437239)) available:"Fremont Branch" isolanguage:"eng"',
     )
Exemple #2
0
 def test_no_known_isbn(self):
     self.assertEqual(
         QueryBuilder.bibliocommons_query(books=[moby_dick],
                                          branch=None,
                                          isolanguage=None),
         '(contributor:(Herman Melville) AND title:(Moby Dick) AND formatcode:(BK))',
     )
Exemple #3
0
 def test_single_isbn(self):
     self.assertEqual(
         QueryBuilder.bibliocommons_query(books=[don_quixote],
                                          branch=None,
                                          isolanguage=None),
         'identifier:(0142437239)',
     )
Exemple #4
0
 def test_no_book_options_okay(self):
     self.assertEqual(
         QueryBuilder.bibliocommons_query(books=[moby_dick],
                                          branch=None,
                                          isolanguage=None,
                                          print_only=False),
         '(contributor:(Herman Melville) AND title:(Moby Dick))',
     )
Exemple #5
0
    def test_query_way_too_long(self):
        """ A query is only valid when it is below 900 characters. """
        lots_of_books = [
            GoodreadsBook(
                goodreads_id="123456",
                isbn=f"0000000{i:03d}",
                title="Unknown",
                author="Unknown",
                description="This won't be used in the query",
                image_url="not relevant, so not a real URL",
            ) for i in range(50)
        ]

        # It's valid to query for a small number of books
        QueryBuilder.bibliocommons_query(books=lots_of_books[:10],
                                         branch=None,
                                         isolanguage=None)
        # Querying for too many introduces an exception
        with self.assertRaises(QueryError):
            QueryBuilder.bibliocommons_query(books=lots_of_books,
                                             branch=None,
                                             isolanguage=None)
Exemple #6
0
 def test_two_books(self):
     self.assertEqual(
         QueryBuilder.bibliocommons_query(
             books=[don_quixote, moby_dick],
             branch='Fremont Branch',
             isolanguage='eng',
         ),
         (
             # Don Quixote has an ISBN
             '(identifier:(0142437239)'
             ' OR '
             # Moby Dick has no ISBN - so we look for title, Author, book type
             '(contributor:(Herman Melville) AND title:(Moby Dick) AND formatcode:(BK)))'
             # Both books are queried as in English and at the Fremont Branch
             ' available:"Fremont Branch" isolanguage:"eng"'),
     )