Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2021-01-30 17:53:23 -08:00
commit 7e7f80d31e
18 changed files with 101 additions and 44 deletions

View file

@ -27,9 +27,9 @@ class Connector(AbstractConnector):
Mapping('series', formatter=get_first),
Mapping('seriesNumber', remote_field='series_number'),
Mapping('subjects'),
Mapping('subjectPlaces'),
Mapping('isbn13', formatter=get_first),
Mapping('isbn10', formatter=get_first),
Mapping('subjectPlaces', remote_field='subject_places'),
Mapping('isbn13', remote_field='isbn_13', formatter=get_first),
Mapping('isbn10', remote_field='isbn_10', formatter=get_first),
Mapping('lccn', formatter=get_first),
Mapping(
'oclcNumber', remote_field='oclc_numbers',
@ -144,9 +144,34 @@ class Connector(AbstractConnector):
# we can mass download edition data from OL to avoid repeatedly querying
edition_options = self.load_edition_data(work.openlibrary_key)
for edition_data in edition_options.get('entries'):
# does this edition have ANY interesting data?
if ignore_edition(edition_data):
continue
self.create_edition_from_data(work, edition_data)
def ignore_edition(edition_data):
''' don't load a million editions that have no metadata '''
# an isbn, we love to see it
if edition_data.get('isbn_13') or edition_data.get('isbn_10'):
print(edition_data.get('isbn_10'))
return False
# grudgingly, oclc can stay
if edition_data.get('oclc_numbers'):
print(edition_data.get('oclc_numbers'))
return False
# if it has a cover it can stay
if edition_data.get('covers'):
print(edition_data.get('covers'))
return False
# keep non-english editions
if edition_data.get('languages') and \
'languages/eng' not in str(edition_data.get('languages')):
print(edition_data.get('languages'))
return False
return True
def get_description(description_blob):
''' descriptions can be a string or a dict '''
if isinstance(description_blob, dict):

View file

@ -190,3 +190,19 @@ class Openlibrary(TestCase):
''' detect if the loaded json is an edition '''
edition = pick_default_edition(self.edition_list_data['entries'])
self.assertEqual(edition['key'], '/books/OL9788823M')
def test_create_edition_from_data(self):
''' okay but can it actually create an edition with proper metadata '''
work = models.Work.objects.create(title='Hello')
result = self.connector.create_edition_from_data(
work, self.edition_data)
self.assertEqual(result.parent_work, work)
self.assertEqual(result.title, 'Sabriel')
self.assertEqual(result.isbn_10, '0060273224')
self.assertIsNotNone(result.description)
self.assertEqual(result.languages[0], 'English')
self.assertEqual(result.publishers[0], 'Harper Trophy')
self.assertEqual(result.pages, 491)
self.assertEqual(result.subjects[0], 'Fantasy.')
self.assertEqual(result.physical_format, 'Hardcover')

View file

@ -9,6 +9,7 @@
"518848"
]
},
"physical_format": "Hardcover",
"lc_classifications": [
"PZ7.N647 Sab 1995"
],

View file

@ -33,7 +33,7 @@ class AuthenticationViews(TestCase):
result = login(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'login.html')
result.render()
self.assertEqual(result.status_code, 200)
request.user = self.local_user
@ -94,7 +94,7 @@ class AuthenticationViews(TestCase):
})
response = view(request)
self.assertEqual(models.User.objects.count(), 1)
self.assertEqual(response.template_name, 'login.html')
response.render()
def test_register_invalid_username(self):
''' gotta have an email '''
@ -109,7 +109,7 @@ class AuthenticationViews(TestCase):
})
response = view(request)
self.assertEqual(models.User.objects.count(), 1)
self.assertEqual(response.template_name, 'login.html')
response.render()
request = self.factory.post(
'register/',
@ -120,7 +120,7 @@ class AuthenticationViews(TestCase):
})
response = view(request)
self.assertEqual(models.User.objects.count(), 1)
self.assertEqual(response.template_name, 'login.html')
response.render()
request = self.factory.post(
'register/',
@ -131,7 +131,7 @@ class AuthenticationViews(TestCase):
})
response = view(request)
self.assertEqual(models.User.objects.count(), 1)
self.assertEqual(response.template_name, 'login.html')
response.render()
def test_register_closed_instance(self):

View file

@ -34,6 +34,7 @@ class AuthorViews(TestCase):
remote_id='https://example.com/book/1',
parent_work=self.work
)
models.SiteSettings.objects.create()
def test_author_page(self):
@ -45,7 +46,8 @@ class AuthorViews(TestCase):
is_api.return_value = False
result = view(request, author.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'author.html')
result.render()
self.assertEqual(result.status_code, 200)
self.assertEqual(result.status_code, 200)
request = self.factory.get('')
@ -66,7 +68,8 @@ class AuthorViews(TestCase):
result = view(request, author.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'edit_author.html')
result.render()
self.assertEqual(result.status_code, 200)
self.assertEqual(result.status_code, 200)
@ -116,4 +119,5 @@ class AuthorViews(TestCase):
resp = view(request, author.id)
author.refresh_from_db()
self.assertEqual(author.name, 'Test Author')
self.assertEqual(resp.template_name, 'edit_author.html')
resp.render()
self.assertEqual(resp.status_code, 200)

