kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
2e79512f55
commit
71174b69f9
|
@ -202,7 +202,10 @@ class Protocol:
|
|||
send_webmentions(obj, proxy=True)
|
||||
|
||||
# deliver original posts and reposts to followers
|
||||
if obj.type in ('share', 'create', 'post') and actor and actor_id:
|
||||
is_reply = (obj.type == 'comment' or
|
||||
(inner_obj and inner_obj.get('inReplyTo')))
|
||||
if (actor and actor_id and
|
||||
(obj.type == 'share' or obj.type in ('create', 'post') and not is_reply)):
|
||||
logger.info(f'Delivering to followers of {actor_id}')
|
||||
for f in models.Follower.query(models.Follower.dest == actor_id,
|
||||
models.Follower.status == 'active',
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
"""Unit tests for protocol.py."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from oauth_dropins.webutil.testutil import requests_response
|
||||
import requests
|
||||
|
||||
from protocol import Protocol
|
||||
from app import app
|
||||
from models import Follower, Object, User
|
||||
|
||||
from .test_activitypub import ACTOR, REPLY
|
||||
from . import testutil
|
||||
|
||||
|
||||
class ProtocolTest(testutil.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user = self.make_user('foo.com', has_hcard=True)
|
||||
self.app_context = app.test_request_context('/')
|
||||
self.app_context.__enter__()
|
||||
|
||||
def tearDown(self):
|
||||
self.app_context.__exit__(None, None, None)
|
||||
super().tearDown()
|
||||
|
||||
@patch('requests.get')
|
||||
def test_receive_reply_dont_deliver_to_followers(self, mock_get):
|
||||
Follower.get_or_create('or.ig', ACTOR['id'])
|
||||
|
||||
# or.ig webmention discovery
|
||||
mock_get.return_value = requests_response('<html></html>')
|
||||
|
||||
reply = {
|
||||
**REPLY,
|
||||
'actor': ACTOR,
|
||||
'object': {
|
||||
**REPLY['object'],
|
||||
'author': ACTOR,
|
||||
},
|
||||
}
|
||||
Protocol.receive(reply['id'], user=self.user, as2=reply)
|
||||
|
||||
self.assert_object(reply['id'],
|
||||
as2=reply,
|
||||
type='post',
|
||||
domains=['or.ig'],
|
||||
labels=['notification', 'activity'],
|
||||
status='complete',
|
||||
)
|
||||
self.assert_object(reply['object']['id'],
|
||||
as2=reply['object'],
|
||||
type='comment',
|
||||
)
|
Ładowanie…
Reference in New Issue