From e7f400533e46827ddfc53776a4e30ed26a60b232 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 12 Dec 2020 14:15:10 -0800 Subject: [PATCH] Fixes missing book and user objects --- .../tests/activitypub/test_base_activity.py | 7 +++---- bookwyrm/tests/models/test_base_model.py | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index 100ff6cf..88997c44 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -31,9 +31,6 @@ class BaseActivity(TestCase): # don't try to load the user 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( '../../static/images/default_avi.jpg') image = Image.open(image_file) @@ -146,6 +143,8 @@ class BaseActivity(TestCase): content='test status', 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.tag = [ { @@ -161,7 +160,7 @@ class BaseActivity(TestCase): ] update_data.to_model(models.Status, instance=status) 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 diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index 966fe3e2..65cf892e 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -170,12 +170,19 @@ class BaseModel(TestCase): ''' attempt to match a remote id to an object in the db ''' # uses a different remote id scheme # 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') - self.assertNotEqual(self.book.remote_id, 'http://book.com/book') + book = models.Edition.objects.create( + 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 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') result = models.User.find_existing_by_remote_id('hi') @@ -183,12 +190,12 @@ class BaseModel(TestCase): result = models.User.find_existing_by_remote_id( 'http://example.com/a/b') - self.assertEqual(result, self.user) + self.assertEqual(result, user) # test using origin id result = models.Edition.find_existing_by_remote_id( 'http://book.com/book') - self.assertEqual(result, self.book) + self.assertEqual(result, book) # test subclass match result = models.Status.find_existing_by_remote_id(