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