Adds test for SearchResult dataclass

also just cleans up the styles in the test file for linting
This commit is contained in:
Mouse Reeve 2020-12-30 09:26:02 -08:00
parent d7db6d50ba
commit 6a8353de09

View file

@ -2,12 +2,14 @@
from django.test import TestCase
from bookwyrm import models
from bookwyrm.connectors.abstract_connector import Mapping
from bookwyrm.connectors.abstract_connector import Mapping, SearchResult
from bookwyrm.connectors.openlibrary import Connector
class AbstractConnector(TestCase):
''' generic code for connecting to outside data sources '''
def setUp(self):
''' we need an example connector '''
self.book = models.Edition.objects.create(title='Example Edition')
models.Connector.objects.create(
@ -38,6 +40,7 @@ class AbstractConnector(TestCase):
def test_create_mapping(self):
''' 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')
@ -45,6 +48,7 @@ class AbstractConnector(TestCase):
def test_create_mapping_with_remote(self):
''' 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')
@ -52,9 +56,24 @@ class AbstractConnector(TestCase):
def test_create_mapping_with_formatter(self):
''' a function is provided to modify the data '''
formatter = lambda x: 'aa' + x
mapping = Mapping('isbn', formatter=formatter)
self.assertEqual(mapping.local_field, 'isbn')
self.assertEqual(mapping.remote_field, 'isbn')
self.assertEqual(mapping.formatter, formatter)
self.assertEqual(mapping.formatter('bb'), 'aabb')
def test_search_result(self):
''' a class that stores info about a search result '''
result = SearchResult(
title='Title',
key='https://example.com/book/1',
author='Author Name',
year='1850',
connector=self.connector,
)
# there's really not much to test here, it's just a dataclass
self.assertEqual(result.confidence, 1)
self.assertEqual(result.title, 'Title')