From fe9d4ff775e805be3160888bace92aa18aeeb924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriele=20H=C3=B6fler?= Date: Thu, 1 Aug 2019 11:50:11 +0200 Subject: [PATCH] First simple tests for almasru --- sru/tests/test_almasru.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/sru/tests/test_almasru.py b/sru/tests/test_almasru.py index 9fd155e..8118deb 100644 --- a/sru/tests/test_almasru.py +++ b/sru/tests/test_almasru.py @@ -1,26 +1,40 @@ +"""Tests for almasru""" + +from xml.etree.ElementTree import Element import pytest import sru.almasru as almasru RETRIEVER = almasru.RecordRetriever('obv-at-oenb', '43ACC_ONB', 'marcxml') +QUERY_MULTIPLE = "alma.local_control_field_009=AC13320616 OR alma.local_control_field_009=AC13320328" +QUERY_UNIQUE = "alma.local_control_field_009=AC13320616" +QUERY_HUNDREDS = "alma.creator=Stocker" class TestRecordRetriever: + """Test RecordRetriever""" def test_erroneous_xml(self): with pytest.raises(almasru.SruException): RETRIEVER.by_mms_id('MMS-ID') def test_get_multiple(self): - query = "alma.local_control_field_009=AC13320616 OR alma.local_control_field_009=AC13320328" - RETRIEVER.get_multiple(query) + RETRIEVER.get_multiple(QUERY_MULTIPLE) assert True def test_get_unique(self): - query = "alma.local_control_field_009=AC13320616" - RETRIEVER.get_unique(query) + RETRIEVER.get_unique(QUERY_UNIQUE) assert True def test_not_unique(self): - query = "alma.local_control_field_009=AC13320616 OR alma.local_control_field_009=AC13320328" with pytest.raises(almasru.NotUnique): - RETRIEVER.get_unique(query) + RETRIEVER.get_unique(QUERY_MULTIPLE) + + def test_get_multiple_has_elements(self): + first_element = RETRIEVER.get_multiple(QUERY_MULTIPLE)[0] + assert isinstance(first_element, Element) + +# The following takes approx 2 minutes. Only uncomment if you have the time! + def test_get_multiple_hundreds(self): + hundreds = RETRIEVER.get_multiple(QUERY_HUNDREDS) + num_of_elements = len(hundreds) + assert int(num_of_elements) is 771 -- GitLab