def test_xisbn_to_books(self):
        with open(example_path('0140551042_xisbn.json')) as _xisbn:
            xisbn = json.load(_xisbn)
            books = Book.xisbn_to_books(xisbn)
            self.assertTrue(len(books) == len(XISBN_BOOKS))
            for i in range(len(books)):

                self.assertTrue(books[i].title == XISBN_BOOKS[i].title,
                                "Got title %s, expected title %s" % \
                                (books[i].title, XISBN_BOOKS[i].title))

                self.assertTrue([books[i].authors[k].name == \
                                 XISBN_BOOKS[i].authors[k].name
                                 for k in range(len(books[i].authors))],
                                "Got authors %s \n expected authors %s" % \
                                (books[i].authors, XISBN_BOOKS[i].authors))

                self.assertTrue(books[i].publisher == XISBN_BOOKS[i].publisher,
                                "Got publisher %s, expected publisher %s" % \
                                (books[i].publisher, XISBN_BOOKS[i].publisher))

                self.assertTrue(books[i].identifiers == XISBN_BOOKS[i].identifiers,
                                "Got identifiers %s, expected identifiers %s" % \
                                (books[i].identifiers, XISBN_BOOKS[i].identifiers))

                self.assertTrue(books[i].publish_date == XISBN_BOOKS[i].publish_date,
                                "Got publish_date %s, expected publish_date %s" % \
                                (books[i].publish_date, XISBN_BOOKS[i].publish_date))
    def test_xisbn_to_books(self):
        with open(example_path('0140551042_xisbn.json')) as _xisbn:
            xisbn = json.load(_xisbn)
            books = Book.xisbn_to_books(xisbn)
            self.assertTrue(len(books) == len(XISBN_BOOKS))
            for i in range(len(books)):

                self.assertTrue(books[i].title == XISBN_BOOKS[i].title,
                                "Got title %s, expected title %s" % \
                                (books[i].title, XISBN_BOOKS[i].title))

                self.assertTrue([books[i].authors[k].name == \
                                 XISBN_BOOKS[i].authors[k].name
                                 for k in range(len(books[i].authors))],
                                "Got authors %s \n expected authors %s" % \
                                (books[i].authors, XISBN_BOOKS[i].authors))

                self.assertTrue(books[i].publisher == XISBN_BOOKS[i].publisher,
                                "Got publisher %s, expected publisher %s" % \
                                (books[i].publisher, XISBN_BOOKS[i].publisher))

                self.assertTrue(books[i].identifiers == XISBN_BOOKS[i].identifiers,
                                "Got identifiers %s, expected identifiers %s" % \
                                (books[i].identifiers, XISBN_BOOKS[i].identifiers))

                self.assertTrue(books[i].publish_date == XISBN_BOOKS[i].publish_date,
                                "Got publish_date %s, expected publish_date %s" % \
                                (books[i].publish_date, XISBN_BOOKS[i].publish_date))
 def test_create_book(self, mock_get):
     book = Book(
         publisher='Karamanolis',
         title='Alles ber Mikrofone',
         identifiers={'isbn_10': ['3922238246']},
         publish_date=1982,
         authors=[Author(name='Karl Schwarzer')],
         publish_location='Neubiberg bei Mnchen',
     )
     author_autocomplete = [{'name': "Karl Schwarzer", 'key': "/authors/OL7292805A"}]
     mock_get.return_value.json.return_value = author_autocomplete
     got_result = self.ol.create_book(book, debug=True)
     mock_get.assert_called_with(
         "{}/authors/_autocomplete?q={}&limit=1".format(
             self.ol.base_url, "Karl Schwarzer"
         )
     )
     expected_result = {
         '_save': '',
         'author_key': '/authors/OL7292805A',
         'author_name': 'Karl Schwarzer',
         'id_name': 'isbn_10',
         'id_value': '3922238246',
         'publish_date': 1982,
         'publisher': 'Karamanolis',
         'title': 'Alles ber Mikrofone',
     }
     self.assertTrue(
         got_result == expected_result,
         "Expected create_book to return %s, got %s" % (expected_result, got_result),
     )
 def test_canonical_title(self):
     """This also effectively tests `book.rm_punctuation`"""
     book = Book(title=u"The Autobiography of: Benjamin Franklin")
     expected = u"the autobiography of benjamin franklin"
     got = book.canonical_title
     self.assertTrue(got == expected,
                     "Title canonicalization expected %s, got %s" \
                     % (expected, got))
