mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-10 17:25:35 +00:00
Removes outdated unit tests
This commit is contained in:
parent
87fe984462
commit
af19d728d2
8 changed files with 16 additions and 141 deletions
|
@ -17,4 +17,5 @@ class Connector(AbstractMinimalConnector):
|
|||
|
||||
def parse_isbn_search_data(self, data):
|
||||
for search_result in data:
|
||||
yield self.format_search_result(search_result)
|
||||
search_result["connector"] = self
|
||||
yield SearchResult(**search_result)
|
||||
|
|
|
@ -78,7 +78,7 @@ class Connector(AbstractConnector):
|
|||
}
|
||||
|
||||
def parse_search_data(self, data):
|
||||
for search_result in data.get("results"):
|
||||
for search_result in data.get("results", []):
|
||||
images = search_result.get("image")
|
||||
cover = f"{self.covers_url}/img/entities/{images[0]}" if images else None
|
||||
# a deeply messy translation of inventaire's scores
|
||||
|
@ -96,7 +96,9 @@ class Connector(AbstractConnector):
|
|||
|
||||
def parse_isbn_search_data(self, data):
|
||||
"""got some daaaata"""
|
||||
results = data.get("entities", [])
|
||||
results = data.get("entities")
|
||||
if not results:
|
||||
return
|
||||
for search_result in list(results.values()):
|
||||
title = search_result.get("claims", {}).get("wdt:P1476", [])
|
||||
if not title:
|
||||
|
|
|
@ -42,15 +42,9 @@ class AbstractConnector(TestCase):
|
|||
|
||||
generated_remote_link_field = "openlibrary_link"
|
||||
|
||||
def format_search_result(self, search_result):
|
||||
return search_result
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data
|
||||
|
||||
def format_isbn_search_result(self, search_result):
|
||||
return search_result
|
||||
|
||||
def parse_isbn_search_data(self, data):
|
||||
return data
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
""" testing book data connectors """
|
||||
from django.test import TestCase
|
||||
import responses
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.connectors import abstract_connector
|
||||
|
@ -25,18 +24,12 @@ class AbstractConnector(TestCase):
|
|||
class TestConnector(abstract_connector.AbstractMinimalConnector):
|
||||
"""nothing added here"""
|
||||
|
||||
def format_search_result(self, search_result):
|
||||
return search_result
|
||||
|
||||
def get_or_create_book(self, remote_id):
|
||||
pass
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data
|
||||
|
||||
def format_isbn_search_result(self, search_result):
|
||||
return search_result
|
||||
|
||||
def parse_isbn_search_data(self, data):
|
||||
return data
|
||||
|
||||
|
@ -54,45 +47,6 @@ class AbstractConnector(TestCase):
|
|||
self.assertIsNone(connector.name)
|
||||
self.assertEqual(connector.identifier, "example.com")
|
||||
|
||||
@responses.activate
|
||||
def test_search(self):
|
||||
"""makes an http request to the outside service"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://example.com/search?q=a%20book%20title",
|
||||
json=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"],
|
||||
status=200,
|
||||
)
|
||||
results = self.test_connector.search("a book title")
|
||||
self.assertEqual(len(results), 10)
|
||||
self.assertEqual(results[0], "a")
|
||||
self.assertEqual(results[1], "b")
|
||||
self.assertEqual(results[2], "c")
|
||||
|
||||
@responses.activate
|
||||
def test_search_min_confidence(self):
|
||||
"""makes an http request to the outside service"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://example.com/search?q=a%20book%20title&min_confidence=1",
|
||||
json=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"],
|
||||
status=200,
|
||||
)
|
||||
results = self.test_connector.search("a book title", min_confidence=1)
|
||||
self.assertEqual(len(results), 10)
|
||||
|
||||
@responses.activate
|
||||
def test_isbn_search(self):
|
||||
"""makes an http request to the outside service"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://example.com/isbn?q=123456",
|
||||
json=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"],
|
||||
status=200,
|
||||
)
|
||||
results = self.test_connector.isbn_search("123456")
|
||||
self.assertEqual(len(results), 10)
|
||||
|
||||
def test_create_mapping(self):
|
||||
"""maps remote fields for book data to bookwyrm activitypub fields"""
|
||||
mapping = Mapping("isbn")
|
||||
|
|
|
@ -30,14 +30,11 @@ class BookWyrmConnector(TestCase):
|
|||
result = self.connector.get_or_create_book(book.remote_id)
|
||||
self.assertEqual(book, result)
|
||||
|
||||
def test_format_search_result(self):
|
||||
def test_parse_search_data(self):
|
||||
"""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])
|
||||
result = list(self.connector.parse_search_data(search_data))[0]
|
||||
self.assertIsInstance(result, SearchResult)
|
||||
self.assertEqual(result.title, "Jonathan Strange and Mr Norrell")
|
||||
self.assertEqual(result.key, "https://example.com/book/122")
|
||||
|
@ -45,10 +42,9 @@ class BookWyrmConnector(TestCase):
|
|||
self.assertEqual(result.year, 2017)
|
||||
self.assertEqual(result.connector, self.connector)
|
||||
|
||||
def test_format_isbn_search_result(self):
|
||||
def test_parse_isbn_search_data(self):
|
||||
"""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)
|
||||
result = self.connector.format_isbn_search_result(results[0])
|
||||
result = list(self.connector.parse_isbn_search_data(search_data))[0]
|
||||
self.assertEqual(result.connector, self.connector)
|
||||
|
|
|
@ -49,39 +49,11 @@ class ConnectorManager(TestCase):
|
|||
self.assertEqual(len(connectors), 1)
|
||||
self.assertIsInstance(connectors[0], BookWyrmConnector)
|
||||
|
||||
@responses.activate
|
||||
def test_search_plaintext(self):
|
||||
"""search all connectors"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://fake.ciom/search/Example?min_confidence=0.1",
|
||||
json=[{"title": "Hello", "key": "https://www.example.com/search/1"}],
|
||||
)
|
||||
results = connector_manager.search("Example")
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(len(results[0]["results"]), 1)
|
||||
self.assertEqual(results[0]["connector"].identifier, "test_connector_remote")
|
||||
self.assertEqual(results[0]["results"][0].title, "Hello")
|
||||
|
||||
def test_search_empty_query(self):
|
||||
"""don't panic on empty queries"""
|
||||
results = connector_manager.search("")
|
||||
self.assertEqual(results, [])
|
||||
|
||||
@responses.activate
|
||||
def test_search_isbn(self):
|
||||
"""special handling if a query resembles an isbn"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://fake.ciom/isbn/0000000000",
|
||||
json=[{"title": "Hello", "key": "https://www.example.com/search/1"}],
|
||||
)
|
||||
results = connector_manager.search("0000000000")
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(len(results[0]["results"]), 1)
|
||||
self.assertEqual(results[0]["connector"].identifier, "test_connector_remote")
|
||||
self.assertEqual(results[0]["results"][0].title, "Hello")
|
||||
|
||||
def test_first_search_result(self):
|
||||
"""only get one search result"""
|
||||
result = connector_manager.first_search_result("Example")
|
||||
|
|
|
@ -66,38 +66,14 @@ class Inventaire(TestCase):
|
|||
with self.assertRaises(ConnectorException):
|
||||
self.connector.get_book_data("https://test.url/ok")
|
||||
|
||||
@responses.activate
|
||||
def test_search(self):
|
||||
"""min confidence filtering"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://inventaire.io/search?q=hi",
|
||||
json={
|
||||
"results": [
|
||||
{
|
||||
"_score": 200,
|
||||
"label": "hello",
|
||||
},
|
||||
{
|
||||
"_score": 100,
|
||||
"label": "hi",
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
results = self.connector.search("hi", min_confidence=0.5)
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(results[0].title, "hello")
|
||||
|
||||
def test_format_search_result(self):
|
||||
def test_parse_search_data(self):
|
||||
"""json to search result objs"""
|
||||
search_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/inventaire_search.json"
|
||||
)
|
||||
search_results = json.loads(search_file.read_bytes())
|
||||
|
||||
results = self.connector.parse_search_data(search_results)
|
||||
formatted = self.connector.format_search_result(results[0])
|
||||
formatted = list(self.connector.parse_search_data(search_results))[0]
|
||||
|
||||
self.assertEqual(formatted.title, "The Stories of Vladimir Nabokov")
|
||||
self.assertEqual(
|
||||
|
@ -178,15 +154,14 @@ class Inventaire(TestCase):
|
|||
result = self.connector.resolve_keys(keys)
|
||||
self.assertEqual(result, ["epistolary novel", "crime novel"])
|
||||
|
||||
def test_isbn_search(self):
|
||||
def test_pase_isbn_search_data(self):
|
||||
"""another search type"""
|
||||
search_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/inventaire_isbn_search.json"
|
||||
)
|
||||
search_results = json.loads(search_file.read_bytes())
|
||||
|
||||
results = self.connector.parse_isbn_search_data(search_results)
|
||||
formatted = self.connector.format_isbn_search_result(results[0])
|
||||
formatted = list(self.connector.parse_isbn_search_data(search_results))[0]
|
||||
|
||||
self.assertEqual(formatted.title, "L'homme aux cercles bleus")
|
||||
self.assertEqual(
|
||||
|
@ -198,25 +173,12 @@ class Inventaire(TestCase):
|
|||
"https://covers.inventaire.io/img/entities/12345",
|
||||
)
|
||||
|
||||
def test_isbn_search_empty(self):
|
||||
def test_parse_isbn_search_data_empty(self):
|
||||
"""another search type"""
|
||||
search_results = {}
|
||||
results = self.connector.parse_isbn_search_data(search_results)
|
||||
results = list(self.connector.parse_isbn_search_data(search_results))
|
||||
self.assertEqual(results, [])
|
||||
|
||||
def test_isbn_search_no_title(self):
|
||||
"""another search type"""
|
||||
search_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/inventaire_isbn_search.json"
|
||||
)
|
||||
search_results = json.loads(search_file.read_bytes())
|
||||
search_results["entities"]["isbn:9782290349229"]["claims"]["wdt:P1476"] = None
|
||||
|
||||
result = self.connector.format_isbn_search_result(
|
||||
search_results.get("entities")
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_is_work_data(self):
|
||||
"""is it a work"""
|
||||
work_file = pathlib.Path(__file__).parent.joinpath(
|
||||
|
|
|
@ -102,18 +102,12 @@ class BookSearch(TestCase):
|
|||
class TestConnector(AbstractMinimalConnector):
|
||||
"""nothing added here"""
|
||||
|
||||
def format_search_result(self, search_result):
|
||||
return search_result
|
||||
|
||||
def get_or_create_book(self, remote_id):
|
||||
pass
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data
|
||||
|
||||
def format_isbn_search_result(self, search_result):
|
||||
return search_result
|
||||
|
||||
def parse_isbn_search_data(self, data):
|
||||
return data
|
||||
|
||||
|
|
Loading…
Reference in a new issue