forked from mirrors/bookwyrm
Throws validation error when remote_id is None
This commit is contained in:
parent
cc42e9d149
commit
ef2a07884f
2 changed files with 5 additions and 2 deletions
|
@ -18,7 +18,7 @@ from bookwyrm.connectors import get_image
|
||||||
|
|
||||||
def validate_remote_id(value):
|
def validate_remote_id(value):
|
||||||
''' make sure the remote_id looks like a url '''
|
''' make sure the remote_id looks like a url '''
|
||||||
if not re.match(r'^http.?:\/\/[^\s]+$', value):
|
if not value or not re.match(r'^http.?:\/\/[^\s]+$', value):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_('%(value)s is not a valid remote_id'),
|
_('%(value)s is not a valid remote_id'),
|
||||||
params={'value': value},
|
params={'value': value},
|
||||||
|
@ -127,7 +127,6 @@ class ForeignKey(ActivitypubRelatedFieldMixin, models.ForeignKey):
|
||||||
return value.remote_id
|
return value.remote_id
|
||||||
|
|
||||||
def field_from_activity(self, value):
|
def field_from_activity(self, value):
|
||||||
print(value)
|
|
||||||
try:
|
try:
|
||||||
validate_remote_id(value)
|
validate_remote_id(value)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
''' quotation activty object serializer class '''
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
@ -9,6 +10,7 @@ from bookwyrm import activitypub, models
|
||||||
class Quotation(TestCase):
|
class Quotation(TestCase):
|
||||||
''' we have hecka ways to create statuses '''
|
''' we have hecka ways to create statuses '''
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
''' model objects we'll need '''
|
||||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||||
|
@ -28,6 +30,7 @@ class Quotation(TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_quotation_activity(self):
|
def test_quotation_activity(self):
|
||||||
|
''' create a Quoteation ap object from json '''
|
||||||
quotation = activitypub.Quotation(**self.status_data)
|
quotation = activitypub.Quotation(**self.status_data)
|
||||||
|
|
||||||
self.assertEqual(quotation.type, 'Quotation')
|
self.assertEqual(quotation.type, 'Quotation')
|
||||||
|
@ -41,6 +44,7 @@ class Quotation(TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_activity_to_model(self):
|
def test_activity_to_model(self):
|
||||||
|
''' create a model instance from an activity object '''
|
||||||
activity = activitypub.Quotation(**self.status_data)
|
activity = activitypub.Quotation(**self.status_data)
|
||||||
quotation = activity.to_model(models.Quotation)
|
quotation = activity.to_model(models.Quotation)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue