Fixes missing book and user objects

This commit is contained in:
Mouse Reeve 2020-12-12 14:15:10 -08:00
parent 4ed713662e
commit e7f400533e
2 changed files with 15 additions and 9 deletions

View file

@ -31,9 +31,6 @@ class BaseActivity(TestCase):
# don't try to load the user icon # don't try to load the user icon
del self.userdata['icon'] del self.userdata['icon']
self.book = models.Edition.objects.create(
title='Test Edition', remote_id='http://book.com/book')
image_file = pathlib.Path(__file__).parent.joinpath( image_file = pathlib.Path(__file__).parent.joinpath(
'../../static/images/default_avi.jpg') '../../static/images/default_avi.jpg')
image = Image.open(image_file) image = Image.open(image_file)
@ -146,6 +143,8 @@ class BaseActivity(TestCase):
content='test status', content='test status',
user=self.user, user=self.user,
) )
book = models.Edition.objects.create(
title='Test Edition', remote_id='http://book.com/book')
update_data = activitypub.Note(**status.to_activity()) update_data = activitypub.Note(**status.to_activity())
update_data.tag = [ update_data.tag = [
{ {
@ -161,7 +160,7 @@ class BaseActivity(TestCase):
] ]
update_data.to_model(models.Status, instance=status) update_data.to_model(models.Status, instance=status)
self.assertEqual(status.mention_users.first(), self.user) self.assertEqual(status.mention_users.first(), self.user)
self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.mention_books.first(), book)
@responses.activate @responses.activate

View file

@ -170,12 +170,19 @@ class BaseModel(TestCase):
''' attempt to match a remote id to an object in the db ''' ''' attempt to match a remote id to an object in the db '''
# uses a different remote id scheme # uses a different remote id scheme
# this isn't really part of this test directly but it's helpful to state # this isn't really part of this test directly but it's helpful to state
self.assertEqual(self.book.origin_id, 'http://book.com/book') book = models.Edition.objects.create(
self.assertNotEqual(self.book.remote_id, 'http://book.com/book') title='Test Edition', remote_id='http://book.com/book')
user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
user.remote_id = 'http://example.com/a/b'
user.save()
self.assertEqual(book.origin_id, 'http://book.com/book')
self.assertNotEqual(book.remote_id, 'http://book.com/book')
# uses subclasses # uses subclasses
models.Comment.objects.create( models.Comment.objects.create(
user=self.user, content='test status', book=self.book, \ user=user, content='test status', book=book, \
remote_id='https://comment.net') remote_id='https://comment.net')
result = models.User.find_existing_by_remote_id('hi') result = models.User.find_existing_by_remote_id('hi')
@ -183,12 +190,12 @@ class BaseModel(TestCase):
result = models.User.find_existing_by_remote_id( result = models.User.find_existing_by_remote_id(
'http://example.com/a/b') 'http://example.com/a/b')
self.assertEqual(result, self.user) self.assertEqual(result, user)
# test using origin id # test using origin id
result = models.Edition.find_existing_by_remote_id( result = models.Edition.find_existing_by_remote_id(
'http://book.com/book') 'http://book.com/book')
self.assertEqual(result, self.book) self.assertEqual(result, book)
# test subclass match # test subclass match
result = models.Status.find_existing_by_remote_id( result = models.Status.find_existing_by_remote_id(