mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-06 09:49:55 +02:00
Fixed #54: Now use pytest everywhere \o/
This commit is contained in:
parent
a7758395ee
commit
099cdfa99c
65 changed files with 1466 additions and 1467 deletions
|
@ -1,50 +0,0 @@
|
|||
import os
|
||||
import datetime
|
||||
import unittest
|
||||
from test_plus.test import TestCase
|
||||
|
||||
from funkwhale_api.providers.audiofile import tasks
|
||||
|
||||
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class TestAudioFile(TestCase):
|
||||
def test_can_import_single_audio_file(self, *mocks):
|
||||
metadata = {
|
||||
'artist': ['Test artist'],
|
||||
'album': ['Test album'],
|
||||
'title': ['Test track'],
|
||||
'TRACKNUMBER': ['4'],
|
||||
'date': ['2012-08-15'],
|
||||
'musicbrainz_albumid': ['a766da8b-8336-47aa-a3ee-371cc41ccc75'],
|
||||
'musicbrainz_trackid': ['bd21ac48-46d8-4e78-925f-d9cc2a294656'],
|
||||
'musicbrainz_artistid': ['013c8e5b-d72a-4cd3-8dee-6c64d6125823'],
|
||||
}
|
||||
|
||||
m1 = unittest.mock.patch('mutagen.File', return_value=metadata)
|
||||
m2 = unittest.mock.patch(
|
||||
'funkwhale_api.music.metadata.Metadata.get_file_type',
|
||||
return_value='OggVorbis',
|
||||
)
|
||||
with m1, m2:
|
||||
track_file = tasks.from_path(
|
||||
os.path.join(DATA_DIR, 'dummy_file.ogg'))
|
||||
|
||||
self.assertEqual(
|
||||
track_file.track.title, metadata['title'][0])
|
||||
self.assertEqual(
|
||||
track_file.track.mbid, metadata['musicbrainz_trackid'][0])
|
||||
self.assertEqual(
|
||||
track_file.track.position, 4)
|
||||
self.assertEqual(
|
||||
track_file.track.album.title, metadata['album'][0])
|
||||
self.assertEqual(
|
||||
track_file.track.album.mbid,
|
||||
metadata['musicbrainz_albumid'][0])
|
||||
self.assertEqual(
|
||||
track_file.track.album.release_date, datetime.date(2012, 8, 15))
|
||||
self.assertEqual(
|
||||
track_file.track.artist.name, metadata['artist'][0])
|
||||
self.assertEqual(
|
||||
track_file.track.artist.mbid,
|
||||
metadata['musicbrainz_artistid'][0])
|
|
@ -1,162 +0,0 @@
|
|||
|
||||
|
||||
search = {}
|
||||
|
||||
|
||||
search['8 bit adventure'] = {
|
||||
"pageInfo": {
|
||||
"totalResults": 1000000,
|
||||
"resultsPerPage": 25
|
||||
},
|
||||
"nextPageToken": "CBkQAA",
|
||||
"etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/1L34zetsKWv-raAFiz0MuT0SsfQ\"",
|
||||
"items": [
|
||||
{
|
||||
"id": {
|
||||
"videoId": "0HxZn6CzOIo",
|
||||
"kind": "youtube#video"
|
||||
},
|
||||
"etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/GxK-wHBWUYfrJsd1dijBPTufrVE\"",
|
||||
"snippet": {
|
||||
"liveBroadcastContent": "none",
|
||||
"description": "Make sure to apply adhesive evenly before use. GET IT HERE: http://adhesivewombat.bandcamp.com/album/marsupial-madness Facebook: ...",
|
||||
"channelId": "UCps63j3krzAG4OyXeEyuhFw",
|
||||
"title": "AdhesiveWombat - 8 Bit Adventure",
|
||||
"channelTitle": "AdhesiveWombat",
|
||||
"publishedAt": "2012-08-22T18:41:03.000Z",
|
||||
"thumbnails": {
|
||||
"medium": {
|
||||
"url": "https://i.ytimg.com/vi/0HxZn6CzOIo/mqdefault.jpg",
|
||||
"height": 180,
|
||||
"width": 320
|
||||
},
|
||||
"high": {
|
||||
"url": "https://i.ytimg.com/vi/0HxZn6CzOIo/hqdefault.jpg",
|
||||
"height": 360,
|
||||
"width": 480
|
||||
},
|
||||
"default": {
|
||||
"url": "https://i.ytimg.com/vi/0HxZn6CzOIo/default.jpg",
|
||||
"height": 90,
|
||||
"width": 120
|
||||
}
|
||||
}
|
||||
},
|
||||
"kind": "youtube#searchResult"
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"videoId": "n4A_F5SXmgo",
|
||||
"kind": "youtube#video"
|
||||
},
|
||||
"etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/aRVESw24jlgiErDgJKxNrazKRDc\"",
|
||||
"snippet": {
|
||||
"liveBroadcastContent": "none",
|
||||
"description": "Free Download: http://bit.ly/1fZ1pMJ I don't post 8 bit'ish music much but damn I must admit this is goood! Enjoy \u2665 \u25bbSpikedGrin: ...",
|
||||
"channelId": "UCMOgdURr7d8pOVlc-alkfRg",
|
||||
"title": "\u3010Electro\u3011AdhesiveWombat - 8 Bit Adventure (SpikedGrin Remix) [Free Download]",
|
||||
"channelTitle": "xKito Music",
|
||||
"publishedAt": "2013-10-27T13:16:48.000Z",
|
||||
"thumbnails": {
|
||||
"medium": {
|
||||
"url": "https://i.ytimg.com/vi/n4A_F5SXmgo/mqdefault.jpg",
|
||||
"height": 180,
|
||||
"width": 320
|
||||
},
|
||||
"high": {
|
||||
"url": "https://i.ytimg.com/vi/n4A_F5SXmgo/hqdefault.jpg",
|
||||
"height": 360,
|
||||
"width": 480
|
||||
},
|
||||
"default": {
|
||||
"url": "https://i.ytimg.com/vi/n4A_F5SXmgo/default.jpg",
|
||||
"height": 90,
|
||||
"width": 120
|
||||
}
|
||||
}
|
||||
},
|
||||
"kind": "youtube#searchResult"
|
||||
},
|
||||
],
|
||||
"regionCode": "FR",
|
||||
"kind": "youtube#searchListResponse"
|
||||
}
|
||||
|
||||
search['system of a down toxicity'] = {
|
||||
"items": [
|
||||
{
|
||||
"id": {
|
||||
"kind": "youtube#video",
|
||||
"videoId": "BorYwGi2SJc"
|
||||
},
|
||||
"kind": "youtube#searchResult",
|
||||
"snippet": {
|
||||
"title": "System of a Down: Toxicity",
|
||||
"channelTitle": "Vedres Csaba",
|
||||
"channelId": "UCBXeuQORNwPv4m68fgGMtPQ",
|
||||
"thumbnails": {
|
||||
"default": {
|
||||
"height": 90,
|
||||
"width": 120,
|
||||
"url": "https://i.ytimg.com/vi/BorYwGi2SJc/default.jpg"
|
||||
},
|
||||
"high": {
|
||||
"height": 360,
|
||||
"width": 480,
|
||||
"url": "https://i.ytimg.com/vi/BorYwGi2SJc/hqdefault.jpg"
|
||||
},
|
||||
"medium": {
|
||||
"height": 180,
|
||||
"width": 320,
|
||||
"url": "https://i.ytimg.com/vi/BorYwGi2SJc/mqdefault.jpg"
|
||||
}
|
||||
},
|
||||
"publishedAt": "2007-12-17T12:39:54.000Z",
|
||||
"description": "http://www.vedrescsaba.uw.hu The System of a Down song Toxicity arranged for a classical piano quintet, played by Vedres Csaba and the Kairosz quartet.",
|
||||
"liveBroadcastContent": "none"
|
||||
},
|
||||
"etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/UwR8H6P6kbijNZmBNkYd2jAzDnI\""
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"kind": "youtube#video",
|
||||
"videoId": "ENBv2i88g6Y"
|
||||
},
|
||||
"kind": "youtube#searchResult",
|
||||
"snippet": {
|
||||
"title": "System Of A Down - Question!",
|
||||
"channelTitle": "systemofadownVEVO",
|
||||
"channelId": "UCvtZDkeFxMkRTNqfqXtxxkw",
|
||||
"thumbnails": {
|
||||
"default": {
|
||||
"height": 90,
|
||||
"width": 120,
|
||||
"url": "https://i.ytimg.com/vi/ENBv2i88g6Y/default.jpg"
|
||||
},
|
||||
"high": {
|
||||
"height": 360,
|
||||
"width": 480,
|
||||
"url": "https://i.ytimg.com/vi/ENBv2i88g6Y/hqdefault.jpg"
|
||||
},
|
||||
"medium": {
|
||||
"height": 180,
|
||||
"width": 320,
|
||||
"url": "https://i.ytimg.com/vi/ENBv2i88g6Y/mqdefault.jpg"
|
||||
}
|
||||
},
|
||||
"publishedAt": "2009-10-03T04:49:03.000Z",
|
||||
"description": "System of a Down's official music video for 'Question!'. Click to listen to System of a Down on Spotify: http://smarturl.it/SystemSpotify?IQid=SystemQu As featured ...",
|
||||
"liveBroadcastContent": "none"
|
||||
},
|
||||
"etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/dB-M0N9mB4xE-k4yAF_4d8aU0I4\""
|
||||
},
|
||||
],
|
||||
"etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/yhLQgSpeObNnybd5JqSzlGiJ8Ew\"",
|
||||
"nextPageToken": "CBkQAA",
|
||||
"pageInfo": {
|
||||
"resultsPerPage": 25,
|
||||
"totalResults": 26825
|
||||
},
|
||||
"kind": "youtube#searchListResponse",
|
||||
"regionCode": "FR"
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
import json
|
||||
from collections import OrderedDict
|
||||
import unittest
|
||||
from test_plus.test import TestCase
|
||||
from django.urls import reverse
|
||||
from funkwhale_api.providers.youtube.client import client
|
||||
|
||||
from . import data as api_data
|
||||
|
||||
class TestAPI(TestCase):
|
||||
maxDiff = None
|
||||
@unittest.mock.patch(
|
||||
'funkwhale_api.providers.youtube.client._do_search',
|
||||
return_value=api_data.search['8 bit adventure'])
|
||||
def test_can_get_search_results_from_youtube(self, *mocks):
|
||||
query = '8 bit adventure'
|
||||
|
||||
results = client.search(query)
|
||||
self.assertEqual(results[0]['id']['videoId'], '0HxZn6CzOIo')
|
||||
self.assertEqual(results[0]['snippet']['title'], 'AdhesiveWombat - 8 Bit Adventure')
|
||||
self.assertEqual(results[0]['full_url'], 'https://www.youtube.com/watch?v=0HxZn6CzOIo')
|
||||
|
||||
@unittest.mock.patch(
|
||||
'funkwhale_api.providers.youtube.client._do_search',
|
||||
return_value=api_data.search['8 bit adventure'])
|
||||
def test_can_get_search_results_from_funkwhale(self, *mocks):
|
||||
query = '8 bit adventure'
|
||||
url = self.reverse('api:v1:providers:youtube:search')
|
||||
response = self.client.get(url + '?query={0}'.format(query))
|
||||
# we should cast the youtube result to something more generic
|
||||
expected = {
|
||||
"id": "0HxZn6CzOIo",
|
||||
"url": "https://www.youtube.com/watch?v=0HxZn6CzOIo",
|
||||
"type": "youtube#video",
|
||||
"description": "Make sure to apply adhesive evenly before use. GET IT HERE: http://adhesivewombat.bandcamp.com/album/marsupial-madness Facebook: ...",
|
||||
"channelId": "UCps63j3krzAG4OyXeEyuhFw",
|
||||
"title": "AdhesiveWombat - 8 Bit Adventure",
|
||||
"channelTitle": "AdhesiveWombat",
|
||||
"publishedAt": "2012-08-22T18:41:03.000Z",
|
||||
"cover": "https://i.ytimg.com/vi/0HxZn6CzOIo/hqdefault.jpg"
|
||||
}
|
||||
|
||||
self.assertEqual(
|
||||
json.loads(response.content.decode('utf-8'))[0], expected)
|
||||
|
||||
@unittest.mock.patch(
|
||||
'funkwhale_api.providers.youtube.client._do_search',
|
||||
side_effect=[
|
||||
api_data.search['8 bit adventure'],
|
||||
api_data.search['system of a down toxicity'],
|
||||
]
|
||||
)
|
||||
def test_can_send_multiple_queries_at_once(self, *mocks):
|
||||
queries = OrderedDict()
|
||||
queries['1'] = {
|
||||
'q': '8 bit adventure',
|
||||
}
|
||||
queries['2'] = {
|
||||
'q': 'system of a down toxicity',
|
||||
}
|
||||
|
||||
results = client.search_multiple(queries)
|
||||
|
||||
self.assertEqual(results['1'][0]['id']['videoId'], '0HxZn6CzOIo')
|
||||
self.assertEqual(results['1'][0]['snippet']['title'], 'AdhesiveWombat - 8 Bit Adventure')
|
||||
self.assertEqual(results['1'][0]['full_url'], 'https://www.youtube.com/watch?v=0HxZn6CzOIo')
|
||||
self.assertEqual(results['2'][0]['id']['videoId'], 'BorYwGi2SJc')
|
||||
self.assertEqual(results['2'][0]['snippet']['title'], 'System of a Down: Toxicity')
|
||||
self.assertEqual(results['2'][0]['full_url'], 'https://www.youtube.com/watch?v=BorYwGi2SJc')
|
||||
|
||||
@unittest.mock.patch(
|
||||
'funkwhale_api.providers.youtube.client._do_search',
|
||||
return_value=api_data.search['8 bit adventure'],
|
||||
)
|
||||
def test_can_send_multiple_queries_at_once_from_funwkhale(self, *mocks):
|
||||
queries = OrderedDict()
|
||||
queries['1'] = {
|
||||
'q': '8 bit adventure',
|
||||
}
|
||||
|
||||
expected = {
|
||||
"id": "0HxZn6CzOIo",
|
||||
"url": "https://www.youtube.com/watch?v=0HxZn6CzOIo",
|
||||
"type": "youtube#video",
|
||||
"description": "Make sure to apply adhesive evenly before use. GET IT HERE: http://adhesivewombat.bandcamp.com/album/marsupial-madness Facebook: ...",
|
||||
"channelId": "UCps63j3krzAG4OyXeEyuhFw",
|
||||
"title": "AdhesiveWombat - 8 Bit Adventure",
|
||||
"channelTitle": "AdhesiveWombat",
|
||||
"publishedAt": "2012-08-22T18:41:03.000Z",
|
||||
"cover": "https://i.ytimg.com/vi/0HxZn6CzOIo/hqdefault.jpg"
|
||||
}
|
||||
|
||||
url = self.reverse('api:v1:providers:youtube:searchs')
|
||||
response = self.client.post(
|
||||
url, json.dumps(queries), content_type='application/json')
|
||||
|
||||
self.assertEqual(
|
||||
expected,
|
||||
json.loads(response.content.decode('utf-8'))['1'][0])
|
Loading…
Add table
Add a link
Reference in a new issue