chore: move dependencies, add more tests

This commit is contained in:
2025-12-05 11:21:41 +01:00
parent 8455322af4
commit 30e4cded8f
10 changed files with 608 additions and 6 deletions

48
tests/test_catalogue.py Normal file
View 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()