'Testing whether a playlist is correctly removed'

@deferred(timeout=10)
def test_delete_playlist(self):

    mock_channel_community = MockObject()
    mock_channel_community.called_remove = False
    mock_channel_community.called_remove_torrents = False
    my_channel_id = self.create_fake_channel('channel', '')
    def verify_playlist_removed(_):
        self.assertTrue(mock_channel_community.called_remove_torrents)
        self.assertTrue(mock_channel_community.called_remove)
    def remove_playlist_called(playlists):
        self.assertEqual(playlists, [1234])
        mock_channel_community.called_remove = True
    def remove_torrents_called(playlist_id, torrents):
        self.assertEqual(playlist_id, 1234)
        self.assertEqual(torrents, [42])
        mock_channel_community.called_remove_torrents = True
    mock_channel_community.remove_playlists = remove_playlist_called
    mock_channel_community.remove_playlist_torrents = remove_torrents_called
    mock_dispersy = MockObject()
    mock_dispersy.get_community = (lambda _: mock_channel_community)
    self.session.get_dispersy_instance = (lambda : mock_dispersy)
    self.create_playlist(my_channel_id, 1234, 42, 'test    playlist', 'test    description')
    torrent_list = [[my_channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000000, 'ubuntu-torrent.iso', [['file1.txt', 42]], []]]
    self.insert_torrents_into_channel(torrent_list)
    self.insert_torrent_into_playlist(1234, ('a' * 40).decode('hex'))
    return self.do_request(('channels/discovered/%s/playlists/1' % 'fakedispersyid'.encode('hex')), expected_code=200, expected_json={'removed': True}, request_type='DELETE').addCallback(verify_playlist_removed)
