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 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")
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")
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")
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")
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")
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("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")