test_getting_json_values.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. )
  24. def test_none_is_returned_from_nested_objects():
  25. assert (
  26. get_value_from_json(
  27. "val.child.val3",
  28. {
  29. "val2": "nope",
  30. "val": {
  31. "child": {
  32. "val2": "nope",
  33. "val": "ok",
  34. },
  35. },
  36. },
  37. )
  38. is None
  39. )