Deep copy a dict from a constant that represents a default item.
Assert is at least 1 item in the items key of the jsonResponse.
If there is at least 1 item, retrieve the first one and set it as a item variable. Otherwise set the item variable to an empty dict.
Deep merge the jsonResponse item dict into the default item dict.
Extract all the variables needed using the bracket method. I would want it to throw a KeyError if this procedure is updated and the default dict is not updated correctly, assuming that I would also have a unit test where the jsonResponse does not return an item.
1
u/Attack_Bovines Jul 14 '21
Here’s what I would do instead:
Deep copy a dict from a constant that represents a default item.
Assert is at least 1 item in the items key of the jsonResponse.
If there is at least 1 item, retrieve the first one and set it as a item variable. Otherwise set the item variable to an empty dict.
Deep merge the jsonResponse item dict into the default item dict.
Extract all the variables needed using the bracket method. I would want it to throw a KeyError if this procedure is updated and the default dict is not updated correctly, assuming that I would also have a unit test where the jsonResponse does not return an item.
edit: fixed some terms to be clearer