Browse Source

[Tests] Add Script neuron param tests + add pip mock dependency + main in each neuron test

monf 8 năm trước cách đây
mục cha
commit
d573db69e9

+ 1 - 0
install/files/python_requirements.txt

@@ -17,3 +17,4 @@ Flask-Restful==0.3.5
 wikipedia==1.4.0
 requests==2.12.1
 httpretty==0.8.14
+mock==2.0.0

+ 4 - 0
neurons/ansible_playbook/tests/test_ansible_playbook.py

@@ -25,3 +25,7 @@ class TestAnsible_Playbook(unittest.TestCase):
         }
         run_test(parameters)
 
+
+if __name__ == '__main__':
+    unittest.main()
+

+ 4 - 0
neurons/gmail_checker/tests/test_gmail_checker.py

@@ -31,3 +31,7 @@ class TestGmail_Checker(unittest.TestCase):
         }
         run_test(parameters)
 
+
+if __name__ == '__main__':
+    unittest.main()
+

+ 3 - 0
neurons/openweathermap/tests/test_openweathermap.py

@@ -31,3 +31,6 @@ class TestOpenWeatherMap(unittest.TestCase):
         }
         run_test(parameters)
 
+
+if __name__ == '__main__':
+    unittest.main()

+ 3 - 0
neurons/push_message/tests/test_push_message.py

@@ -41,3 +41,6 @@ class TestPush_Message(unittest.TestCase):
         }
         run_test(parameters)
 
+
+if __name__ == '__main__':
+    unittest.main()

+ 0 - 0
neurons/script/tests/__init__.py


+ 57 - 0
neurons/script/tests/test_script.py

@@ -0,0 +1,57 @@
+import unittest
+import os
+
+from core.NeuronModule import MissingParameterException, InvalidParameterException
+from neurons.script.script import Script
+from core.FileManager import FileManager
+
+
+class TestScript(unittest.TestCase):
+
+    def setUp(self):
+        self.path="path"
+        self.random = "random"
+
+    def testParameters(self):
+        def run_test_missing_param(parameters_to_test):
+            with self.assertRaises(MissingParameterException):
+                Script(**parameters_to_test)
+
+        def run_test_invalid_param(parameters_to_test):
+            with self.assertRaises(InvalidParameterException):
+                Script(**parameters_to_test)
+
+        # empty
+        parameters = dict()
+        run_test_missing_param(parameters)
+
+        # missing path
+        parameters = {
+            "random": self.random
+        }
+        run_test_missing_param(parameters)
+
+        # ramdom path
+        self.path="/tmp/iamarandompath/anotherrandompath/kalliope"
+        parameters = {
+            "path": self.path
+        }
+        run_test_invalid_param(parameters)
+
+        # Test Non executable file
+        # Create the file and remove permissions to the user
+        tmp_file_path = "/tmp/kalliope/tests/neuronScript"
+        FileManager.write_in_file(tmp_file_path, "[kalliope-test] TestScript - testParameters")
+        os.chmod(tmp_file_path, 0600)
+        # test the user does not have access
+        self.path = tmp_file_path
+        parameters = {
+            "path": self.path
+        }
+        run_test_invalid_param(parameters)
+        # Remove the tmp file
+        FileManager.remove_file(tmp_file_path)
+
+
+if __name__ == '__main__':
+    unittest.main()