forked from mirrors/bookwyrm
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
|
return
|
||||||
if not instance.remote_id:
|
if not instance.remote_id:
|
||||||
instance.remote_id = instance.get_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):
|
def save(self, *args, **kwargs):
|
||||||
''' update user active time '''
|
''' update user active time '''
|
||||||
self.user.last_active_date = timezone.now()
|
self.user.last_active_date = timezone.now()
|
||||||
self.user.save()
|
self.user.save(broadcast=False)
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
|
@ -178,7 +178,8 @@ class ActivitypubFields(TestCase):
|
||||||
self.assertEqual(model_instance.privacy_field, 'unlisted')
|
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 '''
|
''' translate between to/cc fields and privacy '''
|
||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
'rat', 'rat@rat.rat', 'ratword',
|
'rat', 'rat@rat.rat', 'ratword',
|
||||||
|
@ -195,13 +196,15 @@ class ActivitypubFields(TestCase):
|
||||||
self.assertEqual(activity['to'], [public])
|
self.assertEqual(activity['to'], [public])
|
||||||
self.assertEqual(activity['cc'], [followers])
|
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 = {}
|
activity = {}
|
||||||
instance.set_activity_from_field(activity, model_instance)
|
instance.set_activity_from_field(activity, model_instance)
|
||||||
self.assertEqual(activity['to'], [followers])
|
self.assertEqual(activity['to'], [followers])
|
||||||
self.assertEqual(activity['cc'], [public])
|
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 = {}
|
activity = {}
|
||||||
instance.set_activity_from_field(activity, model_instance)
|
instance.set_activity_from_field(activity, model_instance)
|
||||||
self.assertEqual(activity['to'], [followers])
|
self.assertEqual(activity['to'], [followers])
|
||||||
|
@ -209,6 +212,7 @@ class ActivitypubFields(TestCase):
|
||||||
|
|
||||||
model_instance = Status.objects.create(
|
model_instance = Status.objects.create(
|
||||||
user=user,
|
user=user,
|
||||||
|
content='hi',
|
||||||
privacy='direct',
|
privacy='direct',
|
||||||
)
|
)
|
||||||
model_instance.mention_users.set([user])
|
model_instance.mention_users.set([user])
|
||||||
|
@ -290,12 +294,13 @@ class ActivitypubFields(TestCase):
|
||||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||||
local=True, localname='mouse')
|
local=True, localname='mouse')
|
||||||
user.remote_id = 'https://example.com/user/mouse'
|
user.remote_id = 'https://example.com/user/mouse'
|
||||||
user.save()
|
user.save(broadcast=False)
|
||||||
User.objects.create_user(
|
User.objects.create_user(
|
||||||
'rat', 'rat@rat.rat', 'ratword',
|
'rat', 'rat@rat.rat', 'ratword',
|
||||||
local=True, localname='rat')
|
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)
|
self.assertEqual(value, user)
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,7 +399,8 @@ class ActivitypubFields(TestCase):
|
||||||
|
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_image_field(self):
|
@patch('bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast')
|
||||||
|
def test_image_field(self, _):
|
||||||
''' storing images '''
|
''' storing images '''
|
||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
''' testing models '''
|
''' testing models '''
|
||||||
|
from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from bookwyrm import models, settings
|
from bookwyrm import models, settings
|
||||||
|
|
||||||
|
|
||||||
|
@patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay')
|
||||||
class List(TestCase):
|
class List(TestCase):
|
||||||
''' some activitypub oddness ahead '''
|
''' some activitypub oddness ahead '''
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -11,17 +13,18 @@ class List(TestCase):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||||
local=True, localname='mouse')
|
local=True, localname='mouse')
|
||||||
self.list = models.List.objects.create(
|
with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
|
||||||
name='Test List', user=self.user)
|
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 '''
|
''' shelves use custom remote ids '''
|
||||||
expected_id = 'https://%s/list/%d' % \
|
expected_id = 'https://%s/list/%d' % \
|
||||||
(settings.DOMAIN, self.list.id)
|
(settings.DOMAIN, self.list.id)
|
||||||
self.assertEqual(self.list.get_remote_id(), expected_id)
|
self.assertEqual(self.list.get_remote_id(), expected_id)
|
||||||
|
|
||||||
|
|
||||||
def test_to_activity(self):
|
def test_to_activity(self, _):
|
||||||
''' jsonify it '''
|
''' jsonify it '''
|
||||||
activity_json = self.list.to_activity()
|
activity_json = self.list.to_activity()
|
||||||
self.assertIsInstance(activity_json, dict)
|
self.assertIsInstance(activity_json, dict)
|
||||||
|
@ -31,7 +34,7 @@ class List(TestCase):
|
||||||
self.assertEqual(activity_json['name'], 'Test List')
|
self.assertEqual(activity_json['name'], 'Test List')
|
||||||
self.assertEqual(activity_json['owner'], self.user.remote_id)
|
self.assertEqual(activity_json['owner'], self.user.remote_id)
|
||||||
|
|
||||||
def test_list_item(self):
|
def test_list_item(self, _):
|
||||||
''' a list entry '''
|
''' a list entry '''
|
||||||
work = models.Work.objects.create(title='hello')
|
work = models.Work.objects.create(title='hello')
|
||||||
book = models.Edition.objects.create(title='hi', parent_work=work)
|
book = models.Edition.objects.create(title='hi', parent_work=work)
|
||||||
|
@ -43,12 +46,12 @@ class List(TestCase):
|
||||||
|
|
||||||
self.assertTrue(item.approved)
|
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['actor'], self.user.remote_id)
|
||||||
self.assertEqual(add_activity['object']['id'], book.remote_id)
|
self.assertEqual(add_activity['object']['id'], book.remote_id)
|
||||||
self.assertEqual(add_activity['target'], self.list.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['actor'], self.user.remote_id)
|
||||||
self.assertEqual(remove_activity['object']['id'], book.remote_id)
|
self.assertEqual(remove_activity['object']['id'], book.remote_id)
|
||||||
self.assertEqual(remove_activity['target'], self.list.remote_id)
|
self.assertEqual(remove_activity['target'], self.list.remote_id)
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Relationship(TestCase):
|
||||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||||
local=True, localname='mouse')
|
local=True, localname='mouse')
|
||||||
self.local_user.remote_id = 'http://local.com/user/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):
|
def test_user_follows(self):
|
||||||
rel = models.UserFollows.objects.create(
|
rel = models.UserFollows.objects.create(
|
||||||
|
|
Loading…
Reference in a new issue