This commit is contained in:
Joachim
2021-05-26 23:57:29 +02:00
parent f848dcd756
commit 2ea1cd8319
69 changed files with 1370 additions and 1105 deletions

View File

@ -1,15 +1,17 @@
import datetime
from unittest.mock import patch
from django.test import TestCase
from bookwyrm import models
class Author(TestCase):
def setUp(self):
self.book = models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
)
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
self.book = models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
)
self.author = models.Author.objects.create(
name="Author fullname",
aliases=["One", "Two"],

View File

@ -25,24 +25,25 @@ class BaseActivity(TestCase):
def setUp(self):
"""we're probably going to re-use this so why copy/paste"""
self.user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
self.user.remote_id = "http://example.com/a/b"
self.user.save(broadcast=False)
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
self.user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
self.user.remote_id = "http://example.com/a/b"
self.user.save(broadcast=False)
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
self.userdata = json.loads(datafile.read_bytes())
# don't try to load the user icon
del self.userdata["icon"]
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
self.userdata = json.loads(datafile.read_bytes())
# don't try to load the user icon
del self.userdata["icon"]
image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg"
)
image = Image.open(image_file)
output = BytesIO()
image.save(output, format=image.format)
self.image_data = output.getvalue()
image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg"
)
image = Image.open(image_file)
output = BytesIO()
image.save(output, format=image.format)
self.image_data = output.getvalue()
def test_init(self, _):
"""simple successfuly init"""
@ -139,8 +140,9 @@ class BaseActivity(TestCase):
self.user.avatar.file # pylint: disable=pointless-statement
# this would trigger a broadcast because it's a local user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
activity.to_model(model=models.User, instance=self.user)
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
activity.to_model(model=models.User, instance=self.user)
self.assertIsNotNone(self.user.avatar.file)
self.assertEqual(self.user.name, "New Name")
self.assertEqual(self.user.key_pair.public_key, "hi")
@ -152,9 +154,10 @@ class BaseActivity(TestCase):
content="test status",
user=self.user,
)
book = models.Edition.objects.create(
title="Test Edition", remote_id="http://book.com/book"
)
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
book = models.Edition.objects.create(
title="Test Edition", remote_id="http://book.com/book"
)
update_data = activitypub.Note(
id=status.remote_id,
content=status.content,

View File

@ -22,10 +22,11 @@ class Quotation(TestCase):
outbox="https://example.com/user/mouse/outbox",
remote_id="https://example.com/user/mouse",
)
self.book = models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
)
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
self.book = models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
)
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_quotation.json")
self.status_data = json.loads(datafile.read_bytes())