Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite library module tests to use mocked inputs #169

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/autotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ jobs:
- name: Run all tests with pytest
run: pytest --cov=pittapi tests/
--ignore=tests/lab_test.py
--ignore=tests/library_test.py
--ignore=tests/people_test.py
1 change: 0 additions & 1 deletion .github/workflows/tests-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ jobs:
- name: Test with pytest
run: pytest --cov=pittapi tests/
--ignore=tests/lab_test.py
--ignore=tests/library_test.py
--ignore=tests/people_test.py
15 changes: 10 additions & 5 deletions pittapi/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
from html.parser import HTMLParser
from typing import Any, Dict, List

LIBRARY_URL = """https://pitt.primo.exlibrisgroup.com/primaws/rest/pub/pnxs?acTriggered=false&blendFac
etsSeparately=false&citationTrailFilterByAvailability=true&disableCache=false&getMore=0&inst=01PITT_INST&isCD
Search=false&lang=en&limit=10&newspapersActive=false&newspapersSearch=false&offset=0&otbRanking=false&pcAvai
lability=false&qExclude=&qInclude=&rapido=false&refEntryActive=false&rtaLinks=true&scope=MyInst_and_CI&searc
hInFulltextUserSelection=false&skipDelivery=Y&sort=rank&tab=Everything&vid=01PITT_INST:01PITT_INST"""
LIBRARY_URL = (
"https://pitt.primo.exlibrisgroup.com/primaws/rest/pub/pnxs"
"?acTriggered=false&blendFacetsSeparately=false"
"&citationTrailFilterByAvailability=true&disableCache=false&getMore=0"
"&inst=01PITT_INST&isCDSearch=false&lang=en&limit=10&newspapersActive=false"
"&newspapersSearch=false&offset=0&otbRanking=false&pcAvailability=false"
"&qExclude=&qInclude=&rapido=false&refEntryActive=false&rtaLinks=true"
"&scope=MyInst_and_CI&searchInFulltextUserSelection=false&skipDelivery=Y"
"&sort=rank&tab=Everything&vid=01PITT_INST:01PITT_INST"
)

QUERY_START = "&q=any,contains,"

Expand Down
3 changes: 1 addition & 2 deletions tests/dining_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs):

with (SAMPLE_PATH / 'dining_menu.json').open() as f:
self.dining_menu_data = json.load(f)


@responses.activate
def test_get_locations(self):
Expand Down Expand Up @@ -70,4 +70,3 @@ def test_get_location_menu(self):
json=self.dining_menu_data, status=200)
locations = dining.get_location_menu("The Eatery", datetime.datetime(2024, 4, 12), "Breakfast")
self.assertIsInstance(locations, dict)

36 changes: 22 additions & 14 deletions tests/library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,32 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""

import json
import unittest
import pytest
from pathlib import Path

from pittapi import library
import responses

class LibraryTest(unittest.TestCase):
def test_get_documents(self):
self.assertIsInstance(library.get_documents("water"), dict)
from pittapi import library

SAMPLE_PATH = Path() / 'tests' / 'samples'

@pytest.mark.skip(reason="bookmarks seem to not be supported in new API anymore")
def test_get_document_by_bookmark(self):
bookmark_test = library.get_document_by_bookmark("ePnHCXMw42LgT" +
"QStzc4rAe_hSmEGbaYyt7QAHThpwMYgouGcGJDo6hSkCezyGQI7SJYmZgacDKzhQ" +
"LXAWkDazTXE2UMXdOZRPHT8Ih50Ha6hBehic_yyKlhkYVM48RbmFiamxibGAFlyLRc")
self.assertIsInstance(bookmark_test, dict)

class LibraryTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
with (SAMPLE_PATH / 'library_mock_response_water.json').open() as f:
self.library_query = json.load(f)

@pytest.mark.skip(reason="bookmarks seem to not be supported in new API anymore")
def test_invalid_bookmark(self):
self.assertRaises(ValueError, library.get_document_by_bookmark("abcd"))
@responses.activate
def test_get_documents(self):
responses.add(
responses.GET,
library.LIBRARY_URL + library.QUERY_START + "water",
json=self.library_query,
status=200
)
query_result = library.get_documents("water")
self.assertIsInstance(query_result, dict)
self.assertEqual(query_result["pages"], 10)
self.assertEqual(len(query_result["docs"]), 10)
4 changes: 2 additions & 2 deletions tests/people_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_people_get_person(self):
def test_people_get_person_too_many(self):
responses.add(responses.POST, people.PEOPLE_SEARCH_URL,
body=TOO_MANY_TEST_DATA, status=200)

ans = people.get_person("Smith")
self.assertIsInstance(ans,list)
self.assertEqual(ans, [{"ERROR":"Too many people matched your criteria."}])
Expand All @@ -134,7 +134,7 @@ def test_people_get_person_too_many(self):
def test_people_get_person_none(self):
responses.add(responses.POST, people.PEOPLE_SEARCH_URL,
body=NONE_FOUND_TEST_DATA, status=200)

ans = people.get_person("Lebron Iverson Jordan Kobe")
self.assertIsInstance(ans,list)
self.assertEqual(ans, [{"ERROR":"No one found."}])
Loading
Loading