kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.receive: when fetching actor, fetch profile id
also update tests to test profile vs actor id with Fake users morepull/1731/head
rodzic
bf9957f889
commit
ca86534f21
|
|
@ -1042,7 +1042,8 @@ class Protocol:
|
||||||
if (actor and actor.keys() == set(['id'])
|
if (actor and actor.keys() == set(['id'])
|
||||||
and obj.type not in ('delete', 'undo')):
|
and obj.type not in ('delete', 'undo')):
|
||||||
logger.debug('Fetching actor so we have name, profile photo, etc')
|
logger.debug('Fetching actor so we have name, profile photo, etc')
|
||||||
actor_obj = from_cls.load(actor['id'], raise_=False)
|
actor_obj = from_cls.load(ids.profile_id(id=actor['id'], proto=from_cls),
|
||||||
|
raise_=False)
|
||||||
if actor_obj and actor_obj.as1:
|
if actor_obj and actor_obj.as1:
|
||||||
obj.our_as1 = {
|
obj.our_as1 = {
|
||||||
**obj.as1, 'actor': {
|
**obj.as1, 'actor': {
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ class PagesTest(TestCase):
|
||||||
['Updating profile from <a href="web:fake:user">fake:handle:user</a>...'],
|
['Updating profile from <a href="web:fake:user">fake:handle:user</a>...'],
|
||||||
get_flashed_messages())
|
get_flashed_messages())
|
||||||
|
|
||||||
self.assertEqual(['fake:profile:user', 'fake:user'], Fake.fetched)
|
self.assertEqual(['fake:profile:user'], Fake.fetched)
|
||||||
|
|
||||||
actor['updated'] = '2022-01-02T03:04:05+00:00'
|
actor['updated'] = '2022-01-02T03:04:05+00:00'
|
||||||
self.assert_object('fake:profile:user', source_protocol='fake', our_as1=actor,
|
self.assert_object('fake:profile:user', source_protocol='fake', our_as1=actor,
|
||||||
|
|
@ -248,7 +248,7 @@ class PagesTest(TestCase):
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
'verb': 'update',
|
'verb': 'update',
|
||||||
'id': 'fake:profile:user#bridgy-fed-update-2022-01-02T03:04:05+00:00',
|
'id': 'fake:profile:user#bridgy-fed-update-2022-01-02T03:04:05+00:00',
|
||||||
'actor': 'fake:user',
|
'actor': {**actor, 'id': 'fake:user'},
|
||||||
'object': actor,
|
'object': actor,
|
||||||
}
|
}
|
||||||
self.assertEqual([('other:bob:target', update)], OtherFake.sent)
|
self.assertEqual([('other:bob:target', update)], OtherFake.sent)
|
||||||
|
|
|
||||||
|
|
@ -1518,11 +1518,7 @@ class ProtocolReceiveTest(TestCase):
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
'verb': 'post',
|
'verb': 'post',
|
||||||
'id': 'fake:post#bridgy-fed-create',
|
'id': 'fake:post#bridgy-fed-create',
|
||||||
'actor': {
|
'actor': 'fake:user',
|
||||||
'objectType': 'person',
|
|
||||||
'id': 'fake:user',
|
|
||||||
'url': 'fake:user',
|
|
||||||
},
|
|
||||||
'object': note_as1,
|
'object': note_as1,
|
||||||
'published': '2022-01-02T03:04:05+00:00',
|
'published': '2022-01-02T03:04:05+00:00',
|
||||||
}
|
}
|
||||||
|
|
@ -1635,7 +1631,7 @@ class ProtocolReceiveTest(TestCase):
|
||||||
_, status = Fake.receive_as1(update)
|
_, status = Fake.receive_as1(update)
|
||||||
self.assertEqual(204, status)
|
self.assertEqual(204, status)
|
||||||
|
|
||||||
self.assertEqual(['fake:post'], Fake.fetched)
|
self.assertEqual(['fake:profile:user', 'fake:post'], Fake.fetched)
|
||||||
self.assert_object('fake:post',
|
self.assert_object('fake:post',
|
||||||
our_as1=post,
|
our_as1=post,
|
||||||
type='note',
|
type='note',
|
||||||
|
|
@ -1655,7 +1651,7 @@ class ProtocolReceiveTest(TestCase):
|
||||||
with self.assertRaises(ErrorButDoNotRetryTask):
|
with self.assertRaises(ErrorButDoNotRetryTask):
|
||||||
Fake.receive_as1(update)
|
Fake.receive_as1(update)
|
||||||
|
|
||||||
self.assertEqual(['fake:post'], Fake.fetched)
|
self.assertEqual(['fake:profile:user', 'fake:post'], Fake.fetched)
|
||||||
self.assertIsNone(Object.get_by_id('fake:update'))
|
self.assertIsNone(Object.get_by_id('fake:update'))
|
||||||
|
|
||||||
def test_create_reply(self):
|
def test_create_reply(self):
|
||||||
|
|
@ -2157,19 +2153,20 @@ class ProtocolReceiveTest(TestCase):
|
||||||
|
|
||||||
self.make_followers()
|
self.make_followers()
|
||||||
|
|
||||||
|
actor = {
|
||||||
|
'objectType': 'person',
|
||||||
|
'id': 'fake:user',
|
||||||
|
'displayName': 'Ms. ☕ Baz',
|
||||||
|
'urls': [{'displayName': 'Ms. ☕ Baz', 'value': 'https://user.com/'}],
|
||||||
|
'updated': '2022-01-02T03:04:05+00:00',
|
||||||
|
}
|
||||||
id = 'fake:user#update-2022-01-02T03:04:05+00:00'
|
id = 'fake:user#update-2022-01-02T03:04:05+00:00'
|
||||||
update_as1 = {
|
update_as1 = {
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
'verb': 'update',
|
'verb': 'update',
|
||||||
'id': id,
|
'id': id,
|
||||||
'actor': 'fake:user',
|
'actor': actor,
|
||||||
'object': {
|
'object': {**actor, 'id': 'fake:profile:user'},
|
||||||
'objectType': 'person',
|
|
||||||
'id': 'fake:profile:user',
|
|
||||||
'displayName': 'Ms. ☕ Baz',
|
|
||||||
'urls': [{'displayName': 'Ms. ☕ Baz', 'value': 'https://user.com/'}],
|
|
||||||
'updated': '2022-01-02T03:04:05+00:00',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
Fake.receive_as1(update_as1)
|
Fake.receive_as1(update_as1)
|
||||||
|
|
||||||
|
|
@ -2427,11 +2424,11 @@ class ProtocolReceiveTest(TestCase):
|
||||||
self.assertEqual([('efake:follow:target', accept_as1)], ExplicitFake.sent)
|
self.assertEqual([('efake:follow:target', accept_as1)], ExplicitFake.sent)
|
||||||
|
|
||||||
def test_stop_following(self):
|
def test_stop_following(self):
|
||||||
follower = Follower.get_or_create(to=self.user, from_=self.alice)
|
|
||||||
|
|
||||||
self.user.obj.our_as1 = {'id': 'fake:user'}
|
self.user.obj.our_as1 = {'id': 'fake:user'}
|
||||||
self.user.obj.put()
|
self.user.obj.put()
|
||||||
|
|
||||||
|
follower = Follower.get_or_create(to=self.user, from_=self.alice)
|
||||||
|
|
||||||
stop_as1 = {
|
stop_as1 = {
|
||||||
'id': 'other:stop-following',
|
'id': 'other:stop-following',
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
|
|
@ -2462,12 +2459,12 @@ class ProtocolReceiveTest(TestCase):
|
||||||
self.assertEqual([('fake:user:target', stop_following_as1)], Fake.sent)
|
self.assertEqual([('fake:user:target', stop_following_as1)], Fake.sent)
|
||||||
|
|
||||||
def test_stop_following_inactive(self):
|
def test_stop_following_inactive(self):
|
||||||
follower = Follower.get_or_create(to=self.user, from_=self.alice,
|
|
||||||
status='inactive')
|
|
||||||
OtherFake.fetchable['other:alice'] = {}
|
|
||||||
self.user.obj.our_as1 = {'id': 'fake:user'}
|
self.user.obj.our_as1 = {'id': 'fake:user'}
|
||||||
self.user.obj.put()
|
self.user.obj.put()
|
||||||
|
|
||||||
|
follower = Follower.get_or_create(to=self.user, from_=self.alice,
|
||||||
|
status='inactive')
|
||||||
|
|
||||||
stop_following_as1 = {
|
stop_following_as1 = {
|
||||||
'id': 'other:stop-following',
|
'id': 'other:stop-following',
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
|
|
@ -2690,7 +2687,7 @@ class ProtocolReceiveTest(TestCase):
|
||||||
self.assertEqual(('OK', 202), Fake.receive(obj, authed_as='fake:user'))
|
self.assertEqual(('OK', 202), Fake.receive(obj, authed_as='fake:user'))
|
||||||
self.assert_equals({
|
self.assert_equals({
|
||||||
**follow,
|
**follow,
|
||||||
'actor': {'id': 'fake:user'},
|
'actor': 'fake:user',
|
||||||
'object': 'other:alice',
|
'object': 'other:alice',
|
||||||
}, Object.get_by_id('fake:follow').our_as1)
|
}, Object.get_by_id('fake:follow').our_as1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ import protocol
|
||||||
import router
|
import router
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.getLogger('memcache').setLevel(logging.INFO)
|
||||||
|
|
||||||
ATPROTO_KEY = arroba.util.new_key(2349823483510) # deterministic seed
|
ATPROTO_KEY = arroba.util.new_key(2349823483510) # deterministic seed
|
||||||
|
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue