Exemplo n.º 1
0
 def test_success_create(self):
     config = JsonConfig(self.VALID_CONFIG_PATH)
     traemplists = config.get_traemplist_configs()
     self.assertEqual(traemplists, [
         TraemplistConfig(account=AccountConfig(
             credentials=AccountCredentialsConfig(
                 client_id="valid_id",
                 client_secret="valid_secret",
                 refresh_token="valid_refresh_token"),
             playlists=[
                 PlaylistConfig(id="playlist_a"),
                 PlaylistConfig(id="playlist_b")
             ]),
                          traemplist_songs_count=20,
                          traemplist_id="t_id")
     ])
Exemplo n.º 2
0
 def test_save_and_reload(self):
     config_file_path = self.tmp_dir + "/config.json"
     shutil.copyfile(self.VALID_CONFIG_PATH, config_file_path)
     config = JsonConfig(config_file_path)
     traemplists = config.get_traemplist_configs()
     new_refresh_token = str(uuid4())
     traemplists[0].account.credentials.refresh_token = new_refresh_token
     config.save()
     config = JsonConfig(config_file_path)
     self.assertEqual(
         config.get_traemplist_configs()
         [0].account.credentials.refresh_token, new_refresh_token)
Exemplo n.º 3
0
 def test_invalid_config_data_error(self):
     with self.assertRaises(InvalidConfigDataError):
         JsonConfig(self.INVALID_DATA_CONFIG_PATH)
Exemplo n.º 4
0
 def test_invalid_json_error(self):
     with self.assertRaises(InvalidJsonError):
         JsonConfig(self.INVALID_JSON_CONFIG_PATH)
Exemplo n.º 5
0
 def test_non_existent_file_error(self):
     config_file_path = self.tmp_dir + "/non_existent.json"
     with self.assertRaises(ConfigFileNotFoundError):
         JsonConfig(config_file_path)
Exemplo n.º 6
0
import os
from traemplist.logger import StandardOutputLogger
from traemplist.config import JsonConfig, AccountCredentialsConfig
from traemplist.client import SpotifyClient, SpotifyAccessTokenProvider
from traemplist.repository import SqLiteTracksRepository
from traemplist.service import TracksHistoryService

this_dir_path = os.path.dirname(os.path.abspath(__file__))
logger = StandardOutputLogger()
config = JsonConfig(f"{this_dir_path}/config.json")

for traemplist_config in config.get_traemplist_configs():
    account_credentials = traemplist_config.account.credentials
    spotify_client = SpotifyClient(
        access_token_provider=SpotifyAccessTokenProvider(
            AccountCredentialsConfig(
                client_id=account_credentials.client_id,
                client_secret=account_credentials.client_secret,
                refresh_token=account_credentials.refresh_token)))
    TracksHistoryService(
        client=spotify_client,
        repository=SqLiteTracksRepository(
            f"{this_dir_path}/storage/{account_credentials.client_id}_tracks.db"
        ),
        logger=logger).save_all_user_playlists_tracks()