Updates models tests
This commit is contained in:
@ -1,12 +1,16 @@
|
||||
""" testing models """
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
from django.db import IntegrityError
|
||||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models
|
||||
|
||||
|
||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
|
||||
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
|
||||
@patch("bookwyrm.lists_stream.remove_user_lists_task.delay")
|
||||
class Relationship(TestCase):
|
||||
"""following, blocking, stuff like that"""
|
||||
|
||||
@ -24,14 +28,39 @@ class Relationship(TestCase):
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
self.local_user.remote_id = "http://local.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
|
||||
def test_user_follows_from_request(self, _):
|
||||
def test_user_follows(self, *_):
|
||||
"""basic functionality of user follows"""
|
||||
relationship = models.UserFollows.objects.create(
|
||||
user_subject=self.local_user, user_object=self.remote_user
|
||||
)
|
||||
self.assertEqual(relationship.status, "follows")
|
||||
activity = relationship.to_activity()
|
||||
self.assertEqual(activity.type, "Follow")
|
||||
self.assertEqual(
|
||||
relationship.remote_id,
|
||||
f"http://local.com/user/mouse#follows/{relationship.id}",
|
||||
)
|
||||
|
||||
def test_user_follows_blocks(self, *_):
|
||||
"""can't follow if you're blocked"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
models.UserBlocks.objects.create(
|
||||
user_subject=self.local_user, user_object=self.remote_user
|
||||
)
|
||||
|
||||
with self.assertRaises(IntegrityError):
|
||||
models.UserFollows.objects.create(
|
||||
user_subject=self.local_user, user_object=self.remote_user
|
||||
)
|
||||
|
||||
def test_user_follows_from_request(self, *_):
|
||||
"""convert a follow request into a follow"""
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
@ -42,19 +71,19 @@ class Relationship(TestCase):
|
||||
activity = json.loads(mock.call_args[1]["args"][1])
|
||||
self.assertEqual(activity["type"], "Follow")
|
||||
self.assertEqual(
|
||||
request.remote_id, "http://local.com/user/mouse#follows/%d" % request.id
|
||||
request.remote_id, f"http://local.com/user/mouse#follows/{request.id}"
|
||||
)
|
||||
self.assertEqual(request.status, "follow_request")
|
||||
|
||||
rel = models.UserFollows.from_request(request)
|
||||
self.assertEqual(
|
||||
rel.remote_id, "http://local.com/user/mouse#follows/%d" % request.id
|
||||
rel.remote_id, f"http://local.com/user/mouse#follows/{request.id}"
|
||||
)
|
||||
self.assertEqual(rel.status, "follows")
|
||||
self.assertEqual(rel.user_subject, self.local_user)
|
||||
self.assertEqual(rel.user_object, self.remote_user)
|
||||
|
||||
def test_user_follows_from_request_custom_remote_id(self, _):
|
||||
def test_user_follows_from_request_custom_remote_id(self, *_):
|
||||
"""store a specific remote id for a relationship provided by remote"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
request = models.UserFollowRequest.objects.create(
|
||||
@ -72,7 +101,7 @@ class Relationship(TestCase):
|
||||
self.assertEqual(rel.user_object, self.remote_user)
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_follow_request_activity(self, broadcast_mock, _):
|
||||
def test_follow_request_activity(self, broadcast_mock, *_):
|
||||
"""accept a request and make it a relationship"""
|
||||
models.UserFollowRequest.objects.create(
|
||||
user_subject=self.local_user,
|
||||
@ -84,7 +113,7 @@ class Relationship(TestCase):
|
||||
self.assertEqual(activity["type"], "Follow")
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_follow_request_accept(self, broadcast_mock, _):
|
||||
def test_follow_request_accept(self, broadcast_mock, *_):
|
||||
"""accept a request and make it a relationship"""
|
||||
self.local_user.manually_approves_followers = True
|
||||
self.local_user.save(
|
||||
@ -110,7 +139,7 @@ class Relationship(TestCase):
|
||||
self.assertEqual(rel.user_object, self.local_user)
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_follow_request_reject(self, broadcast_mock, _):
|
||||
def test_follow_request_reject(self, broadcast_mock, *_):
|
||||
"""accept a request and make it a relationship"""
|
||||
self.local_user.manually_approves_followers = True
|
||||
self.local_user.save(
|
||||
|
Reference in New Issue
Block a user