forked from mirrors/bookwyrm
Catches exception thrown when boosting unknown statuses
This commit is contained in:
parent
1fb728edbd
commit
b4c60c0591
2 changed files with 25 additions and 2 deletions
|
@ -3,7 +3,7 @@ from dataclasses import dataclass, fields, MISSING
|
|||
from json import JSONEncoder
|
||||
|
||||
from django.apps import apps
|
||||
from django.db import transaction
|
||||
from django.db import IntegrityError, transaction
|
||||
|
||||
from bookwyrm.connectors import ConnectorException, get_data
|
||||
from bookwyrm.tasks import app
|
||||
|
@ -92,7 +92,10 @@ class ActivityObject:
|
|||
|
||||
with transaction.atomic():
|
||||
# we can't set many to many and reverse fields on an unsaved object
|
||||
instance.save()
|
||||
try:
|
||||
instance.save()
|
||||
except IntegrityError as e:
|
||||
raise ActivitySerializerError(e)
|
||||
|
||||
# add many to many fields, which have to be set post-save
|
||||
for field in instance.many_to_many_fields:
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.http import HttpResponseBadRequest, HttpResponseNotAllowed, \
|
|||
HttpResponseNotFound
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
import responses
|
||||
|
||||
from bookwyrm import models, incoming
|
||||
|
||||
|
@ -421,6 +422,25 @@ class Incoming(TestCase):
|
|||
self.assertEqual(notification.related_status, self.status)
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_handle_discarded_boost(self):
|
||||
''' test a boost of a mastodon status that will be discarded '''
|
||||
activity = {
|
||||
'type': 'Announce',
|
||||
'id': 'http://www.faraway.com/boost/12',
|
||||
'actor': self.remote_user.remote_id,
|
||||
'object': self.status.to_activity(),
|
||||
}
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'http://www.faraway.com/boost/12',
|
||||
json={'id': 'http://www.faraway.com/boost/12'},
|
||||
status=200)
|
||||
incoming.handle_boost(activity)
|
||||
self.assertEqual(models.Boost.objects.count(), 0)
|
||||
|
||||
|
||||
|
||||
def test_handle_unboost(self):
|
||||
''' undo a boost '''
|
||||
activity = {
|
||||
|
|
Loading…
Reference in a new issue