Commit 70634048 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fixed #18: added v1 namespace under API

parent 3c2a6914
Pipeline #93 passed with stage
in 32 seconds
......@@ -14,9 +14,9 @@ router.register(r'import-batches', views.ImportBatchViewSet, 'import-batches')
router.register(r'submit', views.SubmitViewSet, 'submit')
router.register(r'playlists', playlists_views.PlaylistViewSet, 'playlists')
router.register(r'playlist-tracks', playlists_views.PlaylistTrackViewSet, 'playlist-tracks')
urlpatterns = router.urls
v1_patterns = router.urls
urlpatterns += [
v1_patterns += [
url(r'^providers/', include('funkwhale_api.providers.urls', namespace='providers')),
url(r'^favorites/', include('funkwhale_api.favorites.urls', namespace='favorites')),
url(r'^search$', views.Search.as_view(), name='search'),
......@@ -26,3 +26,7 @@ urlpatterns += [
url(r'^token/', jwt_views.obtain_jwt_token),
url(r'^token/refresh/', jwt_views.refresh_jwt_token),
]
urlpatterns = [
url(r'^v1/', include(v1_patterns, namespace='v1'))
]
......@@ -24,7 +24,7 @@ class TestFavorites(TestCase):
def test_user_can_get_his_favorites(self):
favorite = TrackFavorite.add(self.track, self.user)
url = reverse('api:favorites:tracks-list')
url = reverse('api:v1:favorites:tracks-list')
self.client.login(username=self.user.username, password='test')
response = self.client.get(url)
......@@ -41,7 +41,7 @@ class TestFavorites(TestCase):
self.assertEqual(expected, parsed_json['results'])
def test_user_can_add_favorite_via_api(self):
url = reverse('api:favorites:tracks-list')
url = reverse('api:v1:favorites:tracks-list')
self.client.login(username=self.user.username, password='test')
response = self.client.post(url, {'track': self.track.pk})
......@@ -60,7 +60,7 @@ class TestFavorites(TestCase):
def test_user_can_remove_favorite_via_api(self):
favorite = TrackFavorite.add(self.track, self.user)
url = reverse('api:favorites:tracks-detail', kwargs={'pk': favorite.pk})
url = reverse('api:v1:favorites:tracks-detail', kwargs={'pk': favorite.pk})
self.client.login(username=self.user.username, password='test')
response = self.client.delete(url, {'track': self.track.pk})
self.assertEqual(response.status_code, 204)
......@@ -69,7 +69,7 @@ class TestFavorites(TestCase):
def test_user_can_remove_favorite_via_api_using_track_id(self):
favorite = TrackFavorite.add(self.track, self.user)
url = reverse('api:favorites:tracks-remove')
url = reverse('api:v1:favorites:tracks-remove')
self.client.login(username=self.user.username, password='test')
response = self.client.delete(
url, json.dumps({'track': self.track.pk}),
......@@ -83,7 +83,7 @@ class TestFavorites(TestCase):
def test_can_restrict_api_views_to_authenticated_users(self):
urls = [
('api:favorites:tracks-list', 'get'),
('api:v1:favorites:tracks-list', 'get'),
]
for route_name, method in urls:
......@@ -103,7 +103,7 @@ class TestFavorites(TestCase):
def test_can_filter_tracks_by_favorites(self):
favorite = TrackFavorite.add(self.track, self.user)
url = reverse('api:tracks-list')
url = reverse('api:v1:tracks-list')
self.client.login(username=self.user.username, password='test')
response = self.client.get(url, data={'favorites': True})
......
......@@ -23,7 +23,7 @@ class TestHistory(TestCase):
def test_anonymous_user_can_create_listening_via_api(self):
track = mommy.make('music.Track')
url = self.reverse('api:history:listenings-list')
url = self.reverse('api:v1:history:listenings-list')
response = self.client.post(url, {
'track': track.pk,
})
......@@ -38,7 +38,7 @@ class TestHistory(TestCase):
self.client.login(username=self.user.username, password='test')
url = self.reverse('api:history:listenings-list')
url = self.reverse('api:v1:history:listenings-list')
response = self.client.post(url, {
'track': track.pk,
})
......
......@@ -314,7 +314,7 @@ class Track(APIModelMixin):
return work
def get_lyrics_url(self):
return reverse('api:tracks-lyrics', kwargs={'pk': self.pk})
return reverse('api:v1:tracks-lyrics', kwargs={'pk': self.pk})
@property
def full_name(self):
......
......@@ -20,7 +20,7 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
def test_can_submit_youtube_url_for_track_import(self, *mocks):
mbid = '9968a9d6-8d92-4051-8f76-674e157b6eed'
video_id = 'tPEE9ZwTmy0'
url = reverse('api:submit-single')
url = reverse('api:v1:submit-single')
user = User.objects.create_superuser(username='test', email='test@test.com', password='test')
self.client.login(username=user.username, password='test')
response = self.client.post(url, {'import_url': 'https://www.youtube.com/watch?v={0}'.format(video_id), 'mbid': mbid})
......@@ -33,7 +33,7 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
user = User.objects.create_superuser(username='test', email='test@test.com', password='test')
mbid = '9968a9d6-8d92-4051-8f76-674e157b6eed'
video_id = 'tPEE9ZwTmy0'
url = reverse('api:submit-single')
url = reverse('api:v1:submit-single')
self.client.login(username=user.username, password='test')
with self.settings(CELERY_ALWAYS_EAGER=False):
response = self.client.post(url, {'import_url': 'https://www.youtube.com/watch?v={0}'.format(video_id), 'mbid': mbid})
......@@ -69,7 +69,7 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
},
]
}
url = reverse('api:submit-album')
url = reverse('api:v1:submit-album')
self.client.login(username=user.username, password='test')
with self.settings(CELERY_ALWAYS_EAGER=False):
response = self.client.post(url, json.dumps(payload), content_type="application/json")
......@@ -123,7 +123,7 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
}
]
}
url = reverse('api:submit-artist')
url = reverse('api:v1:submit-artist')
self.client.login(username=user.username, password='test')
with self.settings(CELERY_ALWAYS_EAGER=False):
response = self.client.post(url, json.dumps(payload), content_type="application/json")
......@@ -159,7 +159,7 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
batch = models.ImportBatch.objects.create(submitted_by=user1)
job = models.ImportJob.objects.create(batch=batch, mbid=mbid, source=source)
url = reverse('api:import-batches-list')
url = reverse('api:v1:import-batches-list')
self.client.login(username=user2.username, password='test')
response2 = self.client.get(url)
......@@ -175,7 +175,7 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
artist2 = models.Artist.objects.create(name='Test2')
query = 'test1'
expected = '[{0}]'.format(json.dumps(serializers.ArtistSerializerNested(artist1).data))
url = self.reverse('api:artists-search')
url = self.reverse('api:v1:artists-search')
response = self.client.get(url + '?query={0}'.format(query))
self.assertJSONEqual(expected, json.loads(response.content.decode('utf-8')))
......@@ -187,17 +187,17 @@ class TestAPI(TMPDirTestCaseMixin, TestCase):
track2 = models.Track.objects.create(artist=artist2, title="test_track2")
query = 'test track 1'
expected = '[{0}]'.format(json.dumps(serializers.TrackSerializerNested(track1).data))
url = self.reverse('api:tracks-search')
url = self.reverse('api:v1:tracks-search')
response = self.client.get(url + '?query={0}'.format(query))
self.assertJSONEqual(expected, json.loads(response.content.decode('utf-8')))
def test_can_restrict_api_views_to_authenticated_users(self):
urls = [
('api:tags-list', 'get'),
('api:tracks-list', 'get'),
('api:artists-list', 'get'),
('api:albums-list', 'get'),
('api:v1:tags-list', 'get'),
('api:v1:tracks-list', 'get'),
('api:v1:artists-list', 'get'),
('api:v1:albums-list', 'get'),
]
for route_name, method in urls:
......
......@@ -59,7 +59,7 @@ Is it me you're looking for?"""
work=None,
mbid='07ca77cf-f513-4e9c-b190-d7e24bbad448')
url = reverse('api:tracks-lyrics', kwargs={'pk': track.pk})
url = reverse('api:v1:tracks-lyrics', kwargs={'pk': track.pk})
user = User.objects.create_user(
username='test', email='test@test.com', password='test')
self.client.login(username=user.username, password='test')
......
......@@ -13,7 +13,7 @@ class TestAPI(TestCase):
return_value=api_data.recordings['search']['brontide matador'])
def test_can_search_recording_in_musicbrainz_api(self, *mocks):
query = 'brontide matador'
url = reverse('api:providers:musicbrainz:search-recordings')
url = reverse('api:v1:providers:musicbrainz:search-recordings')
expected = api_data.recordings['search']['brontide matador']
response = self.client.get(url, data={'query': query})
......@@ -24,7 +24,7 @@ class TestAPI(TestCase):
return_value=api_data.releases['search']['brontide matador'])
def test_can_search_release_in_musicbrainz_api(self, *mocks):
query = 'brontide matador'
url = reverse('api:providers:musicbrainz:search-releases')
url = reverse('api:v1:providers:musicbrainz:search-releases')
expected = api_data.releases['search']['brontide matador']
response = self.client.get(url, data={'query': query})
......@@ -35,7 +35,7 @@ class TestAPI(TestCase):
return_value=api_data.artists['search']['lost fingers'])
def test_can_search_artists_in_musicbrainz_api(self, *mocks):
query = 'lost fingers'
url = reverse('api:providers:musicbrainz:search-artists')
url = reverse('api:v1:providers:musicbrainz:search-artists')
expected = api_data.artists['search']['lost fingers']
response = self.client.get(url, data={'query': query})
......@@ -46,7 +46,7 @@ class TestAPI(TestCase):
return_value=api_data.artists['get']['lost fingers'])
def test_can_get_artist_in_musicbrainz_api(self, *mocks):
uuid = 'ac16bbc0-aded-4477-a3c3-1d81693d58c9'
url = reverse('api:providers:musicbrainz:artist-detail', kwargs={
url = reverse('api:v1:providers:musicbrainz:artist-detail', kwargs={
'uuid': uuid,
})
response = self.client.get(url)
......@@ -60,7 +60,7 @@ class TestAPI(TestCase):
def test_can_broswe_release_group_using_musicbrainz_api(self, *mocks):
uuid = 'ac16bbc0-aded-4477-a3c3-1d81693d58c9'
url = reverse(
'api:providers:musicbrainz:release-group-browse',
'api:v1:providers:musicbrainz:release-group-browse',
kwargs={
'artist_uuid': uuid,
}
......@@ -76,7 +76,7 @@ class TestAPI(TestCase):
def test_can_broswe_releases_using_musicbrainz_api(self, *mocks):
uuid = 'f04ed607-11b7-3843-957e-503ecdd485d1'
url = reverse(
'api:providers:musicbrainz:release-browse',
'api:v1:providers:musicbrainz:release-browse',
kwargs={
'release_group_uuid': uuid,
}
......
......@@ -38,7 +38,7 @@ class TestPlayLists(TestCase):
def test_can_create_playlist_via_api(self):
self.client.login(username=self.user.username, password='test')
url = reverse('api:playlists-list')
url = reverse('api:v1:playlists-list')
data = {
'name': 'test',
}
......@@ -54,7 +54,7 @@ class TestPlayLists(TestCase):
self.client.login(username=self.user.username, password='test')
url = reverse('api:playlist-tracks-list')
url = reverse('api:v1:playlist-tracks-list')
data = {
'playlist': playlist.pk,
'track': tracks[0].pk
......
......@@ -26,7 +26,7 @@ class TestAPI(TestCase):
def test_can_get_search_results_from_funkwhale(self, *mocks):
query = '8 bit adventure'
expected = json.dumps(client.search(query))
url = self.reverse('api:providers:youtube:search')
url = self.reverse('api:v1:providers:youtube:search')
response = self.client.get(url + '?query={0}'.format(query))
self.assertJSONEqual(expected, json.loads(response.content.decode('utf-8')))
......@@ -67,7 +67,7 @@ class TestAPI(TestCase):
}
expected = json.dumps(client.search_multiple(queries))
url = self.reverse('api:providers:youtube:searchs')
url = self.reverse('api:v1:providers:youtube:searchs')
response = self.client.post(
url, json.dumps(queries), content_type='application/json')
......
......@@ -94,7 +94,7 @@ class TestRadios(TestCase):
self.assertEqual(radio.session, restarted_radio.session)
def test_can_get_start_radio_from_api(self):
url = reverse('api:radios:sessions-list')
url = reverse('api:v1:radios:sessions-list')
response = self.client.post(url, {'radio_type': 'random'})
session = models.RadioSession.objects.latest('id')
self.assertEqual(session.radio_type, 'random')
......@@ -107,7 +107,7 @@ class TestRadios(TestCase):
self.assertEqual(session.user, self.user)
def test_can_start_radio_for_anonymous_user(self):
url = reverse('api:radios:sessions-list')
url = reverse('api:v1:radios:sessions-list')
response = self.client.post(url, {'radio_type': 'random'})
session = models.RadioSession.objects.latest('id')
......@@ -118,11 +118,11 @@ class TestRadios(TestCase):
tracks = mommy.make('music.Track', _quantity=1)
self.client.login(username=self.user.username, password='test')
url = reverse('api:radios:sessions-list')
url = reverse('api:v1:radios:sessions-list')
response = self.client.post(url, {'radio_type': 'random'})
session = models.RadioSession.objects.latest('id')
url = reverse('api:radios:tracks-list')
url = reverse('api:v1:radios:tracks-list')
response = self.client.post(url, {'session': session.pk})
data = json.loads(response.content.decode('utf-8'))
......@@ -173,7 +173,7 @@ class TestRadios(TestCase):
def test_can_start_artist_radio_from_api(self):
artist = mommy.make('music.Artist')
url = reverse('api:radios:sessions-list')
url = reverse('api:v1:radios:sessions-list')
response = self.client.post(url, {'radio_type': 'artist', 'related_object_id': artist.id})
session = models.RadioSession.objects.latest('id')
......
......@@ -42,7 +42,7 @@ class UserTestCase(TestCase):
self.assertEqual(response.status_code, 403)
def test_can_fetch_data_from_api(self):
url = self.reverse('api:users:users-me')
url = self.reverse('api:v1:users:users-me')
response = self.client.get(url)
# login required
self.assertEqual(response.status_code, 401)
......
......@@ -4,7 +4,7 @@ class Config {
if (!this.BACKEND_URL.endsWith('/')) {
this.BACKEND_URL += '/'
}
this.API_URL = this.BACKEND_URL + 'api/'
this.API_URL = this.BACKEND_URL + 'api/v1/'
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment