def test_BTE_audio_conversion(self) -> None: """Can we convert wav to audio and update the metadata""" audio_obj = Audio.objects.get(pk=1) bte_respone_obj = convert_and_clean_audio(audio_obj) self.assertEqual( bte_respone_obj.status_code, 200, msg="Unsuccessful audio conversion", )
def process_audio_file(self, pk) -> None: """Given the key to an audio file, extract its content and add the related meta data to the database. :param self: A Celery task object :param pk: Audio file pk :return: None """ af = Audio.objects.get(pk=pk) bte_audio_response = convert_and_clean_audio(af) bte_audio_response.raise_for_status() audio_obj = bte_audio_response.json() cf = ContentFile(base64.b64decode(audio_obj["audio_b64"])) file_name = f"{trunc(best_case_name(af).lower(), 72)}_cl.mp3" af.file_with_date = af.docket.date_argued af.local_path_mp3.save(file_name, cf, save=False) af.duration = audio_obj["duration"] af.processing_complete = True af.save()