forked from mirrors/bookwyrm
Fix tests
This commit is contained in:
parent
bc7710a4a7
commit
c6f8236b07
2 changed files with 9 additions and 10 deletions
|
@ -387,7 +387,8 @@ class ImageField(ActivitypubFieldMixin, models.ImageField):
|
|||
activity[key] = formatted
|
||||
|
||||
def field_to_activity(self, value, alt=None):
|
||||
return image_serializer(value, alt)
|
||||
url = self.get_absolute_url(value)
|
||||
return activitypub.Document(url=url, name=alt)
|
||||
|
||||
def field_from_activity(self, value):
|
||||
image_slug = value
|
||||
|
@ -425,7 +426,7 @@ class ImageField(ActivitypubFieldMixin, models.ImageField):
|
|||
|
||||
def get_absolute_url(self, value):
|
||||
"""returns an absolute URL for the image"""
|
||||
name = getattr(value, self.name)
|
||||
name = getattr(value, "name")
|
||||
if name is None:
|
||||
return None
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ from bookwyrm.activitypub.base_activity import ActivityObject
|
|||
from bookwyrm.models import fields, User, Status
|
||||
from bookwyrm.models.base_model import BookWyrmModel
|
||||
from bookwyrm.models.activitypub_mixin import ActivitypubMixin
|
||||
from bookwyrm.settings import DOMAIN
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class ActivitypubFields(TestCase):
|
||||
|
@ -401,21 +402,18 @@ class ActivitypubFields(TestCase):
|
|||
image.save(output, format=image.format)
|
||||
user.avatar.save("test.jpg", ContentFile(output.getvalue()))
|
||||
|
||||
output = fields.image_serializer(user.avatar, alt="alt text")
|
||||
instance = fields.ImageField()
|
||||
|
||||
output = instance.field_to_activity(user.avatar)
|
||||
self.assertIsNotNone(
|
||||
re.match(
|
||||
r".*\.jpg",
|
||||
fr"https:\/\/{DOMAIN}\/.*\.jpg",
|
||||
output.url,
|
||||
)
|
||||
)
|
||||
self.assertEqual(output.name, "alt text")
|
||||
self.assertEqual(output.name, "")
|
||||
self.assertEqual(output.type, "Document")
|
||||
|
||||
instance = fields.ImageField()
|
||||
|
||||
output = fields.image_serializer(user.avatar, alt=None)
|
||||
self.assertEqual(instance.field_to_activity(user.avatar), output)
|
||||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
|
|
Loading…
Reference in a new issue