Skip to content

Commit

Permalink
Fix activitypub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LoanR committed Jul 31, 2024
1 parent 88cfe63 commit 0085c3a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 30 deletions.
9 changes: 6 additions & 3 deletions pod/activitypub/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ def external_video_update(ap_video):

def external_video_deletion(ap_video_id):
logger.warning("ActivityPub task call ExternalVideo %s delete", ap_video_id)
external_video_to_delete = ExternalVideo.objects.get(ap_id=ap_video_id)
delete_es(media=external_video_to_delete)
external_video_to_delete.delete()
try:
external_video_to_delete = ExternalVideo.objects.get(ap_id=ap_video_id)
delete_es(media=external_video_to_delete)
external_video_to_delete.delete()
except ExternalVideo.DoesNotExist:
logger.warning("Received an ActivityPub delete event on a nonexistent ExternalVideo %s", ap_video_id)


def send_video_announce_object(video: Video, follower: Follower):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
],
"cc": [],
"type": "Announce",
"id": "http://peertube.test/videos/watch/a425fb67-0d67-405f-a305-9cfc62ec00fd/announces/1",
"id": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/announces/1",
"actor": "http://peertube.test/accounts/peertube",
"object": "http://peertube.test/videos/watch/a425fb67-0d67-405f-a305-9cfc62ec00fd",
"object": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d",
"signature": {
"type": "RsaSignature2017",
"creator": "http://peertube.test/accounts/peertube",
"created": "2024-05-15T11:15:55.283Z",
"signatureValue": "I0hzAFwpnlBthbAVas/eN+wAFC2G7mUBPi4ZefgvYKAxm990D0AopzQDUoW+P7Cc8CW7iUv2pX6GwM/m6Ez8LvKaDERmjNjPmAPIAC2Hm/V4/FTuCZ4wiQoIVvRNEsV/4O40Rr+ZyU+A9pJGhFh3RwJ3ezMsCdI36LVx2UHvgBM="
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
],
"cc": [],
"type": "Announce",
"id": "http://peertube.test/videos/watch/a425fb67-0d67-405f-a305-9cfc62ec00fd/announces/3",
"id": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/announces/3",
"actor": "http://peertube.test/video-channels/root_channel",
"object": "http://peertube.test/videos/watch/a425fb67-0d67-405f-a305-9cfc62ec00fd",
"object": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d",
"signature": {
"type": "RsaSignature2017",
"creator": "http://peertube.test/video-channels/root_channel",
"created": "2024-05-15T11:15:54.089Z",
"signatureValue": "H6dBSuPhq0jqJVqHYq8+9SgyQNKwdH3wfTqvTyXGPAfM7xcLWU1o7nSViVkRoIMhvTMzFQYAGrBr5HCdTpfv+q6iyuxf3udTdIzaO7ilqmmihI9gu104nRg61tNPGkbWwhQ2IWLFlVGVlKsTzNdU2VteOQT98LpA1GpFa9ExDdk="
}
}

