mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 12:01:14 +00:00
Fixes field and lists tests
This commit is contained in:
parent
f917079c0b
commit
ffd0759f6f
5 changed files with 28 additions and 16 deletions
|
@ -38,4 +38,7 @@ def execute_after_save(sender, instance, created, *args, **kwargs):
|
|||
return
|
||||
if not instance.remote_id:
|
||||
instance.remote_id = instance.get_remote_id()
|
||||
instance.save(broadcast=False)
|
||||
try:
|
||||
instance.save(broadcast=False)
|
||||
except TypeError:
|
||||
instance.save()
|
||||
|
|
|
@ -54,5 +54,5 @@ class ProgressUpdate(BookWyrmModel):
|
|||
def save(self, *args, **kwargs):
|
||||
''' update user active time '''
|
||||
self.user.last_active_date = timezone.now()
|
||||
self.user.save()
|
||||
self.user.save(broadcast=False)
|
||||
super().save(*args, **kwargs)
|
||||
|
|
|
@ -178,7 +178,8 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(model_instance.privacy_field, 'unlisted')
|
||||
|
||||
|
||||
def test_privacy_field_set_activity_from_field(self):
|
||||
@patch('bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast')
|
||||
def test_privacy_field_set_activity_from_field(self, _):
|
||||
''' translate between to/cc fields and privacy '''
|
||||
user = User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
|
@ -195,13 +196,15 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(activity['to'], [public])
|
||||
self.assertEqual(activity['cc'], [followers])
|
||||
|
||||
model_instance = Status.objects.create(user=user, privacy='unlisted')
|
||||
model_instance = Status.objects.create(
|
||||
user=user, content='hi', privacy='unlisted')
|
||||
activity = {}
|
||||
instance.set_activity_from_field(activity, model_instance)
|
||||
self.assertEqual(activity['to'], [followers])
|
||||
self.assertEqual(activity['cc'], [public])
|
||||
|
||||
model_instance = Status.objects.create(user=user, privacy='followers')
|
||||
model_instance = Status.objects.create(
|
||||
user=user, content='hi', privacy='followers')
|
||||
activity = {}
|
||||
instance.set_activity_from_field(activity, model_instance)
|
||||
self.assertEqual(activity['to'], [followers])
|
||||
|
@ -209,6 +212,7 @@ class ActivitypubFields(TestCase):
|
|||
|
||||
model_instance = Status.objects.create(
|
||||
user=user,
|
||||
content='hi',
|
||||
privacy='direct',
|
||||
)
|
||||
model_instance.mention_users.set([user])
|
||||
|
@ -290,12 +294,13 @@ class ActivitypubFields(TestCase):
|
|||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
user.remote_id = 'https://example.com/user/mouse'
|
||||
user.save()
|
||||
user.save(broadcast=False)
|
||||
User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword',
|
||||
local=True, localname='rat')
|
||||
|
||||
value = instance.field_from_activity(userdata)
|
||||
with patch('bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast'):
|
||||
value = instance.field_from_activity(userdata)
|
||||
self.assertEqual(value, user)
|
||||
|
||||
|
||||
|
@ -394,7 +399,8 @@ class ActivitypubFields(TestCase):
|
|||
|
||||
|
||||
@responses.activate
|
||||
def test_image_field(self):
|
||||
@patch('bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast')
|
||||
def test_image_field(self, _):
|
||||
''' storing images '''
|
||||
user = User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
''' testing models '''
|
||||
from unittest.mock import patch
|
||||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models, settings
|
||||
|
||||
|
||||
@patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay')
|
||||
class List(TestCase):
|
||||
''' some activitypub oddness ahead '''
|
||||
def setUp(self):
|
||||
|
@ -11,17 +13,18 @@ class List(TestCase):
|
|||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.list = models.List.objects.create(
|
||||
name='Test List', user=self.user)
|
||||
with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
|
||||
self.list = models.List.objects.create(
|
||||
name='Test List', user=self.user)
|
||||
|
||||
def test_remote_id(self):
|
||||
def test_remote_id(self, _):
|
||||
''' shelves use custom remote ids '''
|
||||
expected_id = 'https://%s/list/%d' % \
|
||||
(settings.DOMAIN, self.list.id)
|
||||
self.assertEqual(self.list.get_remote_id(), expected_id)
|
||||
|
||||
|
||||
def test_to_activity(self):
|
||||
def test_to_activity(self, _):
|
||||
''' jsonify it '''
|
||||
activity_json = self.list.to_activity()
|
||||
self.assertIsInstance(activity_json, dict)
|
||||
|
@ -31,7 +34,7 @@ class List(TestCase):
|
|||
self.assertEqual(activity_json['name'], 'Test List')
|
||||
self.assertEqual(activity_json['owner'], self.user.remote_id)
|
||||
|
||||
def test_list_item(self):
|
||||
def test_list_item(self, _):
|
||||
''' a list entry '''
|
||||
work = models.Work.objects.create(title='hello')
|
||||
book = models.Edition.objects.create(title='hi', parent_work=work)
|
||||
|
@ -43,12 +46,12 @@ class List(TestCase):
|
|||
|
||||
self.assertTrue(item.approved)
|
||||
|
||||
add_activity = item.to_add_activity(self.user)
|
||||
add_activity = item.to_add_activity()
|
||||
self.assertEqual(add_activity['actor'], self.user.remote_id)
|
||||
self.assertEqual(add_activity['object']['id'], book.remote_id)
|
||||
self.assertEqual(add_activity['target'], self.list.remote_id)
|
||||
|
||||
remove_activity = item.to_remove_activity(self.user)
|
||||
remove_activity = item.to_remove_activity()
|
||||
self.assertEqual(remove_activity['actor'], self.user.remote_id)
|
||||
self.assertEqual(remove_activity['object']['id'], book.remote_id)
|
||||
self.assertEqual(remove_activity['target'], self.list.remote_id)
|
||||
|
|
|
@ -19,7 +19,7 @@ class Relationship(TestCase):
|
|||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse')
|
||||
self.local_user.remote_id = 'http://local.com/user/mouse'
|
||||
self.local_user.save()
|
||||
self.local_user.save(broadcast=False)
|
||||
|
||||
def test_user_follows(self):
|
||||
rel = models.UserFollows.objects.create(
|
||||
|
|
Loading…
Reference in a new issue