Skip to content

Commit

Permalink
tests: remove routing special case for Fake and OtherFake in Protocol…
Browse files Browse the repository at this point in the history
….receive

for #1180
  • Loading branch information
snarfed committed Oct 8, 2024
1 parent 20477db commit a5cbc9b
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 276 deletions.
7 changes: 2 additions & 5 deletions protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def receive(from_cls, obj, authed_as=None, internal=False):
if orig.changed is not None:
obj.changed = orig.changed

# if this is a post, ie not an activity, wrap it in a create or update
# if this is an object, ie not an activity, wrap it in a create or update
obj = from_cls.handle_bare_object(obj, authed_as=authed_as)
obj.add('users', from_user.key)

Expand Down Expand Up @@ -1317,8 +1317,6 @@ def targets(from_cls, obj, from_user, internal=False):

# which protocols should we allow delivering to?
to_protocols = []
if DEBUG and from_user.LABEL != 'efake': # for unit tests
to_protocols += [PROTOCOLS['fake'], PROTOCOLS['other']]
for label in (list(from_user.DEFAULT_ENABLED_PROTOCOLS)
+ from_user.enabled_protocols):
proto = PROTOCOLS[label]
Expand Down Expand Up @@ -1351,8 +1349,7 @@ def targets(from_cls, obj, from_user, internal=False):
continue

target_author_key = target_proto.actor_key(orig_obj)
if (target_proto not in to_protocols
and obj.source_protocol != target_proto.LABEL):
if not from_user.is_enabled(target_proto):
# if author isn't bridged and inReplyTo author is, DM a prompt
if id in in_reply_tos:
if target_author := target_author_key.get():
Expand Down
10 changes: 6 additions & 4 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,16 +881,18 @@ def test_repost_of_indieweb(self, mock_head, mock_get, mock_post):
delivered=['https://user.com/orig'],
type='share',
)

def test_shared_inbox_repost_of_fediverse(self, mock_head, mock_get, mock_post):
to = self.make_user(ACTOR['id'], cls=ActivityPub, obj_as2=ACTOR)
Follower.get_or_create(to=to, from_=self.user)
baz = self.make_user('fake:baz', cls=Fake, obj_id='fake:baz')
baz = self.make_user('fake:baz', cls=Fake, obj_id='fake:baz',
enabled_protocols=['activitypub'])
Follower.get_or_create(to=to, from_=baz)
baj = self.make_user('fake:baj', cls=Fake, obj_id='fake:baj')
baj = self.make_user('fake:baj', cls=Fake, obj_id='fake:baj',
enabled_protocols=['activitypub'])
Follower.get_or_create(to=to, from_=baj, status='inactive')

mock_head.return_value = requests_response(url='http://target')
self.store_object(id=NOTE_OBJECT['id'],
copies=[Target(protocol='fake', uri='fake:o:ap:note')])
mock_get.return_value = self.as2_resp(NOTE_OBJECT)

got = self.post('/ap/sharedInbox', json=REPOST)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ def test_send_new_repo(self, mock_post, mock_create_task, _):
user = user.key.get()
did = user.get_copy(ATProto)
assert did
self.assertEqual([Target(uri=did, protocol='atproto')], user.copies)
self.assertIn(Target(uri=did, protocol='atproto'), user.copies)
did_obj = ATProto.load(did, did_doc=True)
self.assertEqual('http://localhost',
did_obj.raw['service'][0]['serviceEndpoint'])
Expand Down
3 changes: 3 additions & 0 deletions tests/test_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@


class DmsTest(TestCase):
# def setUp(self):
# print('@@@')

def make_alice_bob(self):
self.make_user(id='efake.brid.gy', cls=Web)
self.make_user(id='other.brid.gy', cls=Web)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ def test_web_follow_of_atproto(self, mock_get, mock_post, _, __):

# check results
bob = bob.key.get()
self.assertEqual(1, len(bob.copies))
self.assertEqual('atproto', bob.copies[0].protocol)
bob_did = bob.copies[0].uri
self.assertTrue(bob.is_enabled(ATProto))
bob_did = bob.get_copy(ATProto)
assert bob_did

self.assertEqual({
'type': ['h-entry'],
Expand Down
14 changes: 8 additions & 6 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def test_get_or_create_propagate_fake_other(self):
self.assertEqual(['fake:user'], OtherFake.created_for)

@patch.object(tasks_client, 'create_task', return_value=Task(name='my task'))
@patch('requests.post',
return_value=requests_response('OK')) # create DID on PLC
@patch('requests.post', return_value=requests_response('OK')) # create DID on PLC
def test_get_or_create_propagate_atproto(self, mock_post, mock_create_task):
common.RUN_TASKS_INLINE = False

Expand Down Expand Up @@ -119,9 +118,12 @@ def test_get_or_create_propagate_atproto(self, mock_post, mock_create_task):
},
}, profile)

uri = at_uri(did, 'app.bsky.actor.profile', 'self')
self.assertEqual([Target(uri=uri, protocol='atproto')],
Object.get_by_id(id='fake:profile:user').copies)
obj = Object.get_by_id('fake:profile:user')
self.assertEqual([
Target(protocol='atproto',
uri=at_uri(did, 'app.bsky.actor.profile', 'self')),
Target(protocol='other', uri='other:o:fa:fake:profile:user'),
], obj.copies)

mock_create_task.assert_called()

Expand All @@ -139,7 +141,7 @@ def test_get_or_create_propagate_not_enabled(self, mock_get, mock_post,
mock_create_task.assert_not_called()

user = ActivityPub.get_by_id('https://mas.to/actor')
self.assertEqual([], user.copies)
self.assertIsNone(user.get_copy(ATProto))
self.assertEqual(0, AtpRepo.query().count())

@patch.object(ExplicitFake, 'create_for', side_effect=ValueError('foo'))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def test_update_profile_receive_task(self, mock_create_task):

@patch('requests.get', return_value=ACTOR_HTML_RESP)
def test_update_profile_web(self, mock_get):
self.user.obj.copies = [Target(protocol='fake', uri='fa:profile:web:user.com')]
self.user.obj.put()
Follower.get_or_create(from_=self.make_user('fake:user', cls=Fake),
to=self.user)

Expand Down Expand Up @@ -273,6 +275,8 @@ def test_update_profile_web(self, mock_get):
ACTOR_HTML.replace('Ms. ☕ Baz', 'Ms. ☕ Baz #nobridge'),
url='https://user.com/'))
def test_update_profile_web_delete(self, mock_get):
self.user.obj.copies = [Target(protocol='fake', uri='fa:profile:web:user.com')]
self.user.obj.put()
Follower.get_or_create(from_=self.make_user('fake:user', cls=Fake),
to=self.user)

Expand Down
Loading

0 comments on commit a5cbc9b

Please sign in to comment.