I want to check the value "train-again-v1-16k"
appears in any of the "model_name"
.
I am able to get the response, then I want to make sure the list contains value by using Dictionary Should Contain Value
.
Test case failed:
AttributeError: 'list' object has no attribute 'values'
Please advise what is the correct syntax to check the value in a list.
*** Settings ***
Library Browser
Library String
Library RequestsLibrary
Library Collections
Library RPA.JSON
*** Test Cases ***
001-Models-Deploy
Create Session mysession ${SRS-API-Host}
${response}= GET ${SRS-API-Host}/models_list
${models}= Get values from JSON ${response.json()} $..model_name
Log To Console models is${models}
Dictionary Should Contain Value ${models} 'train-again-v1-16k'
GET Response:
{
"message": "",
"status": "ok",
"valid_model_list": [
{
"corpus_list": [
"test1"
],
"display_name": "16000samplerate-60train-40test-v1-16k",
"language": "NO INFO",
"lexicon": "001_Lex_one_using_001_wav_stm_only",
"model_name": "16000samplerate-60train-40test-v1-16k",
"status": true,
"train_duration": "1.0 Hrs"
},
{
"corpus_list": [
"Corpus3397"
],
"display_name": "train-again-v1-16k",
"language": "NO INFO",
"lexicon": "NTU",
"model_name": "train-again-v1-16k",
"status": true,
"train_duration": "1.33 Hrs"
}
]
}
CodePudding user response:
*** Settings ***
Library Browser
Library String
Library RequestsLibrary
Library Collections
Library RPA.JSON
Resource ../Resources/BrowserFunctions.robot
Suite Setup Start New Browser
Suite Teardown Close Browser
*** Test Cases ***
001-Models-Deploy
#Verify model appear at SRS API Model List
Create Session mysession ${SRS-API-Host}
${response}= GET ${SRS-API-Host}/models_list
${models}= Get values from JSON ${response.json()} $..model_name
Log To Console models is${models}
Should Contain ${models} sourcemodel8k8020-v1-8k
CodePudding user response:
Get values from JSON
returns a list with all matching values, while Dictionary Should Contain Value
works with and expects, well, a dictionary object.
Just change the keyword for asserting a value is present with something that works with lists - List Should Contain Value
, or just Should Contain
:
List Should Contain Value ${models} train-again-v1-16k