Browse Source

[Tests] #135 add Neurotransmitter tests for params

monf 8 years ago
parent
commit
e189ff92d7

+ 5 - 5
kalliope/neurons/neurotransmitter/neurotransmitter.py

@@ -1,6 +1,6 @@
 import logging
 
-from kalliope.core.NeuronModule import NeuronModule, InvalidParameterException
+from kalliope.core.NeuronModule import NeuronModule, MissingParameterException, InvalidParameterException
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
@@ -49,7 +49,7 @@ class Neurotransmitter(NeuronModule):
         Check if received links are ok to perform operations
         :return: true if the neuron is well configured, raise an exception otherwise
 
-        .. raises:: MissingParameterException
+        .. raises:: MissingParameterException, InvalidParameterException
         """
         # with the neuron the user has the choice of a direct link that call another synapse,
         #  or a link with an answer caught from the STT engine
@@ -59,15 +59,15 @@ class Neurotransmitter(NeuronModule):
             raise InvalidParameterException("neurotransmitter cannot be used with both direct_link and from_answer_link")
 
         if self.direct_link is None and self.from_answer_link is None:
-            raise InvalidParameterException("neurotransmitter must be used with direct_link or from_answer_link")
+            raise MissingParameterException("neurotransmitter must be used with direct_link or from_answer_link")
 
         if self.from_answer_link is not None:
             if self.default is None:
                 raise InvalidParameterException("default parameter is required and must contain a valid synapse name")
             for el in self.from_answer_link:
                 if "synapse" not in el:
-                    raise InvalidParameterException("Links must contain a synapse name: %s" % el)
+                    raise MissingParameterException("Links must contain a synapse name: %s" % el)
                 if "answers" not in el:
-                    raise InvalidParameterException("Links must contain answers: %s" % el)
+                    raise MissingParameterException("Links must contain answers: %s" % el)
 
         return True

+ 86 - 0
kalliope/neurons/neurotransmitter/tests/test_neurotransmitter.py

@@ -0,0 +1,86 @@
+import unittest
+
+from kalliope.core.NeuronModule import MissingParameterException, InvalidParameterException
+from kalliope.neurons.neurotransmitter import Neurotransmitter
+
+
+class TestNeurotransmitter(unittest.TestCase):
+
+    def setUp(self):
+        self.from_answer_link = [
+            {
+                "synapse": "synapse2",
+                "answer": "blabla"
+            },
+            {
+                "synapse": "synapse3",
+                "answer": "blablablbla",
+                "answer": "blablblobloa",
+            },
+        ]
+        self.direct_link = "direct_link"
+        self.default = "default"
+
+    def testParameters(self):
+        def run_test_InvalidParameterException(parameters_to_test):
+            with self.assertRaises(InvalidParameterException):
+                Neurotransmitter(**parameters_to_test)
+
+        def run_test_MissingParameterException(parameters_to_test):
+            with self.assertRaises(MissingParameterException):
+                Neurotransmitter(**parameters_to_test)
+
+        # empty
+        parameters = dict()
+        run_test_MissingParameterException(parameters)
+
+        # missing direct_link and from_answer_link
+        parameters = {
+            "default": self.default
+        }
+        run_test_MissingParameterException(parameters)
+
+        # missing direct_link and from_answer_link
+        parameters = {
+            "default": self.default,
+            "from_answer_link": self.from_answer_link,
+            "direct_link": self.direct_link
+        }
+        run_test_InvalidParameterException(parameters)
+
+        # missing default
+        parameters = {
+            "from_answer_link": self.from_answer_link,
+            "direct_link": self.direct_link
+        }
+        run_test_InvalidParameterException(parameters)
+
+        # Missing answer in from_answer_link
+        self.from_answer_link = [
+            {
+                "synapse": "synapse2",
+            }
+        ]
+
+        parameters = {
+            "default": self.default,
+            "from_answer_link": self.from_answer_link
+        }
+        run_test_MissingParameterException(parameters)
+
+        # Missing synapse in from_answer_link
+        self.from_answer_link = [
+            {
+                "answer": "blablablbla",
+            }
+        ]
+
+        parameters = {
+            "default": self.default,
+            "from_answer_link": self.from_answer_link
+        }
+        run_test_MissingParameterException(parameters)
+
+
+    def testCallback(self):
+        pass