def test_create_small_collection(self): number = 30 files = self.__filter_audio_files(TEST_AUDIO_DIR) presets = ['music', 'lowlevel', 'rhythm'] can_files = [] c = Collection.create_collection('test_coll') for _ in xrange(number): f = File.create_file(choice(files), temporary=False) c.add_file(f) can_files.append(f) successful_searches = 0 while True: try: c.get_similar(choice(can_files), choice(presets), 20) successful_searches += 1 sys.stdout.write('+') sys.stdout.flush() if successful_searches > 100: break except CanorisException, e: # 409 when the collection isn't ready yet # 404 when the file wasn't yet analyzed if e.code == 409 or (e.code == 404 and e.type == "NotReadyYet"): sys.stdout.write(',') sys.stdout.flush() time.sleep(1) else: raise e
def test_upload_retrieve_analysis_frames(self): f = File.create_file(TEST_LOCAL_AUDIO_FILE, os.path.basename(TEST_LOCAL_AUDIO_FILE), True) key = f['key'] self.assertRaises(Exception, f.get_analysis) while True: try: f = File.get_file(key) f.get_analysis() break except CanorisException, e: # check whether the file is indeed still processing assert(e.code == 409) sys.stdout.write(',') sys.stdout.flush() time.sleep(1)
def test_retrieve_file_url(self): '''Cannot retrieve a file uploaded by url.''' f = File.create_file(TEST_URL_AUDIO_FILE, temporary=True) self.assertRaises(KeyError, f.retrieve, '/tmp/') f.delete()
def test_retrieve_file_upload(self): f = File.create_file(TEST_LOCAL_AUDIO_FILE, temporary=True) path, _ = f.retrieve('/tmp/') fp = open(path) fp.close() f.delete()
def test_upload_delete(self): f = File.create_file(TEST_LOCAL_AUDIO_FILE, os.path.basename(TEST_LOCAL_AUDIO_FILE), True) f.delete()
def test_upload_url(self): f = File.create_file(TEST_URL_AUDIO_FILE, temporary=True)