diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02433a68c30aa0edcd2ff0785752b03f89701826..e4db8983f8605cd9e7a27581acd26d85d2fbde7b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,29 @@ stages: + - test - review - build +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache" + +test_jsonld_ns: + stage: test + image: python:3 + interruptible: true + cache: + key: "$CI_PROJECT_ID__pip_cache" + paths: + - "$PIP_CACHE_DIR" + + before_script: + - pip install pyld pytest requests requests_mock + script: + - pytest test_ns.py + review: stage: review image: buildkite/puppeteer + interruptible: true variables: GIT_STRATEGY: clone VUE_APP_ROUTER_BASE_URL: /-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/review/ diff --git a/public/ns b/public/ns index 34aaee47f4c9b79c5639c45825329d9900c31307..1882881f91a61fb2904324121ae964e43633e29c 100644 --- a/public/ns +++ b/public/ns @@ -55,6 +55,6 @@ "@id": "fw:license", "@type": "@id" }, - "copyright": "fw:copyright", + "copyright": "fw:copyright" } } diff --git a/test_ns.py b/test_ns.py new file mode 100644 index 0000000000000000000000000000000000000000..afc7632e19a8382bf89a9c8fb65481d0f7787d4b --- /dev/null +++ b/test_ns.py @@ -0,0 +1,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