Merge branch 'failing-tests' into 'develop'
Fixed a bunch of failing tests See merge request funkwhale/funkwhale!114
This commit is contained in:
commit
471d1fe9d7
|
@ -328,7 +328,7 @@ class SubmitViewSet(viewsets.ViewSet):
|
|||
job = models.ImportJob.objects.create(mbid=request.POST['mbid'], batch=batch, source=request.POST['import_url'])
|
||||
tasks.import_job_run.delay(import_job_id=job.pk)
|
||||
serializer = serializers.ImportBatchSerializer(batch)
|
||||
return Response(serializer.data)
|
||||
return Response(serializer.data, status=201)
|
||||
|
||||
def get_import_request(self, data):
|
||||
try:
|
||||
|
|
|
@ -13,7 +13,8 @@ DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||
|
||||
|
||||
def test_can_submit_youtube_url_for_track_import(
|
||||
artists, albums, tracks, mocker, superuser_client):
|
||||
settings, artists, albums, tracks, mocker, superuser_client):
|
||||
mocker.patch('funkwhale_api.music.tasks.import_job_run.delay')
|
||||
mocker.patch(
|
||||
'funkwhale_api.musicbrainz.api.artists.get',
|
||||
return_value=artists['get']['adhesive_wombat'])
|
||||
|
@ -29,13 +30,18 @@ def test_can_submit_youtube_url_for_track_import(
|
|||
mbid = '9968a9d6-8d92-4051-8f76-674e157b6eed'
|
||||
video_id = 'tPEE9ZwTmy0'
|
||||
url = reverse('api:v1:submit-single')
|
||||
video_url = 'https://www.youtube.com/watch?v={0}'.format(video_id)
|
||||
response = superuser_client.post(
|
||||
url,
|
||||
{'import_url': 'https://www.youtube.com/watch?v={0}'.format(video_id),
|
||||
{'import_url': video_url,
|
||||
'mbid': mbid})
|
||||
track = models.Track.objects.get(mbid=mbid)
|
||||
assert track.artist.name == 'Adhesive Wombat'
|
||||
assert track.album.title == 'Marsupial Madness'
|
||||
|
||||
assert response.status_code == 201
|
||||
batch = superuser_client.user.imports.latest('id')
|
||||
job = batch.jobs.latest('id')
|
||||
assert job.status == 'pending'
|
||||
assert str(job.mbid) == mbid
|
||||
assert job.source == video_url
|
||||
|
||||
|
||||
def test_import_creates_an_import_with_correct_data(mocker, superuser_client):
|
||||
|
|
|
@ -106,7 +106,9 @@ def test_deleting_plt_updates_indexes(
|
|||
|
||||
|
||||
@pytest.mark.parametrize('level', ['instance', 'me', 'followers'])
|
||||
def test_playlist_privacy_respected_in_list_anon(level, factories, api_client):
|
||||
def test_playlist_privacy_respected_in_list_anon(
|
||||
settings, level, factories, api_client):
|
||||
settings.API_AUTHENTICATION_REQUIRED = False
|
||||
factories['playlists.Playlist'](privacy_level=level)
|
||||
url = reverse('api:v1:playlists-list')
|
||||
response = api_client.get(url)
|
||||
|
@ -115,26 +117,28 @@ def test_playlist_privacy_respected_in_list_anon(level, factories, api_client):
|
|||
|
||||
|
||||
@pytest.mark.parametrize('method', ['PUT', 'PATCH', 'DELETE'])
|
||||
def test_only_owner_can_edit_playlist(method, factories, api_client):
|
||||
def test_only_owner_can_edit_playlist(method, factories, logged_in_api_client):
|
||||
playlist = factories['playlists.Playlist']()
|
||||
url = reverse('api:v1:playlists-detail', kwargs={'pk': playlist.pk})
|
||||
response = api_client.get(url)
|
||||
response = getattr(logged_in_api_client, method.lower())(url)
|
||||
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.parametrize('method', ['PUT', 'PATCH', 'DELETE'])
|
||||
def test_only_owner_can_edit_playlist_track(method, factories, api_client):
|
||||
def test_only_owner_can_edit_playlist_track(
|
||||
method, factories, logged_in_api_client):
|
||||
plt = factories['playlists.PlaylistTrack']()
|
||||
url = reverse('api:v1:playlist-tracks-detail', kwargs={'pk': plt.pk})
|
||||
response = api_client.get(url)
|
||||
response = getattr(logged_in_api_client, method.lower())(url)
|
||||
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.parametrize('level', ['instance', 'me', 'followers'])
|
||||
def test_playlist_track_privacy_respected_in_list_anon(
|
||||
level, factories, api_client):
|
||||
level, factories, api_client, settings):
|
||||
settings.API_AUTHENTICATION_REQUIRED = False
|
||||
factories['playlists.PlaylistTrack'](playlist__privacy_level=level)
|
||||
url = reverse('api:v1:playlist-tracks-list')
|
||||
response = api_client.get(url)
|
||||
|
|
|
@ -151,14 +151,18 @@ def test_can_start_radio_for_logged_in_user(logged_in_client):
|
|||
assert session.user == logged_in_client.user
|
||||
|
||||
|
||||
def test_can_start_radio_for_anonymous_user(client, db):
|
||||
def test_can_start_radio_for_anonymous_user(api_client, db, settings):
|
||||
settings.API_AUTHENTICATION_REQUIRED = False
|
||||
url = reverse('api:v1:radios:sessions-list')
|
||||
response = client.post(url, {'radio_type': 'random'})
|
||||
response = api_client.post(url, {'radio_type': 'random'})
|
||||
|
||||
assert response.status_code == 201
|
||||
|
||||
session = models.RadioSession.objects.latest('id')
|
||||
|
||||
assert session.radio_type == 'random'
|
||||
assert session.user is None
|
||||
assert session.session_key == client.session.session_key
|
||||
assert session.session_key == api_client.session.session_key
|
||||
|
||||
|
||||
def test_can_get_track_for_session_from_api(factories, logged_in_client):
|
||||
|
@ -228,13 +232,18 @@ def test_can_start_tag_radio(factories):
|
|||
assert radio.pick() in good_tracks
|
||||
|
||||
|
||||
def test_can_start_artist_radio_from_api(client, factories):
|
||||
def test_can_start_artist_radio_from_api(api_client, settings, factories):
|
||||
settings.API_AUTHENTICATION_REQUIRED = False
|
||||
artist = factories['music.Artist']()
|
||||
url = reverse('api:v1:radios:sessions-list')
|
||||
|
||||
response = client.post(
|
||||
response = api_client.post(
|
||||
url, {'radio_type': 'artist', 'related_object_id': artist.id})
|
||||
|
||||
assert response.status_code == 201
|
||||
|
||||
session = models.RadioSession.objects.latest('id')
|
||||
|
||||
assert session.radio_type, 'artist'
|
||||
assert session.related_object, artist
|
||||
|
||||
|
|
|
@ -17,13 +17,15 @@ def test_can_get_search_results_from_youtube(mocker):
|
|||
assert results[0]['full_url'] == 'https://www.youtube.com/watch?v=0HxZn6CzOIo'
|
||||
|
||||
|
||||
def test_can_get_search_results_from_funkwhale(mocker, client, db):
|
||||
def test_can_get_search_results_from_funkwhale(
|
||||
settings, mocker, api_client, db):
|
||||
settings.API_AUTHENTICATION_REQUIRED = False
|
||||
mocker.patch(
|
||||
'funkwhale_api.providers.youtube.client._do_search',
|
||||
return_value=api_data.search['8 bit adventure'])
|
||||
query = '8 bit adventure'
|
||||
url = reverse('api:v1:providers:youtube:search')
|
||||
response = client.get(url, {'query': query})
|
||||
response = api_client.get(url, {'query': query})
|
||||
# we should cast the youtube result to something more generic
|
||||
expected = {
|
||||
"id": "0HxZn6CzOIo",
|
||||
|
@ -37,7 +39,7 @@ def test_can_get_search_results_from_funkwhale(mocker, client, db):
|
|||
"cover": "https://i.ytimg.com/vi/0HxZn6CzOIo/hqdefault.jpg"
|
||||
}
|
||||
|
||||
assert json.loads(response.content.decode('utf-8'))[0] == expected
|
||||
assert response.data[0] == expected
|
||||
|
||||
|
||||
def test_can_send_multiple_queries_at_once(mocker):
|
||||
|
@ -67,7 +69,9 @@ def test_can_send_multiple_queries_at_once(mocker):
|
|||
assert results['2'][0]['full_url'] == 'https://www.youtube.com/watch?v=BorYwGi2SJc'
|
||||
|
||||
|
||||
def test_can_send_multiple_queries_at_once_from_funwkhale(mocker, db, client):
|
||||
def test_can_send_multiple_queries_at_once_from_funwkhale(
|
||||
settings, mocker, db, api_client):
|
||||
settings.API_AUTHENTICATION_REQUIRED = False
|
||||
mocker.patch(
|
||||
'funkwhale_api.providers.youtube.client._do_search',
|
||||
return_value=api_data.search['8 bit adventure'])
|
||||
|
@ -89,7 +93,6 @@ def test_can_send_multiple_queries_at_once_from_funwkhale(mocker, db, client):
|
|||
}
|
||||
|
||||
url = reverse('api:v1:providers:youtube:searchs')
|
||||
response = client.post(
|
||||
url, json.dumps(queries), content_type='application/json')
|
||||
response = api_client.post(url, queries, format='json')
|
||||
|
||||
assert expected == json.loads(response.content.decode('utf-8'))['1'][0]
|
||||
assert expected == response.data['1'][0]
|
||||
|
|
Loading…
Reference in New Issue