2018-05-07 20:09:03 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
|
|
|
|
def test_nodeinfo_endpoint(db, api_client, mocker):
|
2018-06-09 13:36:16 +00:00
|
|
|
payload = {"test": "test"}
|
2018-06-10 09:27:38 +00:00
|
|
|
mocker.patch("funkwhale_api.instance.nodeinfo.get", return_value=payload)
|
2018-06-09 13:36:16 +00:00
|
|
|
url = reverse("api:v1:instance:nodeinfo-2.0")
|
2018-05-07 20:09:03 +00:00
|
|
|
response = api_client.get(url)
|
2018-06-09 13:36:16 +00:00
|
|
|
ct = "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" # noqa
|
2018-05-07 20:09:03 +00:00
|
|
|
assert response.status_code == 200
|
2018-06-09 13:36:16 +00:00
|
|
|
assert response["Content-Type"] == ct
|
2018-05-07 20:09:03 +00:00
|
|
|
assert response.data == payload
|
|
|
|
|
|
|
|
|
|
|
|
def test_nodeinfo_endpoint_disabled(db, api_client, preferences):
|
2018-06-09 13:36:16 +00:00
|
|
|
preferences["instance__nodeinfo_enabled"] = False
|
|
|
|
url = reverse("api:v1:instance:nodeinfo-2.0")
|
2018-05-07 20:09:03 +00:00
|
|
|
response = api_client.get(url)
|
|
|
|
|
|
|
|
assert response.status_code == 404
|
2018-05-17 21:39:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_settings_only_list_public_settings(db, api_client, preferences):
|
2018-06-09 13:36:16 +00:00
|
|
|
url = reverse("api:v1:instance:settings")
|
2018-05-17 21:39:34 +00:00
|
|
|
response = api_client.get(url)
|
|
|
|
|
|
|
|
for conf in response.data:
|
2018-06-09 13:36:16 +00:00
|
|
|
p = preferences.model.objects.get(section=conf["section"], name=conf["name"])
|
2018-05-17 21:39:34 +00:00
|
|
|
assert p.preference.show_in_api is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_admin_settings_restrict_access(db, logged_in_api_client, preferences):
|
2018-06-09 13:36:16 +00:00
|
|
|
url = reverse("api:v1:instance:admin-settings-list")
|
2018-05-17 21:39:34 +00:00
|
|
|
response = logged_in_api_client.get(url)
|
|
|
|
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
def test_admin_settings_correct_permission(db, logged_in_api_client, preferences):
|
2018-05-17 21:39:34 +00:00
|
|
|
user = logged_in_api_client.user
|
2018-05-18 16:48:46 +00:00
|
|
|
user.permission_settings = True
|
|
|
|
user.save()
|
2018-06-09 13:36:16 +00:00
|
|
|
url = reverse("api:v1:instance:admin-settings-list")
|
2018-05-17 21:39:34 +00:00
|
|
|
response = logged_in_api_client.get(url)
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert len(response.data) == len(preferences.all())
|