113 lines
3.3 KiB
Python
113 lines
3.3 KiB
Python
"""Tests for the __init__.py wrapper classes."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
import requests
|
|
|
|
from bibapi import DNB, HBZ, HEBIS, KOBV, OEVK, SWB
|
|
from bibapi.schemas.api_types import (
|
|
ALMASchema,
|
|
DublinCoreSchema,
|
|
PicaSchema,
|
|
)
|
|
|
|
|
|
class TestSWBWrapper:
|
|
"""Tests for the SWB wrapper class."""
|
|
|
|
def test_swb_initialization(self):
|
|
"""Test SWB initializes with correct config."""
|
|
api = SWB()
|
|
assert api.site == "SWB"
|
|
assert "sru.k10plus.de" in api.url
|
|
assert api.prefix == PicaSchema
|
|
assert api.library_identifier == "924$b"
|
|
api.close()
|
|
|
|
@patch.object(requests.Session, "get")
|
|
def test_swb_getbooks(self, mock_get):
|
|
"""Test SWB getBooks method."""
|
|
mock_response = MagicMock()
|
|
mock_response.status_code = 200
|
|
mock_response.content = b"""<?xml version="1.0"?>
|
|
<zs:searchRetrieveResponse xmlns:zs="http://www.loc.gov/zing/srw/">
|
|
<zs:version>1.1</zs:version>
|
|
<zs:numberOfRecords>0</zs:numberOfRecords>
|
|
</zs:searchRetrieveResponse>"""
|
|
mock_get.return_value = mock_response
|
|
|
|
api = SWB()
|
|
books = api.getBooks(["TITLE=Test"])
|
|
assert isinstance(books, list)
|
|
api.close()
|
|
|
|
|
|
class TestDNBWrapper:
|
|
"""Tests for the DNB wrapper class."""
|
|
|
|
def test_dnb_initialization(self):
|
|
"""Test DNB initializes with correct config.
|
|
|
|
Note: DNB class has a bug - it doesn't set library_identifier before
|
|
calling super().__init__. This test documents the bug.
|
|
"""
|
|
# DNB has a bug - library_identifier is not set
|
|
with pytest.raises(AttributeError, match="library_identifier"):
|
|
api = DNB()
|
|
|
|
|
|
class TestKOBVWrapper:
|
|
"""Tests for the KOBV wrapper class."""
|
|
|
|
def test_kobv_initialization(self):
|
|
"""Test KOBV initializes with correct config."""
|
|
api = KOBV()
|
|
assert api.site == "KOBV"
|
|
assert "sru.kobv.de" in api.url
|
|
assert api.prefix == DublinCoreSchema
|
|
assert api.library_identifier == "924$b"
|
|
api.close()
|
|
|
|
|
|
class TestHEBISWrapper:
|
|
"""Tests for the HEBIS wrapper class."""
|
|
|
|
def test_hebis_initialization(self):
|
|
"""Test HEBIS initializes with correct config."""
|
|
api = HEBIS()
|
|
assert api.site == "HEBIS"
|
|
assert "sru.hebis.de" in api.url
|
|
assert api.prefix == PicaSchema
|
|
assert api.library_identifier == "924$b"
|
|
# HEBIS has specific replace patterns
|
|
assert " " in api.replace
|
|
# HEBIS has unsupported args
|
|
assert "YEAR" in api.notsupported_args
|
|
api.close()
|
|
|
|
|
|
class TestOEVKWrapper:
|
|
"""Tests for the OEVK wrapper class."""
|
|
|
|
def test_oevk_initialization(self):
|
|
"""Test OEVK initializes with correct config."""
|
|
api = OEVK()
|
|
assert api.site == "OEVK"
|
|
assert api.prefix == PicaSchema
|
|
assert api.library_identifier == "924$b"
|
|
api.close()
|
|
|
|
|
|
class TestHBZWrapper:
|
|
"""Tests for the HBZ wrapper class."""
|
|
|
|
def test_hbz_initialization(self):
|
|
"""Test HBZ initializes with correct config."""
|
|
api = HBZ()
|
|
assert api.site == "HBZ"
|
|
assert "alma.exlibrisgroup.com" in api.url
|
|
assert api.prefix == ALMASchema
|
|
assert api.library_identifier == "852$a"
|
|
api.close()
|