openshift_check_test.py 833 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pytest
  2. from openshift_checks import get_var, OpenShiftCheckException
  3. # Fixtures
  4. @pytest.fixture()
  5. def task_vars():
  6. return dict(foo=42, bar=dict(baz="openshift"))
  7. @pytest.fixture(params=[
  8. ("notfound",),
  9. ("multiple", "keys", "not", "in", "task_vars"),
  10. ])
  11. def missing_keys(request):
  12. return request.param
  13. # Tests
  14. @pytest.mark.parametrize("keys,expected", [
  15. (("foo",), 42),
  16. (("bar", "baz"), "openshift"),
  17. ])
  18. def test_get_var_ok(task_vars, keys, expected):
  19. assert get_var(task_vars, *keys) == expected
  20. def test_get_var_error(task_vars, missing_keys):
  21. with pytest.raises(OpenShiftCheckException):
  22. get_var(task_vars, *missing_keys)
  23. def test_get_var_default(task_vars, missing_keys):
  24. default = object()
  25. assert get_var(task_vars, *missing_keys, default=default) == default