1
0

test_json.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function
  3. import os
  4. import shutil
  5. import tempfile
  6. def test_local_json(pepper_cli, session_minion_id):
  7. json = '[{"tgt": "*", "fun": "test.ping", "client": "local"}]'
  8. ret = pepper_cli('--json', json)
  9. assert ret[session_minion_id] is True
  10. def test_local_json_bad(pepper_cli):
  11. json = '{what}'
  12. ret = pepper_cli('--json', json)
  13. assert ret == 1
  14. def test_local_json_file(pepper_cli, session_minion_id):
  15. tmpjson = os.path.join(tempfile.mkdtemp(), 'json')
  16. with open(tmpjson, 'w') as tmpfile:
  17. print(
  18. '[{"client": "local", "tgt": "*", "fun": "test.ping"}]',
  19. file=tmpfile,
  20. )
  21. ret = pepper_cli('--json-file', tmpjson)
  22. shutil.rmtree(os.path.dirname(tmpjson))
  23. assert ret[session_minion_id] is True
  24. def test_local_json_file_bad(pepper_cli):
  25. tmpjson = os.path.join(tempfile.mkdtemp(), 'json')
  26. with open(tmpjson, 'w') as tmpfile:
  27. print(
  28. '{what}',
  29. file=tmpfile,
  30. )
  31. ret = pepper_cli('--json-file', tmpjson)
  32. shutil.rmtree(os.path.dirname(tmpjson))
  33. assert ret == 1
  34. def test_local_json_no_file(pepper_cli):
  35. ret = pepper_cli('--json-file', '/tmp/wahteverfile')
  36. assert ret == 1