'Testing whether the API returns the right download when a download is added'

@deferred(timeout=20)
def test_get_downloads(self):

    def verify_download(downloads):
        downloads_json = json.loads(downloads)
        self.assertEqual(len(downloads_json['downloads']), 2)
    (video_tdef, _) = self.create_local_torrent(os.path.join(TESTS_DATA_DIR, 'video.avi'))
    self.session.start_download_from_tdef(video_tdef, DownloadStartupConfig())
    self.session.start_download_from_uri(('file:' + pathname2url(os.path.join(TESTS_DATA_DIR, 'bak_single.torrent'))))
    self.should_check_equality = False
    return self.do_request('downloads?get_peers=1&get_pieces=1', expected_code=200).addCallback(verify_download)
