test_getting_json_values.py 793 B

12345678910111213141516171819202122232425262728293031
  1. from ..client import get_value_from_json
  2. def test_json_value_is_returned():
  3. assert get_value_from_json("val", {"val": "ok", "val2": "nope"}) == "ok"
  4. def test_json_value_is_cast_to_str():
  5. assert get_value_from_json("val", {"val": 21, "val2": "nope"}) == "21"
  6. def test_none_is_returned_if_val_is_not_found():
  7. assert get_value_from_json("val", {"val3": 21, "val2": "nope"}) is None
  8. def test_json_value_is_returned_from_nested_objects():
  9. assert (
  10. get_value_from_json(
  11. "val.child.val",
  12. {
  13. "val2": "nope",
  14. "val": {
  15. "child": {
  16. "val2": "nope",
  17. "val": "ok",
  18. },
  19. },
  20. },
  21. )
  22. == "ok"
  23. )