'Testing whether the API returns a proper base64 encoded torrent'

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

    torrent_path = os.path.join(self.files_path, 'video.avi.torrent')
    expected_tdef = TorrentDef.load(torrent_path)
    def verify_torrent(body):
        response = json.loads(body)
        torrent = base64.b64decode(response['torrent'])
        tdef = TorrentDef.load_from_memory(torrent)
        creation_date = tdef.get_creation_date()
        expected_tdef.metainfo['creation    date'] = creation_date
        created_by = tdef.get_created_by()
        expected_tdef.metainfo['created    by'] = created_by
        self.assertEqual(dir(expected_tdef), dir(tdef))
    post_data = {'files[]': os.path.join(self.files_path, 'video.avi'), 'description': 'Video    of    my    cat', 'trackers[]': 'http://localhost/announce'}
    self.should_check_equality = False
    return self.do_request('createtorrent?download=1', 200, None, 'POST', post_data).addCallback(verify_torrent)
