funkwhale/api/tests/history/test_activity.py

60 wiersze
2.3 KiB
Python
Czysty Zwykły widok Historia

2018-06-10 08:55:16 +00:00
from funkwhale_api.history import activities, serializers
2018-03-01 22:41:51 +00:00
from funkwhale_api.music.serializers import TrackActivitySerializer
2018-06-10 08:55:16 +00:00
from funkwhale_api.users.serializers import UserActivitySerializer
2018-03-01 22:41:51 +00:00
def test_get_listening_activity_url(settings, factories):
2018-06-09 13:36:16 +00:00
listening = factories["history.Listening"]()
2018-03-01 22:41:51 +00:00
user_url = listening.user.get_activity_url()
2018-06-09 13:36:16 +00:00
expected = "{}/listenings/tracks/{}".format(user_url, listening.pk)
2018-03-01 22:41:51 +00:00
assert listening.get_activity_url() == expected
def test_activity_listening_serializer(factories):
2018-06-09 13:36:16 +00:00
listening = factories["history.Listening"]()
2018-03-01 22:41:51 +00:00
actor = UserActivitySerializer(listening.user).data
field = serializers.serializers.DateTimeField()
expected = {
"type": "Listen",
"local_id": listening.pk,
"id": listening.get_activity_url(),
"actor": actor,
"object": TrackActivitySerializer(listening.track).data,
"published": field.to_representation(listening.creation_date),
2018-03-01 22:41:51 +00:00
}
data = serializers.ListeningActivitySerializer(listening).data
assert data == expected
def test_track_listening_serializer_is_connected(activity_registry):
2018-06-09 13:36:16 +00:00
conf = activity_registry["history.Listening"]
assert conf["serializer"] == serializers.ListeningActivitySerializer
2018-03-01 22:41:51 +00:00
2018-06-09 13:36:16 +00:00
def test_track_listening_serializer_instance_activity_consumer(activity_registry):
conf = activity_registry["history.Listening"]
2018-03-01 22:41:51 +00:00
consumer = activities.broadcast_listening_to_instance_activity
2018-06-09 13:36:16 +00:00
assert consumer in conf["consumers"]
2018-03-01 22:41:51 +00:00
2018-06-09 13:36:16 +00:00
def test_broadcast_listening_to_instance_activity(factories, mocker):
p = mocker.patch("funkwhale_api.common.channels.group_send")
listening = factories["history.Listening"]()
2018-03-01 22:41:51 +00:00
data = serializers.ListeningActivitySerializer(listening).data
consumer = activities.broadcast_listening_to_instance_activity
2018-06-09 13:36:16 +00:00
message = {"type": "event.send", "text": "", "data": data}
2018-03-01 22:41:51 +00:00
consumer(data=data, obj=listening)
2018-06-09 13:36:16 +00:00
p.assert_called_once_with("instance_activity", message)
2018-03-01 22:41:51 +00:00
2018-06-09 13:36:16 +00:00
def test_broadcast_listening_to_instance_activity_private(factories, mocker):
p = mocker.patch("funkwhale_api.common.channels.group_send")
listening = factories["history.Listening"](user__privacy_level="me")
2018-03-01 22:41:51 +00:00
data = serializers.ListeningActivitySerializer(listening).data
consumer = activities.broadcast_listening_to_instance_activity
consumer(data=data, obj=listening)
p.assert_not_called()