浏览代码

add ansible_playbook neuron unit tests

nico 8 年之前
父节点
当前提交
4b48b51eb4

+ 19 - 4
kalliope/neurons/ansible_playbook/tests/test_ansible_playbook.py

@@ -1,14 +1,15 @@
+import os
 import unittest
-
+from kalliope.neurons.ansible_playbook import Ansible_playbook
 from kalliope.core.NeuronModule import MissingParameterException
-from kalliope.neurons.ansible_playbook.ansible_playbook import Ansible_playbook
 
 
 class TestAnsible_Playbook(unittest.TestCase):
 
     def setUp(self):
-        self.task_file="task_file"
+        self.task_file = "task_file"
         self.random = "random"
+        self.test_file = "/tmp/kalliope_text_ansible_playbook.txt"
 
     def testParameters(self):
         def run_test(parameters_to_test):
@@ -25,7 +26,21 @@ class TestAnsible_Playbook(unittest.TestCase):
         }
         run_test(parameters)
 
+    def test_create_file_via_ansible_playbook(self):
+        """
+        This test will use an ansible playbook the create a file. We check that the file has been created
+        """
+        param = {
+            "task_file": "./test_ansible_playbook_neuron.yml"
+        }
+
+        Ansible_playbook(**param)
+
+        self.assertTrue(os.path.isfile(self.test_file))
+
+        if os.path.exists(self.test_file):
+            os.remove(self.test_file)
+
 
 if __name__ == '__main__':
     unittest.main()
-

+ 11 - 0
kalliope/neurons/ansible_playbook/tests/test_ansible_playbook_neuron.yml

@@ -0,0 +1,11 @@
+---
+  - name: Playbook
+    hosts: localhost
+    gather_facts: no
+    connection: local
+
+    tasks:
+      - name: "create a local file"
+        file:
+          path: "/tmp/kalliope_text_ansible_playbook.txt"
+          state: "touch"