diff --git a/kepi/bowler_pub/create.py b/kepi/bowler_pub/create.py index 223fa11..6bc6558 100644 --- a/kepi/bowler_pub/create.py +++ b/kepi/bowler_pub/create.py @@ -366,6 +366,46 @@ def on_person(fields, address): on_actor = on_person +def on_like(fields, address): + + logger.debug('%s: on_like %s', address, fields) + + liker = sombrero_fetch.fetch( + fields['actor'], + expected_type = trilby_models.Person, + ) + + if liker is None: + # shouldn't happen + logger.warning('%s: could not find user %s', + address, + fields['actor'], + ) + return None + + liked = sombrero_fetch.fetch( + fields['object'], + expected_type = trilby_models.Status, + ) + + if liked is None: + logger.info('%s: could not find status %s', + address, + fields['object'], + ) + return None + + like = trilby_models.Like( + liker = liker, + liked = liked, + ) + + like.save( + send_signal = True, + ) + + return like + def on_collection(fields, address): result = sombrero_collections.Collection( diff --git a/kepi/bowler_pub/tests/mastodon/test_like.py b/kepi/bowler_pub/tests/mastodon/test_like.py index c1c9994..cba0cd2 100644 --- a/kepi/bowler_pub/tests/mastodon/test_like.py +++ b/kepi/bowler_pub/tests/mastodon/test_like.py @@ -1,26 +1,43 @@ +# test_person.py +# +# Part of kepi. +# Copyright (c) 2018-2020 Marnanel Thurman. +# Licensed under the GNU Public License v2. + +import httpretty +from django.test import TestCase from kepi.trilby_api.tests import create_local_status, create_local_person from kepi.bowler_pub.create import create -from django.test import TestCase -class TestLike(TestCase): +import logging +logger = logging.getLogger(name='kepi') +class Tests(TestCase): + + @httpretty.activate def test_like(self): sender = create_local_person('sender') recipient = create_local_person('recipient') - status = create_local_status(posted_by=sender.id) + status = create_local_status(posted_by=sender) + + self.assertFalse( + sender.has_liked(status), + ) object_json = { '@context': 'https://www.w3.org/ns/activitystreams', 'id': 'foo', 'type': 'Like', - 'actor': sender.id, - 'object': status.id, + 'actor': sender.url, + 'object': status.url, } - status = create(**object_json) + like = create( + fields=object_json, + ) self.assertTrue( - sender.has_favourited(status), + sender.has_liked(status), msg = 'creates a favourite from sender to status', )