Adds test for generated links in book model

This commit is contained in:
Mouse Reeve 2021-12-10 13:15:46 -08:00
parent a3d5acc70c
commit d28b22a361

View file

@ -1,5 +1,7 @@
""" testing models """ """ testing models """
from dateutil.parser import parse from dateutil.parser import parse
from imagekit.models import ImageSpecField
from django.test import TestCase from django.test import TestCase
from django.utils import timezone from django.utils import timezone
@ -26,11 +28,23 @@ class Book(TestCase):
def test_remote_id(self): def test_remote_id(self):
"""fanciness with remote/origin ids""" """fanciness with remote/origin ids"""
remote_id = "https://%s/book/%d" % (settings.DOMAIN, self.work.id) remote_id = f"https://{settings.DOMAIN}/book/{self.work.id}"
self.assertEqual(self.work.get_remote_id(), remote_id) self.assertEqual(self.work.get_remote_id(), remote_id)
self.assertEqual(self.work.remote_id, remote_id) self.assertEqual(self.work.remote_id, remote_id)
def test_create_book(self): def test_generated_links(self):
"""links produced from identifiers"""
book = models.Edition.objects.create(
title="ExEd",
parent_work=self.work,
openlibrary_key="OL123M",
inventaire_id="isbn:123",
)
self.assertEqual(book.openlibrary_link, "https://openlibrary.org/books/OL213M")
self.assertEqual(book.inventaire_link, "https://inventaire.io/entity/isbn:123")
self.assertIsInstance(book.cover_bw_book_xsmall_webp, ImageSpecField)
def test_create_book_invalid(self):
"""you shouldn't be able to create Books (only editions and works)""" """you shouldn't be able to create Books (only editions and works)"""
self.assertRaises(ValueError, models.Book.objects.create, title="Invalid Book") self.assertRaises(ValueError, models.Book.objects.create, title="Invalid Book")