# Path: gepify/providers/songs.py
# def get_song(song_name):
# def add_song_file(song_name, file, format):
# def has_song_format(song_name, format):
# def download_song(self, song_info, provider='youtube', format='mp3'):
# 
# Path: gepify/providers/playlists.py
# def get_playlist(service, playlist, format):
# def has_playlist(service, playlist, format):
# def checksum(tracks):
# def handle_error(playlist_cache_key):
# def create_zip_playlist(playlist, service, checksum, format='mp3'):
# def download_playlist(playlist, service, provider='youtube', format='mp3'):
# def clean_playlists():
# 
# Path: gepify/providers/youtube.py
# DEVELOPER_KEY = os.environ.get('YOUTUBE_DEVELOPER_KEY')
# YOUTUBE_API_SERVICE_NAME = 'youtube'
# YOUTUBE_API_VERSION = 'v3'
# def get_song_id(song_name):
# def download_song(id, format):
# 
# Path: gepify/providers/soundcloud.py
# SOUNDCLOUD_CLIENT_ID = os.environ.get('SOUNDCLOUD_CLIENT_ID')
# def get_song_id(song_name):
# def download_song(id, format):


from unittest import mock, TestCase
from gepify.providers import songs, playlists, youtube, soundcloud
from werkzeug.contrib.cache import SimpleCache
import json
import time
import os
        #     'Song is aleady downloading. Will retry in 5 seconds.')
        # self.assertTrue(retry.called)

    def test_download_song_with_unsupported_provider(self):
        with self.assertRaisesRegex(ValueError, 'Provider not found: zamunda'):
            songs.download_song({'name': 'song'}, provider='zamunda')
        song = songs.get_song('song')
        self.assertNotIn('mp3', song['files'])

    @mock.patch('gepify.providers.youtube.get_song_id',
                side_effect=lambda name: 'dQw4w9WgXcQ')
    @mock.patch('gepify.providers.youtube.download_song')
    def test_download_song_with_youtube(self, download_song, *args):
        songs.download_song({'name': 'song'})
        download_song.assert_called_with('dQw4w9WgXcQ', 'mp3')
        song = songs.get_song('song')
        self.assertEqual(song['files']['mp3'], './songs/dQw4w9WgXcQ.mp3')

    @mock.patch('gepify.providers.soundcloud.get_song_id',
                side_effect=lambda name: (1234, 'song id'))
    @mock.patch('gepify.providers.soundcloud.download_song')
    def test_download_song_with_soundcloud(self, download_song, *args):
        songs.download_song({'name': 'song'}, provider='soundcloud')
        download_song.assert_called_with('song id', 'mp3')
        song = songs.get_song('song')
        self.assertEqual(song['files']['mp3'], './songs/1234.mp3')


class PlaylistsTestCase(TestCase):
    def setUp(self):

# Path: gepify/providers/songs.py
# def get_song(song_name):
# def add_song_file(song_name, file, format):
# def has_song_format(song_name, format):
# def download_song(self, song_info, provider='youtube', format='mp3'):
# 
# Path: gepify/providers/playlists.py
# def get_playlist(service, playlist, format):
# def has_playlist(service, playlist, format):
# def checksum(tracks):
# def handle_error(playlist_cache_key):
# def create_zip_playlist(playlist, service, checksum, format='mp3'):
# def download_playlist(playlist, service, provider='youtube', format='mp3'):
# def clean_playlists():
# 
# Path: gepify/providers/youtube.py
# DEVELOPER_KEY = os.environ.get('YOUTUBE_DEVELOPER_KEY')
# YOUTUBE_API_SERVICE_NAME = 'youtube'
# YOUTUBE_API_VERSION = 'v3'
# def get_song_id(song_name):
# def download_song(id, format):
# 
# Path: gepify/providers/soundcloud.py
# SOUNDCLOUD_CLIENT_ID = os.environ.get('SOUNDCLOUD_CLIENT_ID')
# def get_song_id(song_name):
# def download_song(id, format):


# Path: tests/test_providers.py
from unittest import mock, TestCase
from gepify.providers import songs, playlists, youtube, soundcloud
from werkzeug.contrib.cache import SimpleCache
import json
import time
import os

        #     'Song is aleady downloading. Will retry in 5 seconds.')
        # self.assertTrue(retry.called)

    def test_download_song_with_unsupported_provider(self):
        with self.assertRaisesRegex(ValueError, 'Provider not found: zamunda'):
            songs.download_song({'name': 'song'}, provider='zamunda')
        song = songs.get_song('song')
        self.assertNotIn('mp3', song['files'])

    @mock.patch('gepify.providers.youtube.get_song_id',
                side_effect=lambda name: 'dQw4w9WgXcQ')
    @mock.patch('gepify.providers.youtube.download_song')
    def test_download_song_with_youtube(self, download_song, *args):
        songs.download_song({'name': 'song'})
        download_song.assert_called_with('dQw4w9WgXcQ', 'mp3')
        song = songs.get_song('song')
        self.assertEqual(song['files']['mp3'], './songs/dQw4w9WgXcQ.mp3')

    @mock.patch('gepify.providers.soundcloud.get_song_id',
                side_effect=lambda name: (1234, 'song id'))
    @mock.patch('gepify.providers.soundcloud.download_song')
    def test_download_song_with_soundcloud(self, download_song, *args):
        songs.download_song({'name': 'song'}, provider='soundcloud')
        download_song.assert_called_with('song id', 'mp3')
        song = songs.get_song('song')
        self.assertEqual(song['files']['mp3'], './songs/1234.mp3')


class PlaylistsTestCase(TestCase):
    def setUp(self):

        playlists.cache = SimpleCache()