def test_remove_playlist_items_processes_removes_items_in_blocks_of_100_items(
            self):
        mock_api = spotipy.client.Spotify()
        mock_api.playlist = Mock(return_value={'name': 'Playlist Name'})
        mock_api.playlist_remove_specific_occurrences_of_items = Mock()
        pl_id = self.generate_spotify_id()
        cleaner = PlaylistCleaner(self.test_logger, mock_api, 'owner_id', {})
        item_ids = [self.generate_spotify_id() for i in range(0, 230)]
        items = [{
            'uri': 'spotify:track:' + item_ids[index],
            'name': item_ids[index],
            'added_by': 'adder',
            'added_at': 'date added',
            'position': index
        } for index in range(0, len(item_ids))]
        expected_removed = [{
            'uri': item['uri'],
            'positions': [item['position']]
        } for item in items]
        cleaner.remove_playlist_items(pl_id, items)

        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.call_count,
            3)

        self.assertEqual(
            len(mock_api.playlist_remove_specific_occurrences_of_items.
                call_args_list[0][0]), 2)
        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.
            call_args_list[0][0][0], pl_id)
        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.
            call_args_list[0][0][1], expected_removed[0:100])

        self.assertEqual(
            len(mock_api.playlist_remove_specific_occurrences_of_items.
                call_args_list[1][0]), 2)
        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.
            call_args_list[1][0][0], pl_id)
        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.
            call_args_list[1][0][1], expected_removed[100:200])

        self.assertEqual(
            len(mock_api.playlist_remove_specific_occurrences_of_items.
                call_args_list[2][0]), 2)
        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.
            call_args_list[2][0][0], pl_id)
        self.assertEqual(
            mock_api.playlist_remove_specific_occurrences_of_items.
            call_args_list[2][0][1], expected_removed[200:230])
 def test_run_removes_only_unauthorized_items(self):
     mock_api = spotipy.client.Spotify()
     mock_api.playlist = Mock(return_value={'name': 'myplaylist'})
     pl_id = self.generate_spotify_id()
     config = {
         'PROTECT_ALL': False,
         'PROTECTED_PLAYLISTS': [{
             'uri': 'spotify:playlist:' + pl_id
         }]
     }
     cleaner = PlaylistCleaner(self.test_logger, mock_api, 'playlist_owner',
                               config)
     unauth_items = [{
         'name': 'unauth_item_1',
         'uri': self.generate_track_uri()
     }, {
         'name': 'unauth_item_2',
         'uri': self.generate_track_uri()
     }]
     cleaner.find_unauthorized_additions = Mock(return_value=unauth_items)
     cleaner.remove_playlist_items = Mock()
     cleaner.run({'uri': 'spotify:playlist:' + pl_id})
     self.assertEqual(len(cleaner.find_unauthorized_additions.call_args[0]),
                      1)
     cleaner.find_unauthorized_additions.called_once_with(pl_id)