コード例 #1
0
def update_author_from_remote(request, author_id, connector_identifier):
    """load the remote data for this author"""
    connector = connector_manager.load_connector(
        get_object_or_404(models.Connector, identifier=connector_identifier))
    author = get_object_or_404(models.Author, id=author_id)

    connector.update_author_from_remote(author)

    return redirect("author", author.id)
コード例 #2
0
ファイル: test_import_model.py プロジェクト: AylaJK/bookwyrm
    def test_get_book_from_isbn(self):
        """search and load books by isbn (9780356506999)"""
        connector_info = models.Connector.objects.create(
            identifier="openlibrary.org",
            name="OpenLibrary",
            connector_file="openlibrary",
            base_url="https://openlibrary.org",
            books_url="https://openlibrary.org",
            covers_url="https://covers.openlibrary.org",
            search_url="https://openlibrary.org/search?q=",
            priority=3,
        )
        connector = connector_manager.load_connector(connector_info)
        result = SearchResult(
            title="Test Result",
            key="https://openlibrary.org/works/OL1234W",
            author="An Author",
            year="1980",
            connector=connector,
        )

        datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_edition.json")
        bookdata = json.loads(datafile.read_bytes())
        responses.add(
            responses.GET,
            "https://openlibrary.org/works/OL1234W",
            json=bookdata,
            status=200,
        )
        responses.add(
            responses.GET,
            "https://openlibrary.org/works/OL15832982W",
            json=bookdata,
            status=200,
        )
        responses.add(
            responses.GET,
            "https://openlibrary.org/authors/OL382982A",
            json={"name": "test author"},
            status=200,
        )

        with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"):
            with patch(
                "bookwyrm.connectors.connector_manager.first_search_result"
            ) as search:
                search.return_value = result
                with patch(
                    "bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
                ):
                    with patch(
                        "bookwyrm.preview_images.generate_edition_preview_image_task.delay"
                    ):
                        book = self.item_1.get_book_from_isbn()

        self.assertEqual(book.title, "Sabriel")
コード例 #3
0
def update_book_from_remote(request, book_id, connector_identifier):
    """load the remote data for this book"""
    connector = connector_manager.load_connector(
        get_object_or_404(models.Connector, identifier=connector_identifier))
    book = get_object_or_404(models.Book.objects.select_subclasses(),
                             id=book_id)

    try:
        connector.update_book_from_remote(book)
    except ConnectorException:
        # the remote source isn't available or doesn't know this book
        return Book().get(request, book_id, update_error=True)

    return redirect("book", book.id)
コード例 #4
0
    def test_get_book_from_isbn(self):
        ''' search and load books by isbn (9780356506999) '''
        connector_info = models.Connector.objects.create(
            identifier='openlibrary.org',
            name='OpenLibrary',
            connector_file='openlibrary',
            base_url='https://openlibrary.org',
            books_url='https://openlibrary.org',
            covers_url='https://covers.openlibrary.org',
            search_url='https://openlibrary.org/search?q=',
            priority=3,
        )
        connector = connector_manager.load_connector(connector_info)
        result = SearchResult(
            title='Test Result',
            key='https://openlibrary.org/works/OL1234W',
            author='An Author',
            year='1980',
            connector=connector,
        )

        datafile = pathlib.Path(__file__).parent.joinpath(
            '../data/ol_edition.json')
        bookdata = json.loads(datafile.read_bytes())
        responses.add(responses.GET,
                      'https://openlibrary.org/works/OL1234W',
                      json=bookdata,
                      status=200)
        responses.add(responses.GET,
                      'https://openlibrary.org/works/OL15832982W',
                      json=bookdata,
                      status=200)
        responses.add(responses.GET,
                      'https://openlibrary.org/authors/OL382982A',
                      json={'name': 'test author'},
                      status=200)

        with patch(
                'bookwyrm.connectors.abstract_connector.load_more_data.delay'):
            with patch(
                    'bookwyrm.connectors.connector_manager.first_search_result'
            ) as search:
                search.return_value = result
                book = self.item_1.get_book_from_isbn()

        self.assertEqual(book.title, 'Sabriel')
コード例 #5
0
 def test_load_connector(self):
     """load a connector object from the database entry"""
     connector = connector_manager.load_connector(self.remote_connector)
     self.assertEqual(connector.identifier, "test_connector_remote")
コード例 #6
0
 def test_load_connector(self):
     """ load a connector object from the database entry """
     connector = connector_manager.load_connector(self.connector)
     self.assertIsInstance(connector, SelfConnector)
     self.assertEqual(connector.identifier, "test_connector")