View file

@ -23,6 +23,7 @@ class BlockViews(TestCase):
inbox='https://example.com/users/rat/inbox',
outbox='https://example.com/users/rat/outbox',
)
models.SiteSettings.objects.create()
def test_block_get(self):
@ -32,7 +33,7 @@ class BlockViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'preferences/blocks.html')
result.render()
self.assertEqual(result.status_code, 200)
def test_block_post(self):

View file

@ -33,6 +33,7 @@ class BookViews(TestCase):
remote_id='https://example.com/book/1',
parent_work=self.work
)
models.SiteSettings.objects.create()
def test_book_page(self):
@ -44,7 +45,7 @@ class BookViews(TestCase):
is_api.return_value = False
result = view(request, self.book.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'book.html')
result.render()
self.assertEqual(result.status_code, 200)
request = self.factory.get('')
@ -63,7 +64,7 @@ class BookViews(TestCase):
request.user.is_superuser = True
result = view(request, self.book.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'edit_book.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -116,7 +117,7 @@ class BookViews(TestCase):
is_api.return_value = False
result = view(request, self.work.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'editions.html')
result.render()
self.assertEqual(result.status_code, 200)
request = self.factory.get('')

View file

@ -15,6 +15,7 @@ class FederationViews(TestCase):
self.local_user = models.User.objects.create_user(
'mouse@local.com', 'mouse@mouse.mouse', 'password',
local=True, localname='mouse')
models.SiteSettings.objects.create()
def test_federation_page(self):
@ -25,5 +26,5 @@ class FederationViews(TestCase):
request.user.is_superuser = True
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'settings/federation.html')
result.render()
self.assertEqual(result.status_code, 200)

View file

@ -21,6 +21,7 @@ class FeedMessageViews(TestCase):
title='Example Edition',
remote_id='https://example.com/book/1',
)
models.SiteSettings.objects.create()
def test_feed(self):
@ -30,7 +31,7 @@ class FeedMessageViews(TestCase):
request.user = self.local_user
result = view(request, 'local')
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'feed/feed.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -45,7 +46,7 @@ class FeedMessageViews(TestCase):
is_api.return_value = False
result = view(request, 'mouse', status.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'feed/status.html')
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.feed.is_api_request') as is_api:
@ -66,7 +67,7 @@ class FeedMessageViews(TestCase):
is_api.return_value = False
result = view(request, 'mouse', status.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'feed/status.html')
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.feed.is_api_request') as is_api:
@ -83,7 +84,7 @@ class FeedMessageViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'feed/direct_messages.html')
result.render()
self.assertEqual(result.status_code, 200)

View file

@ -16,6 +16,7 @@ class ImportViews(TestCase):
self.local_user = models.User.objects.create_user(
'mouse@local.com', 'mouse@mouse.mouse', 'password',
local=True, localname='mouse')
models.SiteSettings.objects.create()
def test_import_page(self):
@ -25,7 +26,7 @@ class ImportViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'import.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -39,5 +40,5 @@ class ImportViews(TestCase):
async_result.return_value = []
result = view(request, import_job.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'import_status.html')
result.render()
self.assertEqual(result.status_code, 200)

View file

@ -18,6 +18,7 @@ class InviteViews(TestCase):
self.local_user = models.User.objects.create_user(
'mouse@local.com', 'mouse@mouse.mouse', 'password',
local=True, localname='mouse')
models.SiteSettings.objects.create()
def test_invite_page(self):
@ -32,7 +33,7 @@ class InviteViews(TestCase):
invite.return_value = True
result = view(request, 'hi')
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'invite.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -44,5 +45,5 @@ class InviteViews(TestCase):
request.user.is_superuser = True
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'settings/manage_invites.html')
result.render()
self.assertEqual(result.status_code, 200)

View file

@ -18,6 +18,7 @@ class LandingViews(TestCase):
local=True, localname='mouse')
self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False
models.SiteSettings.objects.create()
def test_home_page(self):
@ -27,13 +28,13 @@ class LandingViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertEqual(result.status_code, 200)
self.assertEqual(result.template_name, 'feed/feed.html')
result.render()
request.user = self.anonymous_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.status_code, 200)
self.assertEqual(result.template_name, 'discover.html')
result.render()
def test_about_page(self):
@ -43,7 +44,7 @@ class LandingViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'about.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -53,5 +54,3 @@ class LandingViews(TestCase):
request = self.factory.get('')
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'discover.html')
self.assertEqual(result.status_code, 200)

View file

