kopia lustrzana https://github.com/snarfed/bridgy-fed
add Follower.to_as2()
rodzic
c3edf3a68e
commit
36349a5db9
|
@ -365,8 +365,12 @@ class Follower(StringIdModel):
|
|||
|
||||
def to_as1(self):
|
||||
"""Returns this follower as an AS1 actor dict, if possible."""
|
||||
return as2.to_as1(self.to_as2())
|
||||
|
||||
def to_as2(self):
|
||||
"""Returns this follower as an AS2 actor dict, if possible."""
|
||||
if self.last_follow:
|
||||
last_follow = json_loads(self.last_follow)
|
||||
person = last_follow.get('actor' if util.is_web(self.src) else 'object')
|
||||
if person:
|
||||
return as2.to_as1(person)
|
||||
return person
|
||||
|
|
|
@ -194,14 +194,22 @@ class ActivityTest(testutil.TestCase):
|
|||
|
||||
|
||||
class FollowerTest(testutil.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.inbound = Follower(dest='foo.com', src='http://bar/@baz',
|
||||
last_follow=json_dumps({'actor': ACTOR}))
|
||||
self.outbound = Follower(dest='http://bar/@baz', src='foo.com',
|
||||
last_follow=json_dumps({'object': ACTOR}))
|
||||
|
||||
def test_to_as1(self):
|
||||
self.assertIsNone(Follower().to_as1())
|
||||
self.assertEqual({}, Follower().to_as1())
|
||||
|
||||
as1_actor = as2.to_as1(ACTOR)
|
||||
f = Follower(dest='foo.com', src='http://bar/@baz',
|
||||
last_follow=json_dumps({'actor': ACTOR}))
|
||||
self.assertEqual(as1_actor, f.to_as1())
|
||||
self.assertEqual(as1_actor, self.inbound.to_as1())
|
||||
self.assertEqual(as1_actor, self.outbound.to_as1())
|
||||
|
||||
f = Follower(dest='http://bar/@baz', src='foo.com',
|
||||
last_follow=json_dumps({'object': ACTOR}))
|
||||
self.assertEqual(as1_actor, f.to_as1())
|
||||
def test_to_as2(self):
|
||||
self.assertIsNone(Follower().to_as2())
|
||||
self.assertEqual(ACTOR, self.inbound.to_as2())
|
||||
self.assertEqual(ACTOR, self.outbound.to_as2())
|
||||
|
|
Ładowanie…
Reference in New Issue