kopia lustrzana https://gitlab.com/marnanel/chapeau
on_like() added to create.py; test_like() passes
rodzic
bbb0fc278a
commit
fda564d8d2
|
@ -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(
|
||||
|
|
|
@ -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',
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue