mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-24 09:00:33 +00:00
Add test for normalizing isbns in book model
Turns out this was actually working as expected
This commit is contained in:
parent
285c513211
commit
f839038c8f
2 changed files with 12 additions and 3 deletions
|
@ -366,9 +366,9 @@ class Edition(Book):
|
|||
|
||||
# normalize isbn format
|
||||
if self.isbn_10:
|
||||
self.isbn_10 = re.sub(r"[^0-9X]", "", self.isbn_10)
|
||||
self.isbn_10 = normalize_isbn(self.isbn_10)
|
||||
if self.isbn_13:
|
||||
self.isbn_13 = re.sub(r"[^0-9X]", "", self.isbn_13)
|
||||
self.isbn_10 = normalize_isbn(self.isbn_13)
|
||||
|
||||
# set rank
|
||||
self.edition_rank = self.get_rank()
|
||||
|
@ -463,6 +463,11 @@ def isbn_13_to_10(isbn_13):
|
|||
return converted + str(checkdigit)
|
||||
|
||||
|
||||
def normalize_isbn(isbn):
|
||||
"""Remove unexpected characters from ISBN 10 or 13"""
|
||||
return re.sub(r"[^0-9X]", "", isbn)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@receiver(models.signals.post_save, sender=Edition)
|
||||
def preview_image(instance, *args, **kwargs):
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.test import TestCase
|
|||
from django.utils import timezone
|
||||
|
||||
from bookwyrm import models, settings
|
||||
from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10
|
||||
from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10, normalize_isbn
|
||||
from bookwyrm.settings import ENABLE_THUMBNAIL_GENERATION
|
||||
|
||||
|
||||
|
@ -72,6 +72,10 @@ class Book(TestCase):
|
|||
isbn_10 = isbn_13_to_10(isbn_13)
|
||||
self.assertEqual(isbn_10, "178816167X")
|
||||
|
||||
def test_normalize_isbn(self):
|
||||
"""Remove misc characters from ISBNs"""
|
||||
self.assertEqual(normalize_isbn("978-0-4633461-1-2"), "9780463346112")
|
||||
|
||||
def test_get_edition_info(self):
|
||||
"""text slug about an edition"""
|
||||
book = models.Edition.objects.create(title="Test Edition")
|
||||
|
|
Loading…
Reference in a new issue