Beispiel #1
0
 def testsignal_resp_handler_remote_action(self):
     """
     Test to check the handling remote action method  with a response of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     cbt = CBT()
     cbt.request.params = {"RecipientId": "1", "OverlayId": "A0FB389"}
     jid_cache = JidCache(signal, 5)
     jid_cache.add_entry("1", "2345")
     transport = XmppTransport.factory(
         "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal,
         signal._presence_publisher, None, None)
     transport.send_msg = MagicMock()
     signal._circles = {
         "A0FB389": {
             "JidCache": jid_cache,
             "Transport": transport
         }
     }
     cbt.tag = "1"
     signal.submit_cbt(cbt)
     resp = CBT.Response()
     cbt.response = resp
     rem_act = {"InitiatorId": "1", "OverlayId": "A0FB389"}
     signal._remote_acts["1"] = rem_act
     signal.submit_cbt(cbt)
     signal.transmit_remote_act = MagicMock()
     signal.free_cbt = MagicMock()
     signal.resp_handler_remote_action(cbt)
     signal.transmit_remote_act.assert_called_once()
     signal.free_cbt.assert_called_once()
     print("Passed : testsignal_resp_handler_remote_action")
 def create_cbt(self,
                initiator=None,
                recipient=None,
                action=None,
                params=None):
     # create and return a CBT with optional parameters
     cbt = CBT(initiator, recipient, action, params)
     self._owned_cbts[cbt.tag] = cbt
     cbt.time_create = time.perf_counter()
     return cbt
Beispiel #3
0
 def testsignal_process_cbt_request_rep_data(self):
     """
     Test to check the process cbt method with a request to report data of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     cbt = CBT()
     cbt.op_type = "Request"
     cbt.request.action = "SIG_QUERY_REPORTING_DATA"
     signal.req_handler_query_reporting_data = MagicMock()
     signal.process_cbt(cbt)
     signal.req_handler_query_reporting_data.assert_called_once()
     print("Passed : testprocess_cbt_request_rep_data")
Beispiel #4
0
 def testsignal_process_cbt_request_rem_act(self):
     """
     Test to check the process cbt method with a request to initiate a remote action of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     cbt = CBT()
     cbt.op_type = "Request"
     cbt.request.action = "SIG_REMOTE_ACTION"
     signal.req_handler_initiate_remote_action = MagicMock()
     signal.process_cbt(cbt)
     signal.req_handler_initiate_remote_action.assert_called_once()
     print("Passed : testprocess_cbt_request_rem_act")
Beispiel #5
0
 def testsignal_process_cbt_resp_tag_present(self):
     """
     Test to check the process cbt method with a response with the cbt tag present.
     """
     sig_dict, signal = self.setup_vars_mocks()
     signal._remote_acts = {"1"}
     signal.resp_handler_remote_action = MagicMock()
     cbt = CBT()
     cbt.op_type = "Response"
     cbt.tag = "1"
     signal.process_cbt(cbt)
     signal.resp_handler_remote_action.assert_called_once()
     print("Passed : testprocess_cbt_resp_tag_present")
Beispiel #6
0
 def testsignal_process_cbt_resp_with_parent_more_children(self):
     """
     Test to check the process cbt method with a response with the parent present and no tag and more than 1 child.
     """
     sig_dict, signal = self.setup_vars_mocks()
     cbt1 = CBT()
     cbt = CBT()
     cbt.op_type = "Response"
     cbt.parent = cbt1
     resp = CBT.Response()
     resp.data = "Data"
     cbt.response = resp
     cbt.response.status = "OK"
     cbt1.child_count = 2
     signal.free_cbt = MagicMock()
     signal.complete_cbt = MagicMock()
     signal.process_cbt(cbt)
     signal.free_cbt.assert_called_once()
     signal.complete_cbt.assert_not_called()
     print("Passed : test_process_cbt_resp_with_parent")
Beispiel #7
0
 def testsignal_req_handler_query_reporting_data(self):
     """
     Test to check the reporting of data method of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     cbt = CBT()
     transport = XmppTransport.factory(
         "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal,
         signal._presence_publisher, None, None)
     transport._host = "IPOP"
     transport.boundjid.full = "ipopuser"
     signal._circles = {"A0FB389": {"Transport": transport}}
     signal.complete_cbt = MagicMock()
     signal.req_handler_query_reporting_data(cbt)
     signal.complete_cbt.assert_called_once()
     print("Passed : testsignal_req_handler_query_reporting_data")
Beispiel #8
0
 def testsignal_scavenge_pending_cbts(self):
     """
     Test to check if scavenge of pending CBT works with one above the request timeout.
     """
     cfxObject = Mock()
     cfx_handle = CFxHandle(cfxObject)
     module = importlib.import_module(
         "controller.modules.{0}".format("Signal"))
     module_class = getattr(module, "Signal")
     sig_dict = {
         "Signal": {
             "Enabled": True,
             "Overlays": {
                 "A0FB389": {
                     "HostAddress": "1.1.1.1",
                     "Port": "5222",
                     "Username": "******",
                     "Password": "******",
                     "AuthenticationMethod": "PASSWORD"
                 }
             }
         },
         "NodeId": "1234434323"
     }
     signal = module_class(cfx_handle, sig_dict, "Signal")
     cfx_handle._cm_instance = signal
     cfx_handle._cm_config = sig_dict
     cbt1 = CBT()
     cbt1.tag = "1"
     cbt1.time_submit = time.time() - 5
     signal.request_timeout = 5
     cbt2 = CBT()
     cbt2.tag = "2"
     cbt2.time_submit = time.time() - 1
     signal.complete_cbt = MagicMock()
     signal._cfx_handle._pending_cbts.update({"0": cbt1})
     signal._cfx_handle._pending_cbts.update({"1": cbt2})
     assert len(signal._cfx_handle._pending_cbts.items()) == 2
     signal.scavenge_pending_cbts()
     assert len(signal._cfx_handle._pending_cbts.items()) == 1
     items = {}
     items.update({"1": cbt2})
     assert signal._cfx_handle._pending_cbts == items
     print("Passed : testsignal_scavenge_pending_cbts")
Beispiel #9
0
 def createCBT(self, initiator='', recipient='', action='', data=''):
     # create and return a CBT with optional parameters
     cbt = CBT(initiator, recipient, action, data)
     self.OwnedCBTs[cbt.Tag] = cbt
     return cbt
Beispiel #10
0
 def create_cbt(self, initiator=None, recipient=None, action=None, params=None):
     # create and return a CBT with optional parameters
     cbt = CBT(initiator, recipient, action, params)
     self._owned_cbts[cbt.tag] = cbt
     cbt.time_create = time.time()
     return cbt