Unify concept of absolute_id and remote_id

This commit is contained in:
Mouse Reeve
2020-05-12 18:56:28 -07:00
parent 93493fc8e4
commit e76f96eb6c
33 changed files with 263 additions and 236 deletions

View File

@ -7,14 +7,18 @@ from fedireads import models, settings
class Book(TestCase):
''' not too much going on in the books model but here we are '''
def setUp(self):
work = models.Work.objects.create(title='Example Work')
models.Edition.objects.create(title='Example Edition', parent_work=work)
self.work = models.Work.objects.create(title='Example Work')
models.Edition.objects.create(title='Example Edition', parent_work=self.work)
def test_absolute_id(self):
''' editions and works use the same absolute id syntax '''
book = models.Edition.objects.first()
expected_id = 'https://%s/book/%d' % (settings.DOMAIN, book.id)
self.assertEqual(book.absolute_id, expected_id)
def test_remote_id(self):
''' editions and works use the same remote_id syntax '''
expected_id = 'https://%s/book/%d' % (settings.DOMAIN, self.work.id)
self.assertEqual(self.work.get_remote_id(), expected_id)
def test_local_id(self):
''' the local_id property for books '''
expected_id = 'https://%s/book/%d' % (settings.DOMAIN, self.work.id)
self.assertEqual(self.work.local_id, expected_id)
def test_create_book(self):
''' you shouldn't be able to create Books (only editions and works) '''
@ -37,8 +41,8 @@ class Shelf(TestCase):
models.Shelf.objects.create(
name='Test Shelf', identifier='test-shelf', user=user)
def test_absolute_id(self):
def test_remote_id(self):
''' editions and works use the same absolute id syntax '''
shelf = models.Shelf.objects.get(identifier='test-shelf')
expected_id = 'https://%s/user/mouse/shelf/test-shelf' % settings.DOMAIN
self.assertEqual(shelf.absolute_id, expected_id)
self.assertEqual(shelf.get_remote_id(), expected_id)