4 changes: 2 additions & 2 deletions pod/activitypub/tests/fixtures/video_delete.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
],
"cc": [],
"type": "Delete",
"id": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/delete",
"id": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/delete",
"actor": "http://peertube.test/accounts/root",
"object": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8",
"object": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d",
"signature": {
"type": "RsaSignature2017",
"creator": "http://peertube.test/accounts/root",
Expand Down
28 changes: 14 additions & 14 deletions pod/activitypub/tests/fixtures/video_update.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"http://peertube.test/accounts/root/followers"
],
"type": "Update",
"id": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/updates/2024-05-15T12:40:45.399Z",
"id": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/updates/2024-05-15T12:40:45.399Z",
"actor": "http://peertube.test/accounts/root",
"object": {
"to": [
Expand All @@ -119,10 +119,10 @@
"http://peertube.test/accounts/root/followers"
],
"type": "Video",
"id": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8",
"id": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d",
"name": "terre",
"duration": "PT31S",
"uuid": "74b35c2c-5b41-47ee-b331-86ec80f317d8",
"uuid": "717c9d87-c912-4943-a392-49fadf2f235d",
"views": 0,
"sensitive": false,
"waitTranscoding": true,
Expand Down Expand Up @@ -177,12 +177,12 @@
{
"type": "Link",
"mediaType": "text/html",
"href": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8"
"href": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d"
},
{
"type": "Link",
"mediaType": "application/x-mpegURL",
"href": "http://peertube.test/static/streaming-playlists/hls/74b35c2c-5b41-47ee-b331-86ec80f317d8/af301f93-0d7d-4940-8e5e-aba13049ac26-master.m3u8",
"href": "http://peertube.test/static/streaming-playlists/hls/717c9d87-c912-4943-a392-49fadf2f235d/af301f93-0d7d-4940-8e5e-aba13049ac26-master.m3u8",
"tag": [
{
"type": "Infohash",
Expand All @@ -192,12 +192,12 @@
"type": "Link",
"name": "sha256",
"mediaType": "application/json",
"href": "http://peertube.test/static/streaming-playlists/hls/74b35c2c-5b41-47ee-b331-86ec80f317d8/dc1221ee-1090-40b8-bdfa-5a5f4cd67c98-segments-sha256.json"
"href": "http://peertube.test/static/streaming-playlists/hls/717c9d87-c912-4943-a392-49fadf2f235d/dc1221ee-1090-40b8-bdfa-5a5f4cd67c98-segments-sha256.json"
},
{
"type": "Link",
"mediaType": "video/mp4",
"href": "http://peertube.test/static/streaming-playlists/hls/74b35c2c-5b41-47ee-b331-86ec80f317d8/519179ac-f8f9-4c50-a90c-2d6bf554e508-270-fragmented.mp4",
"href": "http://peertube.test/static/streaming-playlists/hls/717c9d87-c912-4943-a392-49fadf2f235d/519179ac-f8f9-4c50-a90c-2d6bf554e508-270-fragmented.mp4",
"height": 270,
"width": 480,
"size": 653210,
Expand All @@ -210,7 +210,7 @@
"video/mp4"
],
"mediaType": "application/json",
"href": "http://peertube.test/api/v1/videos/74b35c2c-5b41-47ee-b331-86ec80f317d8/metadata/3",
"href": "http://peertube.test/api/v1/videos/717c9d87-c912-4943-a392-49fadf2f235d/metadata/3",
"height": 270,
"width": 480,
"fps": 30
Expand All @@ -226,7 +226,7 @@
{
"type": "Link",
"mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
"href": "magnet:?xs=http%3A%2F%2Fpeertube.localhost%3A9000%2Flazy-static%2Ftorrents%2Fb0e90759-ec93-47b1-a54b-124eecc7e920-270-hls.torrent&xt=urn:btih:5072ce02cf06578a6ea1c3aa95f80f25afc33949&dn=terre&tr=http%3A%2F%2Fpeertube.localhost%3A9000%2Ftracker%2Fannounce&tr=ws%3A%2F%2Fpeertube.localhost%3A9000%2Ftracker%2Fsocket&ws=http%3A%2F%2Fpeertube.localhost%3A9000%2Fstatic%2Fstreaming-playlists%2Fhls%2F74b35c2c-5b41-47ee-b331-86ec80f317d8%2F519179ac-f8f9-4c50-a90c-2d6bf554e508-270-fragmented.mp4",
"href": "magnet:?xs=http%3A%2F%2Fpeertube.localhost%3A9000%2Flazy-static%2Ftorrents%2Fb0e90759-ec93-47b1-a54b-124eecc7e920-270-hls.torrent&xt=urn:btih:5072ce02cf06578a6ea1c3aa95f80f25afc33949&dn=terre&tr=http%3A%2F%2Fpeertube.localhost%3A9000%2Ftracker%2Fannounce&tr=ws%3A%2F%2Fpeertube.localhost%3A9000%2Ftracker%2Fsocket&ws=http%3A%2F%2Fpeertube.localhost%3A9000%2Fstatic%2Fstreaming-playlists%2Fhls%2F717c9d87-c912-4943-a392-49fadf2f235d%2F519179ac-f8f9-4c50-a90c-2d6bf554e508-270-fragmented.mp4",
"height": 270,
"width": 480,
"fps": 30
Expand All @@ -252,11 +252,11 @@
"href": "ws://peertube.test/tracker/socket"
}
],
"likes": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/likes",
"dislikes": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/dislikes",
"shares": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/announces",
"comments": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/comments",
"hasParts": "http://peertube.test/videos/watch/74b35c2c-5b41-47ee-b331-86ec80f317d8/chapters",
"likes": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/likes",
"dislikes": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/dislikes",
"shares": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/announces",
"comments": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/comments",
"hasParts": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d/chapters",
"attributedTo": [
{
"type": "Person",
Expand Down
5 changes: 2 additions & 3 deletions pod/activitypub/tests/fixtures/video_view.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"http://peertube.test/accounts/root/followers"
],
"cc": [],
"id": "http://peertube.test/accounts/peertube/views/videos/1/CBmE6B8qR3wmPvfXxlnzYLZj2aGxHbuP-a425fb67-0d67-405f-a305-9cfc62ec00fd",
"id": "http://peertube.test/accounts/peertube/views/videos/1/CBmE6B8qR3wmPvfXxlnzYLZj2aGxHbuP-717c9d87-c912-4943-a392-49fadf2f235d",
"type": "View",
"actor": "http://peertube.test/accounts/peertube",
"object": "http://peertube.test/videos/watch/a425fb67-0d67-405f-a305-9cfc62ec00fd",
"object": "http://peertube.test/videos/watch/717c9d87-c912-4943-a392-49fadf2f235d",
"expires": "2024-05-15T11:17:56.017Z",
"signature": {
"type": "RsaSignature2017",
Expand All @@ -31,4 +31,3 @@
"signatureValue": "xCmw4sWlGwss1ksoYSWAZ3g2+ZCy9ILiicz2YYgfeyCssstKDV405l6NfP+g7T0i4icQnjhyaOAYjveQlLSEvth1lhrwStBpY6WboAKbpct6aFV37a5FTAHHZD/zlGHRGTf2PJrPem4MMB0zI9Hr4K0gqylHGMDazyPElJl4S4E="
}
}

43 changes: 41 additions & 2 deletions pod/activitypub/tests/test_video_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_video_creation(self):
) as fd:
account_announce_payload = json.load(fd)

assert not len(ExternalVideo.objects.all())

with httmock.HTTMock(self.mock_application_actor, self.mock_get_video):
response = self.client.post(
"/ap/inbox",
Expand All @@ -32,6 +34,7 @@ def test_video_creation(self):
)
self.assertEqual(response.status_code, 204)

assert len(ExternalVideo.objects.all()) == 1
# TODO: assert ExternalVideo is created

with open(
Expand Down Expand Up @@ -66,6 +69,24 @@ def test_video_view(self):
def test_video_update(self):
"""Test the video update activity on the inbox"""

with open(
"pod/activitypub/tests/fixtures/video_creation_account_announce.json"
) as fd:
account_announce_payload = json.load(fd)

assert not len(ExternalVideo.objects.all())

with httmock.HTTMock(self.mock_application_actor, self.mock_get_video):
response = self.client.post(
"/ap/inbox",
json.dumps(account_announce_payload),
content_type="application/json",
**self.headers,
)
self.assertEqual(response.status_code, 204)

assert ExternalVideo.objects.first().title == "Titre de la vidéo"

with open("pod/activitypub/tests/fixtures/video_update.json") as fd:
payload = json.load(fd)

Expand All @@ -77,11 +98,29 @@ def test_video_update(self):
)
self.assertEqual(response.status_code, 204)

# TODO: assert ExternalVideo is updated
assert ExternalVideo.objects.first().title == "terre"

def test_video_delete(self):
"""Test the video update activity on the inbox"""

with open(
"pod/activitypub/tests/fixtures/video_creation_account_announce.json"
) as fd:
account_announce_payload = json.load(fd)

assert not len(ExternalVideo.objects.all())

with httmock.HTTMock(self.mock_application_actor, self.mock_get_video):
response = self.client.post(
"/ap/inbox",
json.dumps(account_announce_payload),
content_type="application/json",
**self.headers,
)
self.assertEqual(response.status_code, 204)

assert len(ExternalVideo.objects.all()) == 1

with open("pod/activitypub/tests/fixtures/video_delete.json") as fd:
payload = json.load(fd)

Expand All @@ -94,4 +133,4 @@ def test_video_delete(self):
)
self.assertEqual(response.status_code, 204)

# TODO: assert ExternalVideo is deleted
assert not len(ExternalVideo.objects.all())

0 comments on commit 0085c3a

Please sign in to comment.