chore: move dependencies, add more tests
This commit is contained in:
48
tests/test_catalogue.py
Normal file
48
tests/test_catalogue.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for the Catalogue class, which interacts with the library catalogue."""
|
||||
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from src.bibapi.catalogue import Catalogue
|
||||
|
||||
|
||||
class TestCatalogue:
|
||||
"""Tests for the Catalogue class."""
|
||||
|
||||
def test_check_book_exists(self, mocker: MockerFixture):
|
||||
"""Test the check_book_exists method of the Catalogue class."""
|
||||
catalogue = Catalogue()
|
||||
|
||||
# Mock the get_book_links method to control its output
|
||||
mocker.patch.object(
|
||||
catalogue,
|
||||
"get_book_links",
|
||||
return_value=["link1", "link2"],
|
||||
)
|
||||
|
||||
# Test with a known existing book
|
||||
existing_book_searchterm = "1693321114"
|
||||
assert catalogue.check_book_exists(existing_book_searchterm) is True
|
||||
|
||||
# Change the mock to return an empty list for non-existing book
|
||||
mocker.patch.object(
|
||||
catalogue,
|
||||
"get_book_links",
|
||||
return_value=[],
|
||||
)
|
||||
|
||||
# Test with a known non-existing book
|
||||
non_existing_book_searchterm = "00000000009"
|
||||
assert catalogue.check_book_exists(non_existing_book_searchterm) is False
|
||||
|
||||
def test_no_connection_raises_error(self, mocker: MockerFixture):
|
||||
"""Test that a ConnectionError is raised when there is no internet connection."""
|
||||
# Mock the check_connection method to simulate no internet connection
|
||||
mocker.patch.object(
|
||||
Catalogue,
|
||||
"check_connection",
|
||||
return_value=False,
|
||||
)
|
||||
|
||||
with pytest.raises(ConnectionError, match="No internet connection available."):
|
||||
Catalogue()
|
||||
Reference in New Issue
Block a user