Best Python code snippet using localstack_python
test_transcribe_boto3.py
Source:test_transcribe_boto3.py
...15 "OutputBucketName": "my-output-bucket",16 "Specialty": "PRIMARYCARE",17 "Type": "CONVERSATION",18 }19 resp = client.start_medical_transcription_job(**args)20 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)21 # CREATED22 resp = client.get_medical_transcription_job(MedicalTranscriptionJobName=job_name)23 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)24 transcription_job = resp["MedicalTranscriptionJob"]25 transcription_job["MedicalTranscriptionJobName"].should.equal(26 args["MedicalTranscriptionJobName"]27 )28 transcription_job["TranscriptionJobStatus"].should.equal("QUEUED")29 transcription_job["LanguageCode"].should.equal(args["LanguageCode"])30 transcription_job["Media"].should.equal(args["Media"])31 transcription_job.should.contain("CreationTime")32 transcription_job.doesnt.contain("StartTime")33 transcription_job.doesnt.contain("CompletionTime")34 transcription_job.doesnt.contain("Transcript")35 transcription_job["Settings"]["ChannelIdentification"].should.equal(False)36 transcription_job["Settings"]["ShowAlternatives"].should.equal(False)37 transcription_job["Specialty"].should.equal(args["Specialty"])38 transcription_job["Type"].should.equal(args["Type"])39 # IN_PROGRESS40 resp = client.get_medical_transcription_job(MedicalTranscriptionJobName=job_name)41 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)42 transcription_job = resp["MedicalTranscriptionJob"]43 transcription_job["TranscriptionJobStatus"].should.equal("IN_PROGRESS")44 transcription_job["MediaFormat"].should.equal("wav")45 transcription_job.should.contain("StartTime")46 transcription_job.doesnt.contain("CompletionTime")47 transcription_job.doesnt.contain("Transcript")48 transcription_job["MediaSampleRateHertz"].should.equal(44100)49 # COMPLETED50 resp = client.get_medical_transcription_job(MedicalTranscriptionJobName=job_name)51 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)52 transcription_job = resp["MedicalTranscriptionJob"]53 transcription_job["TranscriptionJobStatus"].should.equal("COMPLETED")54 transcription_job.should.contain("CompletionTime")55 transcription_job["Transcript"].should.equal(56 {57 "TranscriptFileUri": "https://s3.{}.amazonaws.com/{}/medical/{}.json".format(58 region_name,59 args["OutputBucketName"],60 args["MedicalTranscriptionJobName"],61 )62 }63 )64 # Delete65 client.delete_medical_transcription_job(MedicalTranscriptionJobName=job_name)66 client.get_medical_transcription_job.when.called_with(67 MedicalTranscriptionJobName=job_name68 ).should.throw(client.exceptions.BadRequestException)69@mock_transcribe70def test_run_medical_transcription_job_all_params():71 region_name = "us-east-1"72 client = boto3.client("transcribe", region_name=region_name)73 vocabulary_name = "MyMedicalVocabulary"74 resp = client.create_medical_vocabulary(75 VocabularyName=vocabulary_name,76 LanguageCode="en-US",77 VocabularyFileUri="https://s3.us-east-1.amazonaws.com/AWSDOC-EXAMPLE-BUCKET/vocab.txt",78 )79 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)80 job_name = "MyJob2"81 args = {82 "MedicalTranscriptionJobName": job_name,83 "LanguageCode": "en-US",84 "MediaSampleRateHertz": 48000,85 "MediaFormat": "flac",86 "Media": {"MediaFileUri": "s3://my-bucket/my-media-file.dat",},87 "OutputBucketName": "my-output-bucket",88 "OutputEncryptionKMSKeyId": "arn:aws:kms:us-east-1:012345678901:key/37111b5e-8eff-4706-ae3a-d4f9d1d559fc",89 "Settings": {90 "ShowSpeakerLabels": True,91 "MaxSpeakerLabels": 5,92 "ChannelIdentification": True,93 "ShowAlternatives": True,94 "MaxAlternatives": 6,95 "VocabularyName": vocabulary_name,96 },97 "Specialty": "PRIMARYCARE",98 "Type": "CONVERSATION",99 }100 resp = client.start_medical_transcription_job(**args)101 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)102 # CREATED103 resp = client.get_medical_transcription_job(MedicalTranscriptionJobName=job_name)104 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)105 transcription_job = resp["MedicalTranscriptionJob"]106 transcription_job["MedicalTranscriptionJobName"].should.equal(107 args["MedicalTranscriptionJobName"]108 )109 transcription_job["TranscriptionJobStatus"].should.equal("QUEUED")110 transcription_job["LanguageCode"].should.equal(args["LanguageCode"])111 transcription_job["Media"].should.equal(args["Media"])112 transcription_job.should.contain("CreationTime")113 transcription_job.doesnt.contain("StartTime")114 transcription_job.doesnt.contain("CompletionTime")115 transcription_job.doesnt.contain("Transcript")116 transcription_job["Settings"]["ShowSpeakerLabels"].should.equal(117 args["Settings"]["ShowSpeakerLabels"]118 )119 transcription_job["Settings"]["MaxSpeakerLabels"].should.equal(120 args["Settings"]["MaxSpeakerLabels"]121 )122 transcription_job["Settings"]["ChannelIdentification"].should.equal(123 args["Settings"]["ChannelIdentification"]124 )125 transcription_job["Settings"]["ShowAlternatives"].should.equal(126 args["Settings"]["ShowAlternatives"]127 )128 transcription_job["Settings"]["MaxAlternatives"].should.equal(129 args["Settings"]["MaxAlternatives"]130 )131 transcription_job["Settings"]["VocabularyName"].should.equal(132 args["Settings"]["VocabularyName"]133 )134 transcription_job["Specialty"].should.equal(args["Specialty"])135 transcription_job["Type"].should.equal(args["Type"])136 # IN_PROGRESS137 resp = client.get_medical_transcription_job(MedicalTranscriptionJobName=job_name)138 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)139 transcription_job = resp["MedicalTranscriptionJob"]140 transcription_job["TranscriptionJobStatus"].should.equal("IN_PROGRESS")141 transcription_job["MediaFormat"].should.equal("flac")142 transcription_job.should.contain("StartTime")143 transcription_job.doesnt.contain("CompletionTime")144 transcription_job.doesnt.contain("Transcript")145 transcription_job["MediaSampleRateHertz"].should.equal(48000)146 # COMPLETED147 resp = client.get_medical_transcription_job(MedicalTranscriptionJobName=job_name)148 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)149 transcription_job = resp["MedicalTranscriptionJob"]150 transcription_job["TranscriptionJobStatus"].should.equal("COMPLETED")151 transcription_job.should.contain("CompletionTime")152 transcription_job["Transcript"].should.equal(153 {154 "TranscriptFileUri": "https://s3.{}.amazonaws.com/{}/medical/{}.json".format(155 region_name,156 args["OutputBucketName"],157 args["MedicalTranscriptionJobName"],158 )159 }160 )161@mock_transcribe162def test_get_nonexistent_medical_transcription_job():163 region_name = "us-east-1"164 client = boto3.client("transcribe", region_name=region_name)165 client.get_medical_transcription_job.when.called_with(166 MedicalTranscriptionJobName="NonexistentJobName"167 ).should.throw(client.exceptions.BadRequestException)168@mock_transcribe169def test_run_medical_transcription_job_with_existing_job_name():170 region_name = "us-east-1"171 client = boto3.client("transcribe", region_name=region_name)172 job_name = "MyJob"173 args = {174 "MedicalTranscriptionJobName": job_name,175 "LanguageCode": "en-US",176 "Media": {"MediaFileUri": "s3://my-bucket/my-media-file.wav",},177 "OutputBucketName": "my-output-bucket",178 "Specialty": "PRIMARYCARE",179 "Type": "CONVERSATION",180 }181 resp = client.start_medical_transcription_job(**args)182 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)183 client.start_medical_transcription_job.when.called_with(**args).should.throw(184 client.exceptions.ConflictException185 )186@mock_transcribe187def test_run_medical_transcription_job_nonexistent_vocabulary():188 region_name = "us-east-1"189 client = boto3.client("transcribe", region_name=region_name)190 job_name = "MyJob3"191 args = {192 "MedicalTranscriptionJobName": job_name,193 "LanguageCode": "en-US",194 "Media": {"MediaFileUri": "s3://my-bucket/my-media-file.dat",},195 "OutputBucketName": "my-output-bucket",196 "Settings": {"VocabularyName": "NonexistentVocabulary"},197 "Specialty": "PRIMARYCARE",198 "Type": "CONVERSATION",199 }200 client.start_medical_transcription_job.when.called_with(**args).should.throw(201 client.exceptions.BadRequestException202 )203@mock_transcribe204def test_list_medical_transcription_jobs():205 region_name = "us-east-1"206 client = boto3.client("transcribe", region_name=region_name)207 def run_job(index, target_status):208 job_name = "Job_{}".format(index)209 args = {210 "MedicalTranscriptionJobName": job_name,211 "LanguageCode": "en-US",212 "Media": {"MediaFileUri": "s3://my-bucket/my-media-file.wav",},213 "OutputBucketName": "my-output-bucket",214 "Specialty": "PRIMARYCARE",215 "Type": "CONVERSATION",216 }217 resp = client.start_medical_transcription_job(**args)218 resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)219 # IMPLICITLY PROMOTE JOB STATUS TO QUEUED220 resp = client.get_medical_transcription_job(221 MedicalTranscriptionJobName=job_name222 )223 # IN_PROGRESS224 if target_status in ["IN_PROGRESS", "COMPLETED"]:225 resp = client.get_medical_transcription_job(226 MedicalTranscriptionJobName=job_name227 )228 # COMPLETED229 if target_status == "COMPLETED":230 resp = client.get_medical_transcription_job(231 MedicalTranscriptionJobName=job_name...
aws-transcribe.py
Source:aws-transcribe.py
...10 file_name = str(file_obj['s3']['object']['key'])11 s3_uri = "s3://"+bucket_name+"/"+file_name12 job_name = context.aws_request_id13 14 transcribe.start_medical_transcription_job(MedicalTranscriptionJobName=job_name,15 Media = {'MediaFileUri': s3_uri}, MediaFormat = 'wav', LanguageCode = 'en-US',16 OutputBucketName = 'file-aws-comprehend',17 Settings={ 'ShowSpeakerLabels': True, 'MaxSpeakerLabels': 2, 'ChannelIdentification': False},18 Type='DICTATION', Specialty='PRIMARYCARE')19 return {20 'statusCode': 200,21 'body': json.dumps('Transcription job created!')
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!