'Testing whether a torrent can be added to a channel using the API'

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

    my_channel_id = self.create_fake_channel('channel', '')
    files_path = os.path.join(self.session_base_dir, 'http_torrent_files')
    os.mkdir(files_path)
    shutil.copyfile(TORRENT_UBUNTU_FILE, os.path.join(files_path, 'ubuntu.torrent'))
    file_server_port = get_random_port()
    self.setUpFileServer(file_server_port, files_path)
    def verify_method_invocation(channel_id, torrent_def, extra_info=None, forward=True):
        self.assertEqual(my_channel_id, channel_id)
        self.assertEqual(TorrentDef.load(TORRENT_UBUNTU_FILE), torrent_def)
        self.assertEqual({'description': 'test'}, (extra_info or {}))
        self.assertEqual(True, forward)
    self.session.add_torrent_def_to_channel = verify_method_invocation
    torrent_url = ('http://localhost:%d/ubuntu.torrent' % file_server_port)
    url = ('channels/discovered/%s/torrents/%s' % ('fakedispersyid'.encode('hex'), urllib.quote_plus(torrent_url)))
    return self.do_request(url, expected_code=200, expected_json={'added': torrent_url}, request_type='PUT', post_data={'description': 'test'})
