فهرست منبع

[Tests] Add Push_message neuron param tests

monf 8 سال پیش
والد
کامیت
943ac9332a

+ 4 - 4
neurons/push_message/push_message.py

@@ -1,7 +1,7 @@
 from __future__ import absolute_import
 from pushetta import Pushetta
 
-from core.NeuronModule import NeuronModule
+from core.NeuronModule import NeuronModule, MissingParameterException
 
 
 class Push_message(NeuronModule):
@@ -34,10 +34,10 @@ class Push_message(NeuronModule):
         .. raises:: NotImplementedError
         """
         if self.message is None:
-            raise NotImplementedError("Pushetta neuron needs message to send")
+            raise MissingParameterException("Pushetta neuron needs message to send")
         if self.api_key is None:
-            raise NotImplementedError("Pushetta neuron needs api_key")
+            raise MissingParameterException("Pushetta neuron needs api_key")
         if self.channel_name is None:
-            raise NotImplementedError("Pushetta neuron needs channel_name")
+            raise MissingParameterException("Pushetta neuron needs channel_name")
 
         return True

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


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

@@ -0,0 +1,43 @@
+import unittest
+
+from core.NeuronModule import MissingParameterException
+from neurons.push_message.push_message import Push_message
+
+
+class TestPush_Message(unittest.TestCase):
+
+    def setUp(self):
+        self.message="message"
+        self.api_key="api_key"
+        self.channel_name = "channel_name"
+
+    def testParameters(self):
+        def run_test(parameters_to_test):
+            with self.assertRaises(MissingParameterException):
+                Push_message(**parameters_to_test)
+
+        # empty
+        parameters = dict()
+        run_test(parameters)
+
+        # missing api_key
+        parameters = {
+            "message": self.message,
+            "channel_name": self.channel_name
+        }
+        run_test(parameters)
+
+        # missing channel_name
+        parameters = {
+           "api_key": self.api_key,
+            "message":self.message
+        }
+        run_test(parameters)
+
+        # missing message
+        parameters = {
+            "api_key": self.api_key,
+            "channel_name": self.channel_name
+        }
+        run_test(parameters)
+