ids.translate_user_id: follow use_instead

pull/714/head
Ryan Barrett 2023-11-03 14:53:19 -07:00
rodzic 6410d0ef1a
commit cada99e407
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 22 dodań i 1 usunięć

7
ids.py
Wyświetl plik

@ -36,8 +36,13 @@ def translate_user_id(*, id, from_proto, to_proto):
if from_proto == to_proto:
return id
# follow use_instead
user = from_proto.get_by_id(id)
if user:
id = user.key.id()
def copy_or_original():
if user := from_proto.get_by_id(id):
if user:
if copy := user.get_copy(to_proto):
return copy
if orig := models.get_original(id):

Wyświetl plik

@ -58,6 +58,22 @@ class IdsTest(TestCase):
self.assertIsNone(translate_user_id(
id='did:plc:123', from_proto=ATProto, to_proto=proto))
def test_translate_user_id_use_instead(self):
did = Target(uri='did:plc:123', protocol='atproto')
user = self.make_user('user.com', cls=Web, copies=[did])
self.make_user('www.user.com', cls=Web, use_instead=user.key)
for proto, expected in [
(ATProto, 'did:plc:123'),
(ActivityPub, 'http://localhost/user.com'),
(Fake, 'fake:u:user.com'),
]:
with self.subTest(proto=proto.LABEL):
self.assertEqual(expected, translate_user_id(
id='www.user.com', from_proto=Web, to_proto=proto))
self.assertEqual(expected, translate_user_id(
id='https://www.user.com/', from_proto=Web, to_proto=proto))
def test_translate_handle(self):
for from_, handle, to, expected in [
# basic