# 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
    @mock.patch('logging.Logger')
    @mock.patch('os.remove')
    def test_clean_playlists(self, os_remove, *args):
        playlists.clean_playlists()
        self.assertEqual(os_remove.call_count, 1)
        os_remove.assert_called_with('./playlists/1.zip')

    @mock.patch('logging.Logger')
    def test_handle_error(self, *args):
        playlists.cache.set('new_playlist', {'checksum': '1234'})
        playlists.handle_error(playlist_cache_key='new_playlist')
        self.assertIsNone(playlists.cache.get('new_playlist'))

    def test_download_playlist_in_unsupported_format(self):
        with self.assertRaisesRegex(ValueError, 'Format not supported: wav'):
            playlists.download_playlist(
                {'id': '1234'}, 'spotify', format='wav')

    @mock.patch('logging.Logger.info')
    def test_download_playlist_if_playlist_is_downloading(self, log_info):
        playlist = {'id': '1234', 'tracks': [{'name': 'some track'}]}
        playlists.cache.set('spotify_1234_mp3', 'downloading')
        playlists.download_playlist(playlist, 'spotify')
        log_info.assert_called_once_with(
            'Attempt to download a playlist in the process of downloading')

    @mock.patch('logging.Logger.info')
    def test_download_playlist_if_playlist_is_downloaded(self, log_info):
        playlist = {'id': '1234', 'tracks': [{'name': 'some track'}]}
        playlist_data = {'checksum': playlists.checksum(playlist['tracks'])}

# 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

    @mock.patch('logging.Logger')
    @mock.patch('os.remove')
    def test_clean_playlists(self, os_remove, *args):
        playlists.clean_playlists()
        self.assertEqual(os_remove.call_count, 1)
        os_remove.assert_called_with('./playlists/1.zip')

    @mock.patch('logging.Logger')
    def test_handle_error(self, *args):
        playlists.cache.set('new_playlist', {'checksum': '1234'})
        playlists.handle_error(playlist_cache_key='new_playlist')
        self.assertIsNone(playlists.cache.get('new_playlist'))

    def test_download_playlist_in_unsupported_format(self):
        with self.assertRaisesRegex(ValueError, 'Format not supported: wav'):
            playlists.download_playlist(
                {'id': '1234'}, 'spotify', format='wav')

    @mock.patch('logging.Logger.info')
    def test_download_playlist_if_playlist_is_downloading(self, log_info):
        playlist = {'id': '1234', 'tracks': [{'name': 'some track'}]}
        playlists.cache.set('spotify_1234_mp3', 'downloading')
        playlists.download_playlist(playlist, 'spotify')
        log_info.assert_called_once_with(
            'Attempt to download a playlist in the process of downloading')

    @mock.patch('logging.Logger.info')
    def test_download_playlist_if_playlist_is_downloaded(self, log_info):
        playlist = {'id': '1234', 'tracks': [{'name': 'some track'}]}
        playlist_data = {'checksum': playlists.checksum(playlist['tracks'])}

        playlists.cache.set('spotify_1234_mp3', playlist_data)