Exemplo n.º 1
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
                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")
 def test_search_result(self):
     ''' a class that stores info about a search result '''
     result = SearchResult(
         title='Title',
         key='https://example.com/book/1',
         author='Author Name',
         year='1850',
         connector=self.test_connector,
     )
     # there's really not much to test here, it's just a dataclass
     self.assertEqual(result.confidence, 1)
     self.assertEqual(result.title, 'Title')
Exemplo n.º 3
0
 def test_search_result(self):
     """ a class that stores info about a search result """
     result = SearchResult(
         title="Title",
         key="https://example.com/book/1",
         author="Author Name",
         year="1850",
         connector=self.test_connector,
     )
     # there's really not much to test here, it's just a dataclass
     self.assertEqual(result.confidence, 1)
     self.assertEqual(result.title, "Title")
Exemplo n.º 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')