'Testing whether a torrent can be successfully removed from a playlist'

@deferred(timeout=15)
@inlineCallbacks
def test_remove_torrent_playlist(self):

    mock_channel_community = MockObject()
    mock_channel_community.called_remove = False
    my_channel_id = self.create_fake_channel('channel', '')
    def verify_torrent_removed(_):
        self.assertTrue(mock_channel_community.called_remove)
    def modify_remove_called(playlist_id, torrents):
        self.assertEqual(playlist_id, 1)
        self.assertEqual(torrents, [42])
        mock_channel_community.called_remove = True
    mock_channel_community.remove_playlist_torrents = modify_remove_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')
    (yield self.do_request(('channels/discovered/%s/playlists/1/abcd' % 'fakedispersyid'.encode('hex')), expected_code=404, request_type='DELETE'))
    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'))
    (yield self.do_request(('channels/discovered/%s/playlists/1/%s' % ('fakedispersyid'.encode('hex'), ('a' * 40))), expected_code=200, request_type='DELETE', expected_json={'removed': True}).addCallback(verify_torrent_removed))