@ -15,6 +15,7 @@ class NotificationViews(TestCase):
self.local_user = models.User.objects.create_user(
'mouse@local.com', 'mouse@mouse.mouse', 'password',
local=True, localname='mouse')
models.SiteSettings.objects.create()
def test_notifications_page(self):
''' there are so many views, this just makes sure it LOADS '''
@ -23,7 +24,7 @@ class NotificationViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'notifications.html')
result.render()
self.assertEqual(result.status_code, 200)
def test_clear_notifications(self):

View file

@ -19,6 +19,7 @@ class PasswordViews(TestCase):
local=True, localname='mouse')
self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False
models.SiteSettings.objects.create(id=1)
def test_password_reset_request(self):
@ -29,7 +30,7 @@ class PasswordViews(TestCase):
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'password_reset_request.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -43,7 +44,7 @@ class PasswordViews(TestCase):
request = self.factory.post('', {'email': 'mouse@mouse.com'})
with patch('bookwyrm.emailing.send_email.delay'):
resp = view(request)
self.assertEqual(resp.template_name, 'password_reset_request.html')
resp.render()
self.assertEqual(
models.PasswordReset.objects.get().user, self.local_user)
@ -56,7 +57,7 @@ class PasswordViews(TestCase):
request.user = self.anonymous_user
result = view(request, code.code)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'password_reset.html')
result.render()
self.assertEqual(result.status_code, 200)
@ -82,7 +83,7 @@ class PasswordViews(TestCase):
'confirm-password': 'hi'
})
resp = view(request, 'jhgdkfjgdf')
self.assertEqual(resp.template_name, 'password_reset.html')
resp.render()
self.assertTrue(models.PasswordReset.objects.exists())
def test_password_reset_mismatch(self):
@ -94,7 +95,7 @@ class PasswordViews(TestCase):
'confirm-password': 'hihi'
})
resp = view(request, code.code)
self.assertEqual(resp.template_name, 'password_reset.html')
resp.render()
self.assertTrue(models.PasswordReset.objects.exists())
@ -106,7 +107,7 @@ class PasswordViews(TestCase):
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'preferences/change_password.html')
result.render()
self.assertEqual(result.status_code, 200)

View file

@ -33,6 +33,7 @@ class ShelfViews(TestCase):
connector_file='self_connector',
local=True
)
models.SiteSettings.objects.create()
def test_search_json_response(self):
@ -89,7 +90,7 @@ class ShelfViews(TestCase):
manager.return_value = [search_result]
response = view(request)
self.assertIsInstance(response, TemplateResponse)
self.assertEqual(response.template_name, 'search_results.html')
response.render()
self.assertEqual(
response.context_data['book_results'][0].title, 'Gideon the Ninth')
@ -103,6 +104,6 @@ class ShelfViews(TestCase):
with patch('bookwyrm.connectors.connector_manager.search'):
response = view(request)
self.assertIsInstance(response, TemplateResponse)
self.assertEqual(response.template_name, 'search_results.html')
response.render()
self.assertEqual(
response.context_data['user_results'][0], self.local_user)

View file

@ -29,6 +29,7 @@ class ShelfViews(TestCase):
identifier='test-shelf',
user=self.local_user
)
models.SiteSettings.objects.create()
def test_shelf_page(self):
@ -41,7 +42,7 @@ class ShelfViews(TestCase):
is_api.return_value = False
result = view(request, self.local_user.username, shelf.identifier)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'user/shelf.html')
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.shelf.is_api_request') as is_api:

View file

@ -33,6 +33,7 @@ class TagViews(TestCase):
remote_id='https://example.com/book/1',
parent_work=self.work
)
models.SiteSettings.objects.create()
def test_tag_page(self):
@ -46,7 +47,7 @@ class TagViews(TestCase):
is_api.return_value = False
result = view(request, tag.identifier)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'tag.html')
result.render()
self.assertEqual(result.status_code, 200)
request = self.factory.get('')

View file

@ -23,6 +23,7 @@ class UserViews(TestCase):
self.rat = models.User.objects.create_user(
'rat@local.com', 'rat@rat.rat', 'password',
local=True, localname='rat')
models.SiteSettings.objects.create()
def test_user_page(self):
@ -34,7 +35,7 @@ class UserViews(TestCase):
is_api.return_value = False
result = view(request, 'mouse')
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'user/user.html')
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.user.is_api_request') as is_api:
@ -65,7 +66,7 @@ class UserViews(TestCase):
is_api.return_value = False
result = view(request, 'mouse')
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'user/followers.html')
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.user.is_api_request') as is_api:
@ -96,7 +97,7 @@ class UserViews(TestCase):
is_api.return_value = False
result = view(request, 'mouse')
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'user/following.html')
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.user.is_api_request') as is_api:
@ -125,7 +126,7 @@ class UserViews(TestCase):
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'preferences/edit_user.html')
result.render()
self.assertEqual(result.status_code, 200)