Skip to content
Snippets Groups Projects
Verified Commit 871f6f49 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added basic NS tests

parent e40ff9c4
No related branches found
No related tags found
1 merge request!20Added basic NS tests
Pipeline #9905 passed with stages
in 2 minutes and 12 seconds
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/
......
......@@ -55,6 +55,6 @@
"@id": "fw:license",
"@type": "@id"
},
"copyright": "fw:copyright",
"copyright": "fw:copyright"
}
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment