Runs black

This commit is contained in:
Mouse Reeve
2021-03-08 08:49:10 -08:00
parent a07f955781
commit 70296e760b
198 changed files with 10239 additions and 8572 deletions

View File

@ -1,4 +1,4 @@
''' testing book data connectors '''
""" testing book data connectors """
import json
import pathlib
from django.test import TestCase
@ -9,39 +9,36 @@ from bookwyrm.connectors.abstract_connector import SearchResult
class BookWyrmConnector(TestCase):
''' this connector doesn't do much, just search '''
def setUp(self):
''' create the connector '''
models.Connector.objects.create(
identifier='example.com',
connector_file='bookwyrm_connector',
base_url='https://example.com',
books_url='https://example.com',
covers_url='https://example.com/images/covers',
search_url='https://example.com/search?q=',
)
self.connector = Connector('example.com')
""" this connector doesn't do much, just search """
work_file = pathlib.Path(__file__).parent.joinpath(
'../data/bw_work.json')
edition_file = pathlib.Path(__file__).parent.joinpath(
'../data/bw_edition.json')
def setUp(self):
""" create the connector """
models.Connector.objects.create(
identifier="example.com",
connector_file="bookwyrm_connector",
base_url="https://example.com",
books_url="https://example.com",
covers_url="https://example.com/images/covers",
search_url="https://example.com/search?q=",
)
self.connector = Connector("example.com")
work_file = pathlib.Path(__file__).parent.joinpath("../data/bw_work.json")
edition_file = pathlib.Path(__file__).parent.joinpath("../data/bw_edition.json")
self.work_data = json.loads(work_file.read_bytes())
self.edition_data = json.loads(edition_file.read_bytes())
def test_format_search_result(self):
''' create a SearchResult object from search response json '''
datafile = pathlib.Path(__file__).parent.joinpath(
'../data/bw_search.json')
""" create a SearchResult object from search response json """
datafile = pathlib.Path(__file__).parent.joinpath("../data/bw_search.json")
search_data = json.loads(datafile.read_bytes())
results = self.connector.parse_search_data(search_data)
self.assertIsInstance(results, list)
result = self.connector.format_search_result(results[0])
self.assertIsInstance(result, SearchResult)
self.assertEqual(result.title, 'Jonathan Strange and Mr Norrell')
self.assertEqual(result.key, 'https://example.com/book/122')
self.assertEqual(result.author, 'Susanna Clarke')
self.assertEqual(result.title, "Jonathan Strange and Mr Norrell")
self.assertEqual(result.key, "https://example.com/book/122")
self.assertEqual(result.author, "Susanna Clarke")
self.assertEqual(result.year, 2017)
self.assertEqual(result.connector, self.connector)