funkwhale/api/tests/music/test_api.py

51 wiersze
1.5 KiB
Python
Czysty Zwykły widok Historia

2017-12-27 22:32:02 +00:00
import os
2018-06-10 08:55:16 +00:00
import pytest
from django.urls import reverse
2017-12-27 22:32:02 +00:00
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
2018-06-09 13:36:16 +00:00
@pytest.mark.parametrize(
"route,method",
[
("api:v1:tags-list", "get"),
("api:v1:tracks-list", "get"),
("api:v1:artists-list", "get"),
("api:v1:albums-list", "get"),
],
)
def test_can_restrict_api_views_to_authenticated_users(
2018-06-09 13:36:16 +00:00
db, route, method, preferences, client
):
url = reverse(route)
2018-06-09 13:36:16 +00:00
preferences["common__api_authentication_required"] = True
response = getattr(client, method)(url)
assert response.status_code == 401
2018-09-22 12:29:30 +00:00
def test_upload_url_is_restricted_to_authenticated_users(
2018-06-09 13:36:16 +00:00
api_client, factories, preferences
):
preferences["common__api_authentication_required"] = True
2018-09-22 12:29:30 +00:00
upload = factories["music.Upload"](library__privacy_level="instance")
assert upload.audio_file is not None
url = upload.track.listen_url
response = api_client.get(url)
assert response.status_code == 401
2018-09-22 12:29:30 +00:00
def test_upload_url_is_accessible_to_authenticated_users(
2018-06-09 13:36:16 +00:00
logged_in_api_client, factories, preferences
):
actor = logged_in_api_client.user.create_actor()
2018-06-09 13:36:16 +00:00
preferences["common__api_authentication_required"] = True
upload = factories["music.Upload"](library__actor=actor, import_status="finished")
2018-09-22 12:29:30 +00:00
assert upload.audio_file is not None
url = upload.track.listen_url
response = logged_in_api_client.get(url)
assert response.status_code == 200
2018-09-22 12:29:30 +00:00
assert response["X-Accel-Redirect"] == "/_protected{}".format(upload.audio_file.url)