def test_spotify_artists_empty_returns_empty_list(self):
        result = filter_artists_to_unsub({
            'Bob Dylan': 1,
            'Mac Miller': 100
        }, [], 15)

        self.assertEqual(0, len(result))
def main():
    yaml_content = open('../api_secrets.yaml').read()
    client_id, client_secret = secrets_helpers.read_spotify_secrets_from_yaml(
        yaml_content)
    lastfm_username, lastfm_password = secrets_helpers.parse_lastfm_credentials_from_args(
        sys.argv[1:])
    lastfm_api_key, lastfm_api_secret = secrets_helpers.read_lastfm_secrets_from_yaml(
        yaml_content)

    lastfm_client = LastfmClient(lastfm_api_key, lastfm_api_secret,
                                 lastfm_username, lastfm_password)
    spotify_client = SpotifyClient(client_id, client_secret)

    print('Downloading spotify artists...')
    start = time.perf_counter()
    spotify_artists: list[
        SpotifyArtist] = spotify_client.get_user_followed_artists()
    finish = time.perf_counter()
    print(f'Spotify artists downloaded in {finish - start:0.4f} seconds')

    print('Downloading lastfm artists, this may take a while.')
    start = time.perf_counter()
    # Might take a while without setting limit.
    lastfm_artists: dict[str, int] = lastfm_client.get_users_followed_artists()
    finish = time.perf_counter()
    print(f'Lastfm artists downloaded in {finish - start:0.4f} seconds')

    artists_to_unfollow = filter_artists_to_unsub(lastfm_artists,
                                                  spotify_artists,
                                                  CONST_MAXIMUM_PLAYCOUNT)

    print(f'Number of artists to unfollow: {len(artists_to_unfollow)}')
    answer = input('Continue ? (y - yes, any other symbol - no) ').strip()

    if answer == 'y':
        spotify_client.unfollow_spotify_artists(artists_to_unfollow)
    else:
        print('Exiting.')
        sys.exit()
    def test_spotify_artist_not_in_lastfm_returns_artist(self):
        result = filter_artists_to_unsub({}, spotify_artists, 1)

        self.assertEqual(2, len(result))
        self.assertTrue(bob_dylan in result)
        self.assertTrue(mac_miller in result)
    def test_filter_all_cases_positive(self):
        result = filter_artists_to_unsub(lastfm_artists, spotify_artists, 100)

        self.assertEqual(2, len(result))
        self.assertTrue(bob_dylan in result)
        self.assertTrue(mac_miller in result)
    def test_filter_one_positive_case(self):
        result = filter_artists_to_unsub(lastfm_artists, spotify_artists, 15)

        self.assertEqual(1, len(result))
        self.assertTrue(bob_dylan in result)
        self.assertTrue(mac_miller not in result)
 def test_maximum_playcount_zero_raises_value_error(self):
     with self.assertRaises(ValueError) as err:
         filter_artists_to_unsub(lastfm_artists, spotify_artists, 0)
    def test_empty_input_empty_output(self):
        result = filter_artists_to_unsub({}, [], 15)

        self.assertEqual(0, len(result))