Updates connector tests

This commit is contained in:
Mouse Reeve 2020-12-03 13:22:50 -08:00
parent de7e64932a
commit 9c6db1cc0e
2 changed files with 8 additions and 17 deletions

View file

@ -3,7 +3,7 @@ from django.test import TestCase
from bookwyrm import models from bookwyrm import models
from bookwyrm.connectors.abstract_connector import Mapping from bookwyrm.connectors.abstract_connector import Mapping
from bookwyrm.connectors.bookwyrm_connector import Connector from bookwyrm.connectors.openlibrary import Connector
class AbstractConnector(TestCase): class AbstractConnector(TestCase):
@ -12,7 +12,7 @@ class AbstractConnector(TestCase):
models.Connector.objects.create( models.Connector.objects.create(
identifier='example.com', identifier='example.com',
connector_file='bookwyrm_connector', connector_file='openlibrary',
base_url='https://example.com', base_url='https://example.com',
books_url='https:/example.com', books_url='https:/example.com',
covers_url='https://example.com', covers_url='https://example.com',

View file

@ -1,16 +1,17 @@
''' testing book data connectors ''' ''' testing book data connectors '''
from dateutil import parser
from django.test import TestCase
import json import json
import pathlib import pathlib
from django.test import TestCase
from bookwyrm import models from bookwyrm import models
from bookwyrm.connectors.bookwyrm_connector import Connector from bookwyrm.connectors.bookwyrm_connector import Connector
from bookwyrm.connectors.abstract_connector import SearchResult, get_date from bookwyrm.connectors.abstract_connector import SearchResult
class BookWyrmConnector(TestCase): class BookWyrmConnector(TestCase):
''' this connector doesn't do much, just search '''
def setUp(self): def setUp(self):
''' create the connector '''
models.Connector.objects.create( models.Connector.objects.create(
identifier='example.com', identifier='example.com',
connector_file='bookwyrm_connector', connector_file='bookwyrm_connector',
@ -29,13 +30,9 @@ class BookWyrmConnector(TestCase):
self.edition_data = json.loads(edition_file.read_bytes()) self.edition_data = json.loads(edition_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_format_search_result(self): def test_format_search_result(self):
datafile = pathlib.Path(__file__).parent.joinpath('../data/fr_search.json') datafile = pathlib.Path(__file__).parent.joinpath(
'../data/fr_search.json')
search_data = json.loads(datafile.read_bytes()) search_data = json.loads(datafile.read_bytes())
results = self.connector.parse_search_data(search_data) results = self.connector.parse_search_data(search_data)
self.assertIsInstance(results, list) self.assertIsInstance(results, list)
@ -46,9 +43,3 @@ class BookWyrmConnector(TestCase):
self.assertEqual(result.key, 'https://example.com/book/122') self.assertEqual(result.key, 'https://example.com/book/122')
self.assertEqual(result.author, 'Susanna Clarke') self.assertEqual(result.author, 'Susanna Clarke')
self.assertEqual(result.year, 2017) self.assertEqual(result.year, 2017)
def test_get_date(self):
date = get_date(self.edition_data['published_date'])
expected = parser.parse("2020-09-15T00:00:00+00:00")
self.assertEqual(date, expected)