New version of black, new whitespace
This commit is contained in:
@ -10,10 +10,10 @@ from bookwyrm.settings import DOMAIN
|
||||
|
||||
|
||||
class AbstractConnector(TestCase):
|
||||
""" generic code for connecting to outside data sources """
|
||||
"""generic code for connecting to outside data sources"""
|
||||
|
||||
def setUp(self):
|
||||
""" we need an example connector """
|
||||
"""we need an example connector"""
|
||||
self.connector_info = models.Connector.objects.create(
|
||||
identifier="example.com",
|
||||
connector_file="openlibrary",
|
||||
@ -38,7 +38,7 @@ class AbstractConnector(TestCase):
|
||||
self.edition_data = edition_data
|
||||
|
||||
class TestConnector(abstract_connector.AbstractConnector):
|
||||
""" nothing added here """
|
||||
"""nothing added here"""
|
||||
|
||||
def format_search_result(self, search_result):
|
||||
return search_result
|
||||
@ -81,18 +81,18 @@ class AbstractConnector(TestCase):
|
||||
)
|
||||
|
||||
def test_abstract_connector_init(self):
|
||||
""" barebones connector for search with defaults """
|
||||
"""barebones connector for search with defaults"""
|
||||
self.assertIsInstance(self.connector.book_mappings, list)
|
||||
|
||||
def test_is_available(self):
|
||||
""" this isn't used.... """
|
||||
"""this isn't used...."""
|
||||
self.assertTrue(self.connector.is_available())
|
||||
self.connector.max_query_count = 1
|
||||
self.connector.connector.query_count = 2
|
||||
self.assertFalse(self.connector.is_available())
|
||||
|
||||
def test_get_or_create_book_existing(self):
|
||||
""" find an existing book by remote/origin id """
|
||||
"""find an existing book by remote/origin id"""
|
||||
self.assertEqual(models.Book.objects.count(), 1)
|
||||
self.assertEqual(
|
||||
self.book.remote_id, "https://%s/book/%d" % (DOMAIN, self.book.id)
|
||||
@ -113,7 +113,7 @@ class AbstractConnector(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_get_or_create_book_deduped(self):
|
||||
""" load remote data and deduplicate """
|
||||
"""load remote data and deduplicate"""
|
||||
responses.add(
|
||||
responses.GET, "https://example.com/book/abcd", json=self.edition_data
|
||||
)
|
||||
@ -125,7 +125,7 @@ class AbstractConnector(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_get_or_create_author(self):
|
||||
""" load an author """
|
||||
"""load an author"""
|
||||
self.connector.author_mappings = [
|
||||
Mapping("id"),
|
||||
Mapping("name"),
|
||||
@ -142,7 +142,7 @@ class AbstractConnector(TestCase):
|
||||
self.assertEqual(result.origin_id, "https://www.example.com/author")
|
||||
|
||||
def test_get_or_create_author_existing(self):
|
||||
""" get an existing author """
|
||||
"""get an existing author"""
|
||||
author = models.Author.objects.create(name="Test Author")
|
||||
result = self.connector.get_or_create_author(author.remote_id)
|
||||
self.assertEqual(author, result)
|
||||
|
@ -8,10 +8,10 @@ from bookwyrm.connectors.abstract_connector import Mapping, SearchResult
|
||||
|
||||
|
||||
class AbstractConnector(TestCase):
|
||||
""" generic code for connecting to outside data sources """
|
||||
"""generic code for connecting to outside data sources"""
|
||||
|
||||
def setUp(self):
|
||||
""" we need an example connector """
|
||||
"""we need an example connector"""
|
||||
self.connector_info = models.Connector.objects.create(
|
||||
identifier="example.com",
|
||||
connector_file="openlibrary",
|
||||
@ -23,7 +23,7 @@ class AbstractConnector(TestCase):
|
||||
)
|
||||
|
||||
class TestConnector(abstract_connector.AbstractMinimalConnector):
|
||||
""" nothing added here """
|
||||
"""nothing added here"""
|
||||
|
||||
def format_search_result(self, search_result):
|
||||
return search_result
|
||||
@ -43,7 +43,7 @@ class AbstractConnector(TestCase):
|
||||
self.test_connector = TestConnector("example.com")
|
||||
|
||||
def test_abstract_minimal_connector_init(self):
|
||||
""" barebones connector for search with defaults """
|
||||
"""barebones connector for search with defaults"""
|
||||
connector = self.test_connector
|
||||
self.assertEqual(connector.connector, self.connector_info)
|
||||
self.assertEqual(connector.base_url, "https://example.com")
|
||||
@ -58,7 +58,7 @@ class AbstractConnector(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_search(self):
|
||||
""" makes an http request to the outside service """
|
||||
"""makes an http request to the outside service"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://example.com/search?q=a%20book%20title",
|
||||
@ -73,7 +73,7 @@ class AbstractConnector(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_search_min_confidence(self):
|
||||
""" makes an http request to the outside service """
|
||||
"""makes an http request to the outside service"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://example.com/search?q=a%20book%20title&min_confidence=1",
|
||||
@ -85,7 +85,7 @@ class AbstractConnector(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_isbn_search(self):
|
||||
""" makes an http request to the outside service """
|
||||
"""makes an http request to the outside service"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://example.com/isbn?q=123456",
|
||||
@ -96,7 +96,7 @@ class AbstractConnector(TestCase):
|
||||
self.assertEqual(len(results), 10)
|
||||
|
||||
def test_search_result(self):
|
||||
""" a class that stores info about a search result """
|
||||
"""a class that stores info about a search result"""
|
||||
result = SearchResult(
|
||||
title="Title",
|
||||
key="https://example.com/book/1",
|
||||
@ -109,21 +109,21 @@ class AbstractConnector(TestCase):
|
||||
self.assertEqual(result.title, "Title")
|
||||
|
||||
def test_create_mapping(self):
|
||||
""" maps remote fields for book data to bookwyrm activitypub fields """
|
||||
"""maps remote fields for book data to bookwyrm activitypub fields"""
|
||||
mapping = Mapping("isbn")
|
||||
self.assertEqual(mapping.local_field, "isbn")
|
||||
self.assertEqual(mapping.remote_field, "isbn")
|
||||
self.assertEqual(mapping.formatter("bb"), "bb")
|
||||
|
||||
def test_create_mapping_with_remote(self):
|
||||
""" the remote field is different than the local field """
|
||||
"""the remote field is different than the local field"""
|
||||
mapping = Mapping("isbn", remote_field="isbn13")
|
||||
self.assertEqual(mapping.local_field, "isbn")
|
||||
self.assertEqual(mapping.remote_field, "isbn13")
|
||||
self.assertEqual(mapping.formatter("bb"), "bb")
|
||||
|
||||
def test_create_mapping_with_formatter(self):
|
||||
""" a function is provided to modify the data """
|
||||
"""a function is provided to modify the data"""
|
||||
formatter = lambda x: "aa" + x
|
||||
mapping = Mapping("isbn", formatter=formatter)
|
||||
self.assertEqual(mapping.local_field, "isbn")
|
||||
|
@ -9,10 +9,10 @@ from bookwyrm.connectors.abstract_connector import SearchResult
|
||||
|
||||
|
||||
class BookWyrmConnector(TestCase):
|
||||
""" this connector doesn't do much, just search """
|
||||
"""this connector doesn't do much, just search"""
|
||||
|
||||
def setUp(self):
|
||||
""" create the connector """
|
||||
"""create the connector"""
|
||||
models.Connector.objects.create(
|
||||
identifier="example.com",
|
||||
connector_file="bookwyrm_connector",
|
||||
@ -24,14 +24,14 @@ class BookWyrmConnector(TestCase):
|
||||
self.connector = Connector("example.com")
|
||||
|
||||
def test_get_or_create_book_existing(self):
|
||||
""" load book activity """
|
||||
"""load book activity"""
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
book = models.Edition.objects.create(title="Test Edition", parent_work=work)
|
||||
result = self.connector.get_or_create_book(book.remote_id)
|
||||
self.assertEqual(book, result)
|
||||
|
||||
def test_format_search_result(self):
|
||||
""" create a SearchResult object from search response 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)
|
||||
@ -46,7 +46,7 @@ class BookWyrmConnector(TestCase):
|
||||
self.assertEqual(result.connector, self.connector)
|
||||
|
||||
def test_format_isbn_search_result(self):
|
||||
""" just gotta attach the connector """
|
||||
"""just gotta attach the connector"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/bw_search.json")
|
||||
search_data = json.loads(datafile.read_bytes())
|
||||
results = self.connector.parse_isbn_search_data(search_data)
|
||||
|
@ -8,10 +8,10 @@ from bookwyrm.connectors.self_connector import Connector as SelfConnector
|
||||
|
||||
|
||||
class ConnectorManager(TestCase):
|
||||
""" interface between the app and various connectors """
|
||||
"""interface between the app and various connectors"""
|
||||
|
||||
def setUp(self):
|
||||
""" we'll need some books and a connector info entry """
|
||||
"""we'll need some books and a connector info entry"""
|
||||
self.work = models.Work.objects.create(title="Example Work")
|
||||
|
||||
self.edition = models.Edition.objects.create(
|
||||
@ -32,7 +32,7 @@ class ConnectorManager(TestCase):
|
||||
)
|
||||
|
||||
def test_get_or_create_connector(self):
|
||||
""" loads a connector if the data source is known or creates one """
|
||||
"""loads a connector if the data source is known or creates one"""
|
||||
remote_id = "https://example.com/object/1"
|
||||
connector = connector_manager.get_or_create_connector(remote_id)
|
||||
self.assertIsInstance(connector, BookWyrmConnector)
|
||||
@ -43,7 +43,7 @@ class ConnectorManager(TestCase):
|
||||
self.assertEqual(connector.identifier, same_connector.identifier)
|
||||
|
||||
def test_get_connectors(self):
|
||||
""" load all connectors """
|
||||
"""load all connectors"""
|
||||
remote_id = "https://example.com/object/1"
|
||||
connector_manager.get_or_create_connector(remote_id)
|
||||
connectors = list(connector_manager.get_connectors())
|
||||
@ -52,7 +52,7 @@ class ConnectorManager(TestCase):
|
||||
self.assertIsInstance(connectors[1], BookWyrmConnector)
|
||||
|
||||
def test_search(self):
|
||||
""" search all connectors """
|
||||
"""search all connectors"""
|
||||
results = connector_manager.search("Example")
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertIsInstance(results[0]["connector"], SelfConnector)
|
||||
@ -60,7 +60,7 @@ class ConnectorManager(TestCase):
|
||||
self.assertEqual(results[0]["results"][0].title, "Example Edition")
|
||||
|
||||
def test_search_isbn(self):
|
||||
""" special handling if a query resembles an isbn """
|
||||
"""special handling if a query resembles an isbn"""
|
||||
results = connector_manager.search("0000000000")
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertIsInstance(results[0]["connector"], SelfConnector)
|
||||
@ -68,20 +68,20 @@ class ConnectorManager(TestCase):
|
||||
self.assertEqual(results[0]["results"][0].title, "Example Edition")
|
||||
|
||||
def test_local_search(self):
|
||||
""" search only the local database """
|
||||
"""search only the local database"""
|
||||
results = connector_manager.local_search("Example")
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(results[0].title, "Example Edition")
|
||||
|
||||
def test_first_search_result(self):
|
||||
""" only get one search result """
|
||||
"""only get one search result"""
|
||||
result = connector_manager.first_search_result("Example")
|
||||
self.assertEqual(result.title, "Example Edition")
|
||||
no_result = connector_manager.first_search_result("dkjfhg")
|
||||
self.assertIsNone(no_result)
|
||||
|
||||
def test_load_connector(self):
|
||||
""" load a connector object from the database entry """
|
||||
"""load a connector object from the database entry"""
|
||||
connector = connector_manager.load_connector(self.connector)
|
||||
self.assertIsInstance(connector, SelfConnector)
|
||||
self.assertEqual(connector.identifier, "test_connector")
|
||||
|
@ -16,10 +16,10 @@ from bookwyrm.connectors.connector_manager import ConnectorException
|
||||
|
||||
|
||||
class Openlibrary(TestCase):
|
||||
""" test loading data from openlibrary.org """
|
||||
"""test loading data from openlibrary.org"""
|
||||
|
||||
def setUp(self):
|
||||
""" creates the connector we'll use """
|
||||
"""creates the connector we'll use"""
|
||||
models.Connector.objects.create(
|
||||
identifier="openlibrary.org",
|
||||
name="OpenLibrary",
|
||||
@ -42,7 +42,7 @@ class Openlibrary(TestCase):
|
||||
self.edition_list_data = json.loads(edition_list_file.read_bytes())
|
||||
|
||||
def test_get_remote_id_from_data(self):
|
||||
""" format the remote id from the data """
|
||||
"""format the remote id from the data"""
|
||||
data = {"key": "/work/OL1234W"}
|
||||
result = self.connector.get_remote_id_from_data(data)
|
||||
self.assertEqual(result, "https://openlibrary.org/work/OL1234W")
|
||||
@ -51,13 +51,13 @@ class Openlibrary(TestCase):
|
||||
self.connector.get_remote_id_from_data({})
|
||||
|
||||
def test_is_work_data(self):
|
||||
""" detect if the loaded json is a work """
|
||||
"""detect if the loaded json is a work"""
|
||||
self.assertEqual(self.connector.is_work_data(self.work_data), True)
|
||||
self.assertEqual(self.connector.is_work_data(self.edition_data), False)
|
||||
|
||||
@responses.activate
|
||||
def test_get_edition_from_work_data(self):
|
||||
""" loads a list of editions """
|
||||
"""loads a list of editions"""
|
||||
data = {"key": "/work/OL1234W"}
|
||||
responses.add(
|
||||
responses.GET,
|
||||
@ -74,7 +74,7 @@ class Openlibrary(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_get_work_from_edition_data(self):
|
||||
""" loads a list of editions """
|
||||
"""loads a list of editions"""
|
||||
data = {"works": [{"key": "/work/OL1234W"}]}
|
||||
responses.add(
|
||||
responses.GET,
|
||||
@ -87,7 +87,7 @@ class Openlibrary(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_get_authors_from_data(self):
|
||||
""" find authors in data """
|
||||
"""find authors in data"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://openlibrary.org/authors/OL382982A",
|
||||
@ -112,13 +112,13 @@ class Openlibrary(TestCase):
|
||||
self.assertEqual(result.openlibrary_key, "OL453734A")
|
||||
|
||||
def test_get_cover_url(self):
|
||||
""" formats a url that should contain the cover image """
|
||||
"""formats a url that should contain the cover image"""
|
||||
blob = ["image"]
|
||||
result = self.connector.get_cover_url(blob)
|
||||
self.assertEqual(result, "https://covers.openlibrary.org/b/id/image-L.jpg")
|
||||
|
||||
def test_parse_search_result(self):
|
||||
""" extract the results from the search json response """
|
||||
"""extract the results from the search json response"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_search.json")
|
||||
search_data = json.loads(datafile.read_bytes())
|
||||
result = self.connector.parse_search_data(search_data)
|
||||
@ -126,7 +126,7 @@ class Openlibrary(TestCase):
|
||||
self.assertEqual(len(result), 2)
|
||||
|
||||
def test_format_search_result(self):
|
||||
""" translate json from openlibrary into SearchResult """
|
||||
"""translate json from openlibrary into SearchResult"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_search.json")
|
||||
search_data = json.loads(datafile.read_bytes())
|
||||
results = self.connector.parse_search_data(search_data)
|
||||
@ -141,7 +141,7 @@ class Openlibrary(TestCase):
|
||||
self.assertEqual(result.connector, self.connector)
|
||||
|
||||
def test_parse_isbn_search_result(self):
|
||||
""" extract the results from the search json response """
|
||||
"""extract the results from the search json response"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_isbn_search.json")
|
||||
search_data = json.loads(datafile.read_bytes())
|
||||
result = self.connector.parse_isbn_search_data(search_data)
|
||||
@ -149,7 +149,7 @@ class Openlibrary(TestCase):
|
||||
self.assertEqual(len(result), 1)
|
||||
|
||||
def test_format_isbn_search_result(self):
|
||||
""" translate json from openlibrary into SearchResult """
|
||||
"""translate json from openlibrary into SearchResult"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_isbn_search.json")
|
||||
search_data = json.loads(datafile.read_bytes())
|
||||
results = self.connector.parse_isbn_search_data(search_data)
|
||||
@ -165,7 +165,7 @@ class Openlibrary(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_load_edition_data(self):
|
||||
""" format url from key and make request """
|
||||
"""format url from key and make request"""
|
||||
key = "OL1234W"
|
||||
responses.add(
|
||||
responses.GET,
|
||||
@ -177,7 +177,7 @@ class Openlibrary(TestCase):
|
||||
|
||||
@responses.activate
|
||||
def test_expand_book_data(self):
|
||||
""" given a book, get more editions """
|
||||
"""given a book, get more editions"""
|
||||
work = models.Work.objects.create(title="Test Work", openlibrary_key="OL1234W")
|
||||
edition = models.Edition.objects.create(title="Test Edition", parent_work=work)
|
||||
|
||||
@ -194,29 +194,29 @@ class Openlibrary(TestCase):
|
||||
self.connector.expand_book_data(work)
|
||||
|
||||
def test_get_description(self):
|
||||
""" should do some cleanup on the description data """
|
||||
"""should do some cleanup on the description data"""
|
||||
description = get_description(self.work_data["description"])
|
||||
expected = "First in the Old Kingdom/Abhorsen series."
|
||||
self.assertEqual(description, expected)
|
||||
|
||||
def test_get_openlibrary_key(self):
|
||||
""" extracts the uuid """
|
||||
"""extracts the uuid"""
|
||||
key = get_openlibrary_key("/books/OL27320736M")
|
||||
self.assertEqual(key, "OL27320736M")
|
||||
|
||||
def test_get_languages(self):
|
||||
""" looks up languages from a list """
|
||||
"""looks up languages from a list"""
|
||||
languages = get_languages(self.edition_data["languages"])
|
||||
self.assertEqual(languages, ["English"])
|
||||
|
||||
def test_pick_default_edition(self):
|
||||
""" detect if the loaded json is an edition """
|
||||
"""detect if the loaded json is an edition"""
|
||||
edition = pick_default_edition(self.edition_list_data["entries"])
|
||||
self.assertEqual(edition["key"], "/books/OL9788823M")
|
||||
|
||||
@responses.activate
|
||||
def test_create_edition_from_data(self):
|
||||
""" okay but can it actually create an edition with proper metadata """
|
||||
"""okay but can it actually create an edition with proper metadata"""
|
||||
work = models.Work.objects.create(title="Hello")
|
||||
responses.add(
|
||||
responses.GET,
|
||||
@ -240,7 +240,7 @@ class Openlibrary(TestCase):
|
||||
self.assertEqual(result.physical_format, "Hardcover")
|
||||
|
||||
def test_ignore_edition(self):
|
||||
""" skip editions with poor metadata """
|
||||
"""skip editions with poor metadata"""
|
||||
self.assertFalse(ignore_edition({"isbn_13": "hi"}))
|
||||
self.assertFalse(ignore_edition({"oclc_numbers": "hi"}))
|
||||
self.assertFalse(ignore_edition({"covers": "hi"}))
|
||||
|
@ -9,10 +9,10 @@ from bookwyrm.settings import DOMAIN
|
||||
|
||||
|
||||
class SelfConnector(TestCase):
|
||||
""" just uses local data """
|
||||
"""just uses local data"""
|
||||
|
||||
def setUp(self):
|
||||
""" creating the connector """
|
||||
"""creating the connector"""
|
||||
models.Connector.objects.create(
|
||||
identifier=DOMAIN,
|
||||
name="Local",
|
||||
@ -27,7 +27,7 @@ class SelfConnector(TestCase):
|
||||
self.connector = Connector(DOMAIN)
|
||||
|
||||
def test_format_search_result(self):
|
||||
""" create a SearchResult """
|
||||
"""create a SearchResult"""
|
||||
author = models.Author.objects.create(name="Anonymous")
|
||||
edition = models.Edition.objects.create(
|
||||
title="Edition of Example Work",
|
||||
@ -42,7 +42,7 @@ class SelfConnector(TestCase):
|
||||
self.assertEqual(result.connector, self.connector)
|
||||
|
||||
def test_search_rank(self):
|
||||
""" prioritize certain results """
|
||||
"""prioritize certain results"""
|
||||
author = models.Author.objects.create(name="Anonymous")
|
||||
edition = models.Edition.objects.create(
|
||||
title="Edition of Example Work",
|
||||
@ -78,7 +78,7 @@ class SelfConnector(TestCase):
|
||||
self.assertEqual(results[2].title, "Edition of Example Work")
|
||||
|
||||
def test_search_multiple_editions(self):
|
||||
""" it should get rid of duplicate editions for the same work """
|
||||
"""it should get rid of duplicate editions for the same work"""
|
||||
work = models.Work.objects.create(title="Work Title")
|
||||
edition_1 = models.Edition.objects.create(
|
||||
title="Edition 1 Title", parent_work=work
|
||||
|
Reference in New Issue
Block a user