Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pyld
import json
import os
import requests_mock
PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "public", "ns")
def test_ns_is_valid_json():
with open(PATH) as f:
content = f.read()
json.loads(content)
def test_fw_activity_using_schema():
with open(PATH) as f:
schema = f.read()
jsonld_payload = """
{
"type": "Album",
"id": "https://channels.tests.funkwhale.audio/federation/music/albums/56439007-9f14-4f39-adbf-2108a6d2f494",
"name": "Hobbykoch Podcast",
"published": "2020-02-19T08:00:53.525566+00:00",
"musicbrainzId": null,
"released": "2020-01-01",
"artists": [
{
"type": "Artist",
"id": "https://channels.tests.funkwhale.audio/federation/music/artists/bc187046-ab46-4e16-a41f-770e663dc285",
"name": "Kai Daniel Du",
"published": "2020-02-19T08:00:53.521010+00:00",
"musicbrainzId": null,
"attributedTo": "https://channels.tests.funkwhale.audio/federation/actors/Testacc242",
"tag": [
{
"type": "Hashtag",
"name": "#Podcast"
}
],
"image": null
}
],
"attributedTo": "https://channels.tests.funkwhale.audio/federation/actors/Testacc242",
"tag": [
{
"type": "Hashtag",
"name": "#Podcast"
}
],
"cover": {
"type": "Link",
"href": "https://channels.tests.funkwhale.audio/media/attachments/d7/e1/84/attachment_cover-56439007-9f14-4f39-adbf-2108a6d2f494.jpg",
"mediaType": "image/jpeg"
},
"image": {
"type": "Image",
"url": "https://channels.tests.funkwhale.audio/media/attachments/d7/e1/84/attachment_cover-56439007-9f14-4f39-adbf-2108a6d2f494.jpg",
"mediaType": "image/jpeg"
},
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
"https://funkwhale.audio/ns",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"Hashtag": "as:Hashtag"
}
]
}
"""
parsed = json.loads(jsonld_payload)
with requests_mock.Mocker(real_http=True) as m:
m.get("https://funkwhale.audio/ns", text=schema)
expanded = pyld.jsonld.expand(parsed)
serialized = json.dumps(expanded, indent=2)
assert "_:" not in serialized