Beispiel #5
0
 def to_book(self):
     """Converts an OpenLibrary Search API Results Document to a
     standardized Book
     """
     publisher = self.publishers[0] if self.publishers else ""
     return Book(
         title=self.title,
         subtitle=self.subtitle,
         identifiers=self.identifiers,
         authors=self.authors,
         publisher=publisher,
         publish_date=self.first_publish_year,
     )
    def test_create_book(self):
        book = Book(title="Test Book", author="Jane Doe", year=2015)
        self.assertTrue(
            book.title == "Test Book",
            "Book title should be %s, instead is %s" %
            ("Test Book", book.title))

        self.assertTrue(
            book.author == "Jane Doe",
            "Book author should be %s, instead is %s" %
            ("Jane Doe", book.author))

        self.assertTrue(
            book.year == 2015,
            "Book year should be %s, instead is %s" % (2015, book.year))
    def test_create_book(self):
        book = Book(title="Test Book", authors=["Jane Doe"], publish_date=2015)
        self.assertTrue(
            book.title == "Test Book",
            f"Book title should be Test Book, instead is {book.title}",
        )

        self.assertTrue(
            book.authors[0] == "Jane Doe",
            f"Book author should be Jane Doe, instead is {book.authors}",
        )

        self.assertTrue(
            book.publish_date == 2015,
            f"Book year should be {2015}, instead is {book.publish_date}",
        )
Beispiel #8
0
    def test_create_book(self):
        book = Book(title="Test Book", authors=["Jane Doe"], publish_date=2015)
        self.assertTrue(
            book.title == "Test Book",
            "Book title should be %s, instead is %s" %
            ("Test Book", book.title))

        self.assertTrue(
            book.authors[0] == "Jane Doe",
            "Book author should be %s, instead is %s" %
            ("Jane Doe", book.authors))

        self.assertTrue(
            book.publish_date == 2015,
            "Book year should be %s, instead is %s" %
            (2015, book.publish_date))
Beispiel #9
0
 def create(cls, book: Book, debug=False) -> Work:
     """Creates a new work along with a new edition
     Usage:
         >>> from olclient.openlibrary import OpenLibrary
         >>> import olclient.common as common
         >>> book = common.Book(title=u"Warlight: A novel", authors=[common.Author(name=u"Michael Ondaatje")], publisher=u"Deckle Edge", publish_date=u"2018")
         >>> book.add_id(u'isbn_10', u'0525521194')
         >>> book.add_id(u'isbn_13', u'978-0525521198'))
         >>> ol.Work.create(book)
     """
     year_matches_in_date: list[Any] = re.findall(r'[\d]{4}', book.publish_date)
     book.publish_date = year_matches_in_date[0] if len(year_matches_in_date) > 0 else ''
     ed = cls.OL.create_book(book, debug=debug)
     ed.add_bookcover(book.cover)
     work = ed.work
     work.add_bookcover(book.cover)
     return ed
Beispiel #10
0
 def test_create_book(self):
     book = Book(publisher=u'Karamanolis',
                 title=u'Alles ber Mikrofone',
                 identifiers={'isbn_10': [u'3922238246']},
                 publish_date=1982,
                 authors=[Author(name=u'Karl Schwarzer')],
                 publish_location=u'Neubiberg bei Mnchen')
     got_result = self.ol.create_book(book, debug=True)
     expected_result = {
         '_save': '',
         'author_key': u'/authors/OL7292805A',
         'author_name': u'Karl Schwarzer',
         'id_name': 'isbn_10',
         'id_value': u'3922238246',
         'publish_date': 1982,
         'publisher': u'Karamanolis',
         'title': u'Alles ber Mikrofone'
     }
     self.assertTrue(got_result == expected_result,
                     "Expected create_book to return %s, got %s" \
                     % (got_result, expected_result))
        ),
        'xisbn',
    ))

example_path = lambda filename: os.path.join(EXAMPLES_PATH, filename)

XISBN_BOOKS = [
    Book(
        authors=[Author(name='Carl Bridenbaugh.')],
        cover='',
        identifiers={
            'isbn_10': ['0689705344'],
            'lccn': ['78152044'],
            'oclc':
            ['4128493', '466349680', '6066278', '730964000', '803233939'],
        },
        language='eng',
        pages=None,
        publish_date='1976',
        publisher='Atheneum',
        subtitle='',
        title=
        'Fat mutton and liberty of conscience : society in Rhode Island, 1636-1690',
    ),
    Book(
        authors=[Author(name='Carl Bridenbaugh.')],
        identifiers={
            'isbn_10': ['0571097987'],
            'lccn': [],
            'oclc': [
                '245795534',