How to assert deeply in JSON with python -


i trigerring api call, , server response in json format. response looks this:

{ "status": 0,  "not_passed": 1,  "why": [     {         "code": 229,          "reason": "some reason",       } ] } 

i need assert 2 thing. status , reason fro status using:

    r = requests.get_simple(url=server.my_server, params=p) data = json.loads(r.content) assert data["status"] == 0 

but doesn't work 'reason', maybe because 'reason' deeper in nested structure. how can fix one?

assert data['why'][0]['reason'] == 'something' 

of course assumes data['why'] exists, list, , contains dict first element.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -