more openlibrary connector tests

This commit is contained in:
Mouse Reeve 2020-05-10 14:12:03 -07:00
parent 5e78de1340
commit d5f46a1c6f
2 changed files with 15 additions and 1 deletions

View file

@ -35,7 +35,7 @@ class Connector(AbstractConnector):
def is_work_data(self, data): def is_work_data(self, data):
return not re.match(r'^OL\d+M$', data['key']) return bool(re.match(r'^[\/\w]+OL\d+W$', data['key']))
def get_edition_from_work_data(self, data): def get_edition_from_work_data(self, data):

View file

@ -8,6 +8,7 @@ import pytz
from fedireads import models from fedireads import models
from fedireads.connectors.openlibrary import Connector from fedireads.connectors.openlibrary import Connector
from fedireads.connectors.openlibrary import get_languages, get_description from fedireads.connectors.openlibrary import get_languages, get_description
from fedireads.connectors.openlibrary import pick_default_edition
from fedireads.connectors.abstract_connector import SearchResult, get_date from fedireads.connectors.abstract_connector import SearchResult, get_date
@ -29,8 +30,21 @@ class Openlibrary(TestCase):
'data/ol_work.json') 'data/ol_work.json')
edition_file = pathlib.Path(__file__).parent.joinpath( edition_file = pathlib.Path(__file__).parent.joinpath(
'data/ol_edition.json') 'data/ol_edition.json')
edition_list_file = pathlib.Path(__file__).parent.joinpath(
'data/ol_edition_list.json')
self.work_data = json.loads(work_file.read_bytes()) self.work_data = json.loads(work_file.read_bytes())
self.edition_data = json.loads(edition_file.read_bytes()) self.edition_data = json.loads(edition_file.read_bytes())
self.edition_list_data = json.loads(edition_list_file.read_bytes())
def test_is_work_data(self):
self.assertEqual(self.connector.is_work_data(self.work_data), True)
self.assertEqual(self.connector.is_work_data(self.edition_data), False)
def test_pick_default_edition(self):
edition = pick_default_edition(self.edition_list_data['entries'])
self.assertEqual(edition['key'], '/books/OL9952943M')
def test_format_search_result(self): def test_format_search_result(self):