test_ansible_playbook.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. import unittest
  3. from kalliope.neurons.ansible_playbook import Ansible_playbook
  4. from kalliope.core.NeuronModule import MissingParameterException
  5. class TestAnsible_Playbook(unittest.TestCase):
  6. def setUp(self):
  7. self.task_file = "task_file"
  8. self.random = "random"
  9. self.test_file = "/tmp/kalliope_text_ansible_playbook.txt"
  10. def testParameters(self):
  11. def run_test(parameters_to_test):
  12. with self.assertRaises(MissingParameterException):
  13. Ansible_playbook(**parameters_to_test)
  14. # empty
  15. parameters = dict()
  16. run_test(parameters)
  17. # missing task_file
  18. parameters = {
  19. "random": self.random
  20. }
  21. run_test(parameters)
  22. def test_create_file_via_ansible_playbook(self):
  23. """
  24. This test will use an ansible playbook the create a file. We check that the file has been created
  25. """
  26. param = {
  27. "task_file": "kalliope/neurons/ansible_playbook/tests/test_ansible_playbook_neuron.yml"
  28. }
  29. Ansible_playbook(**param)
  30. self.assertTrue(os.path.isfile(self.test_file))
  31. if os.path.exists(self.test_file):
  32. os.remove(self.test_file)
  33. if __name__ == '__main__':
  34. unittest.main()