Unify concept of absolute_id and remote_id
This commit is contained in:
@ -7,25 +7,19 @@ from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
class BaseModel(TestCase):
|
||||
def test_absolute_id(self):
|
||||
def test_remote_id(self):
|
||||
instance = FedireadsModel()
|
||||
instance.id = 1
|
||||
expected = instance.absolute_id
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(expected, 'https://%s/fedireadsmodel/1' % DOMAIN)
|
||||
|
||||
def test_absolute_id_with_remote(self):
|
||||
instance = FedireadsModel()
|
||||
instance.remote_id = 'boop doop'
|
||||
expected = instance.absolute_id
|
||||
self.assertEqual(expected, 'boop doop')
|
||||
|
||||
def test_absolute_id_with_user(self):
|
||||
def test_remote_id_with_user(self):
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword')
|
||||
instance = FedireadsModel()
|
||||
instance.user = user
|
||||
instance.id = 1
|
||||
expected = instance.absolute_id
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(
|
||||
expected,
|
||||
'https://%s/user/mouse/fedireadsmodel/1' % DOMAIN)
|
||||
|
@ -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)
|
||||
|
@ -35,33 +35,3 @@ class Book(TestCase):
|
||||
|
||||
same_connector = books_manager.get_or_create_connector(remote_id)
|
||||
self.assertEqual(connector.identifier, same_connector.identifier)
|
||||
|
||||
|
||||
def test_get_by_absolute_id_local(self):
|
||||
abs_id = 'https://%s/book/%d' % (DOMAIN, self.work.id)
|
||||
work = books_manager.get_by_absolute_id(abs_id, models.Work)
|
||||
self.assertEqual(work, self.work)
|
||||
|
||||
work = books_manager.get_by_absolute_id(abs_id, models.Edition)
|
||||
self.assertIsNone(work)
|
||||
|
||||
|
||||
def test_get_by_absolute_id_remote(self):
|
||||
remote_work = models.Work.objects.create(
|
||||
title='Example Work',
|
||||
remote_id='https://example.com/book/123',
|
||||
)
|
||||
|
||||
abs_id = 'https://example.com/book/123'
|
||||
work = books_manager.get_by_absolute_id(abs_id, models.Work)
|
||||
self.assertEqual(work, remote_work)
|
||||
|
||||
|
||||
def test_get_by_absolute_id_invalid(self):
|
||||
abs_id = 'https://%s/book/34534623' % DOMAIN
|
||||
result = books_manager.get_by_absolute_id(abs_id, models.Work)
|
||||
self.assertIsNone(result)
|
||||
|
||||
abs_id = 'httook534623'
|
||||
result = books_manager.get_by_absolute_id(abs_id, models.Work)
|
||||
self.assertIsNone(result)
|
||||
|
@ -11,7 +11,7 @@ class Book(TestCase):
|
||||
|
||||
follower = models.User.objects.create_user(
|
||||
'rat', 'rat@mouse.mouse', 'ratword', local=False,
|
||||
actor='http://example.com/u/1',
|
||||
remote_id='http://example.com/u/1',
|
||||
outbox='http://example.com/u/1/o',
|
||||
shared_inbox='http://example.com/inbox',
|
||||
inbox='http://example.com/u/1/inbox')
|
||||
@ -20,14 +20,14 @@ class Book(TestCase):
|
||||
no_inbox_follower = models.User.objects.create_user(
|
||||
'hamster', 'hamster@mouse.mouse', 'hamword',
|
||||
shared_inbox=None, local=False,
|
||||
actor='http://example.com/u/2',
|
||||
remote_id='http://example.com/u/2',
|
||||
outbox='http://example.com/u/2/o',
|
||||
inbox='http://example.com/u/2/inbox')
|
||||
self.user.followers.add(no_inbox_follower)
|
||||
|
||||
non_fr_follower = models.User.objects.create_user(
|
||||
'gerbil', 'gerb@mouse.mouse', 'gerbword',
|
||||
actor='http://example.com/u/3',
|
||||
remote_id='http://example.com/u/3',
|
||||
outbox='http://example2.com/u/3/o',
|
||||
inbox='http://example2.com/u/3/inbox',
|
||||
shared_inbox='http://example2.com/inbox',
|
||||
@ -40,7 +40,7 @@ class Book(TestCase):
|
||||
|
||||
models.User.objects.create_user(
|
||||
'nutria', 'nutria@mouse.mouse', 'nuword',
|
||||
actor='http://example.com/u/4',
|
||||
remote_id='http://example.com/u/4',
|
||||
outbox='http://example.com/u/4/o',
|
||||
shared_inbox='http://example.com/inbox',
|
||||
inbox='http://example.com/u/4/inbox',
|
||||
|
@ -45,7 +45,7 @@ class Comment(TestCase):
|
||||
"items": []
|
||||
}
|
||||
},
|
||||
"inReplyToBook": self.book.absolute_id,
|
||||
"inReplyToBook": self.book.remote_id,
|
||||
"fedireadsType": "Comment"
|
||||
}
|
||||
comment = status_builder.create_comment_from_activity(
|
||||
|
@ -53,7 +53,7 @@ class Quotation(TestCase):
|
||||
'items': []
|
||||
}
|
||||
},
|
||||
'inReplyToBook': self.book.absolute_id,
|
||||
'inReplyToBook': self.book.remote_id,
|
||||
'fedireadsType': 'Quotation',
|
||||
'quote': 'quote body'
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class Review(TestCase):
|
||||
'items': []
|
||||
}
|
||||
},
|
||||
'inReplyToBook': self.book.absolute_id,
|
||||
'inReplyToBook': self.book.remote_id,
|
||||
'fedireadsType': 'Review',
|
||||
'name': 'review title',
|
||||
'rating': 3
|
||||
|
@ -22,6 +22,7 @@ class Status(TestCase):
|
||||
self.assertEqual(reply.content, content)
|
||||
self.assertEqual(reply.reply_parent, status)
|
||||
|
||||
|
||||
def test_create_status_from_activity(self):
|
||||
book = models.Edition.objects.create(title='Example Edition')
|
||||
review = status_builder.create_review(
|
||||
@ -29,7 +30,7 @@ class Status(TestCase):
|
||||
activity = {
|
||||
'id': 'https://example.com/user/mouse/status/12',
|
||||
'url': 'https://example.com/user/mouse/status/12',
|
||||
'inReplyTo': review.absolute_id,
|
||||
'inReplyTo': review.remote_id,
|
||||
'published': '2020-05-10T02:15:59.635557+00:00',
|
||||
'attributedTo': 'https://example.com/user/mouse',
|
||||
'to': [
|
||||
|
@ -23,7 +23,7 @@ class Status(TestCase):
|
||||
self.assertEqual(status.activity_type, 'Note')
|
||||
expected_id = 'https://%s/user/mouse/status/%d' % \
|
||||
(settings.DOMAIN, status.id)
|
||||
self.assertEqual(status.absolute_id, expected_id)
|
||||
self.assertEqual(status.remote_id, expected_id)
|
||||
|
||||
def test_comment(self):
|
||||
comment = models.Comment.objects.first()
|
||||
@ -31,7 +31,7 @@ class Status(TestCase):
|
||||
self.assertEqual(comment.activity_type, 'Note')
|
||||
expected_id = 'https://%s/user/mouse/comment/%d' % \
|
||||
(settings.DOMAIN, comment.id)
|
||||
self.assertEqual(comment.absolute_id, expected_id)
|
||||
self.assertEqual(comment.remote_id, expected_id)
|
||||
|
||||
def test_quotation(self):
|
||||
quotation = models.Quotation.objects.first()
|
||||
@ -39,7 +39,7 @@ class Status(TestCase):
|
||||
self.assertEqual(quotation.activity_type, 'Note')
|
||||
expected_id = 'https://%s/user/mouse/quotation/%d' % \
|
||||
(settings.DOMAIN, quotation.id)
|
||||
self.assertEqual(quotation.absolute_id, expected_id)
|
||||
self.assertEqual(quotation.remote_id, expected_id)
|
||||
|
||||
def test_review(self):
|
||||
review = models.Review.objects.first()
|
||||
@ -47,7 +47,7 @@ class Status(TestCase):
|
||||
self.assertEqual(review.activity_type, 'Article')
|
||||
expected_id = 'https://%s/user/mouse/review/%d' % \
|
||||
(settings.DOMAIN, review.id)
|
||||
self.assertEqual(review.absolute_id, expected_id)
|
||||
self.assertEqual(review.remote_id, expected_id)
|
||||
|
||||
|
||||
class Tag(TestCase):
|
||||
|
@ -14,10 +14,9 @@ class User(TestCase):
|
||||
''' username instead of id here '''
|
||||
user = models.User.objects.get(localname='mouse')
|
||||
expected_id = 'https://%s/user/mouse' % DOMAIN
|
||||
self.assertEqual(user.absolute_id, expected_id)
|
||||
self.assertEqual(user.remote_id, expected_id)
|
||||
self.assertEqual(user.username, 'mouse@%s' % DOMAIN)
|
||||
self.assertEqual(user.localname, 'mouse')
|
||||
self.assertEqual(user.actor, 'https://%s/user/mouse' % DOMAIN)
|
||||
self.assertEqual(user.shared_inbox, 'https://%s/inbox' % DOMAIN)
|
||||
self.assertEqual(user.inbox, '%s/inbox' % expected_id)
|
||||
self.assertEqual(user.outbox, '%s/outbox' % expected_id)
|
||||
|
Reference in New Issue
Block a user